OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #include "snapshot/test/test_cpu_context.h" |
| 16 |
| 17 #include "base/basictypes.h" |
| 18 |
| 19 namespace crashpad { |
| 20 namespace test { |
| 21 |
| 22 void InitializeCPUContextX86(CPUContext* context, uint32_t seed) { |
| 23 context->architecture = kCPUArchitectureX86; |
| 24 |
| 25 if (seed == 0) { |
| 26 memset(context->x86, 0, sizeof(*context->x86)); |
| 27 return; |
| 28 } |
| 29 |
| 30 uint32_t value = seed; |
| 31 |
| 32 context->x86->eax = value++; |
| 33 context->x86->ebx = value++; |
| 34 context->x86->ecx = value++; |
| 35 context->x86->edx = value++; |
| 36 context->x86->edi = value++; |
| 37 context->x86->esi = value++; |
| 38 context->x86->ebp = value++; |
| 39 context->x86->esp = value++; |
| 40 context->x86->eip = value++; |
| 41 context->x86->eflags = value++; |
| 42 context->x86->cs = value++; |
| 43 context->x86->ds = value++; |
| 44 context->x86->es = value++; |
| 45 context->x86->fs = value++; |
| 46 context->x86->gs = value++; |
| 47 context->x86->ss = value++; |
| 48 InitializeCPUContextX86Fxsave(&context->x86->fxsave, &value); |
| 49 context->x86->dr0 = value++; |
| 50 context->x86->dr1 = value++; |
| 51 context->x86->dr2 = value++; |
| 52 context->x86->dr3 = value++; |
| 53 context->x86->dr4 = value++; |
| 54 context->x86->dr5 = value++; |
| 55 context->x86->dr6 = value++; |
| 56 context->x86->dr7 = value++; |
| 57 } |
| 58 |
| 59 void InitializeCPUContextX86_64(CPUContext* context, uint32_t seed) { |
| 60 context->architecture = kCPUArchitectureX86_64; |
| 61 |
| 62 if (seed == 0) { |
| 63 memset(context->x86_64, 0, sizeof(*context->x86_64)); |
| 64 return; |
| 65 } |
| 66 |
| 67 uint32_t value = seed; |
| 68 |
| 69 context->x86_64->rax = value++; |
| 70 context->x86_64->rbx = value++; |
| 71 context->x86_64->rcx = value++; |
| 72 context->x86_64->rdx = value++; |
| 73 context->x86_64->rdi = value++; |
| 74 context->x86_64->rsi = value++; |
| 75 context->x86_64->rbp = value++; |
| 76 context->x86_64->rsp = value++; |
| 77 context->x86_64->r8 = value++; |
| 78 context->x86_64->r9 = value++; |
| 79 context->x86_64->r10 = value++; |
| 80 context->x86_64->r11 = value++; |
| 81 context->x86_64->r12 = value++; |
| 82 context->x86_64->r13 = value++; |
| 83 context->x86_64->r14 = value++; |
| 84 context->x86_64->r15 = value++; |
| 85 context->x86_64->rip = value++; |
| 86 context->x86_64->rflags = value++; |
| 87 context->x86_64->cs = value++; |
| 88 context->x86_64->fs = value++; |
| 89 context->x86_64->gs = value++; |
| 90 InitializeCPUContextX86_64Fxsave(&context->x86_64->fxsave, &value); |
| 91 context->x86_64->dr0 = value++; |
| 92 context->x86_64->dr1 = value++; |
| 93 context->x86_64->dr2 = value++; |
| 94 context->x86_64->dr3 = value++; |
| 95 context->x86_64->dr4 = value++; |
| 96 context->x86_64->dr5 = value++; |
| 97 context->x86_64->dr6 = value++; |
| 98 context->x86_64->dr7 = value++; |
| 99 } |
| 100 |
| 101 namespace { |
| 102 |
| 103 // This is templatized because the CPUContextX86::Fxsave and |
| 104 // CPUContextX86_64::Fxsave are nearly identical but have different sizes for |
| 105 // the members |xmm|, |reserved_4|, and |available|. |
| 106 template <typename FxsaveType> |
| 107 void InitializeCPUContextFxsave(FxsaveType* fxsave, uint32_t* seed) { |
| 108 uint32_t value = *seed; |
| 109 |
| 110 fxsave->fcw = value++; |
| 111 fxsave->fsw = value++; |
| 112 fxsave->ftw = value++; |
| 113 fxsave->reserved_1 = value++; |
| 114 fxsave->fop = value++; |
| 115 fxsave->fpu_ip = value++; |
| 116 fxsave->fpu_cs = value++; |
| 117 fxsave->reserved_2 = value++; |
| 118 fxsave->fpu_dp = value++; |
| 119 fxsave->fpu_ds = value++; |
| 120 fxsave->reserved_3 = value++; |
| 121 fxsave->mxcsr = value++; |
| 122 fxsave->mxcsr_mask = value++; |
| 123 for (size_t st_mm_index = 0; |
| 124 st_mm_index < arraysize(fxsave->st_mm); |
| 125 ++st_mm_index) { |
| 126 for (size_t byte = 0; |
| 127 byte < arraysize(fxsave->st_mm[st_mm_index].st); |
| 128 ++byte) { |
| 129 fxsave->st_mm[st_mm_index].st[byte] = value++; |
| 130 } |
| 131 for (size_t byte = 0; |
| 132 byte < arraysize(fxsave->st_mm[st_mm_index].st_reserved); |
| 133 ++byte) { |
| 134 fxsave->st_mm[st_mm_index].st_reserved[byte] = value; |
| 135 } |
| 136 } |
| 137 for (size_t xmm_index = 0; xmm_index < arraysize(fxsave->xmm); ++xmm_index) { |
| 138 for (size_t byte = 0; byte < arraysize(fxsave->xmm[xmm_index]); ++byte) { |
| 139 fxsave->xmm[xmm_index][byte] = value++; |
| 140 } |
| 141 } |
| 142 for (size_t byte = 0; byte < arraysize(fxsave->reserved_4); ++byte) { |
| 143 fxsave->reserved_4[byte] = value++; |
| 144 } |
| 145 for (size_t byte = 0; byte < arraysize(fxsave->available); ++byte) { |
| 146 fxsave->available[byte] = value++; |
| 147 } |
| 148 |
| 149 *seed = value; |
| 150 } |
| 151 |
| 152 } // namespace |
| 153 |
| 154 void InitializeCPUContextX86Fxsave(CPUContextX86::Fxsave* fxsave, |
| 155 uint32_t* seed) { |
| 156 return InitializeCPUContextFxsave(fxsave, seed); |
| 157 } |
| 158 |
| 159 void InitializeCPUContextX86_64Fxsave(CPUContextX86_64::Fxsave* fxsave, |
| 160 uint32_t* seed) { |
| 161 return InitializeCPUContextFxsave(fxsave, seed); |
| 162 } |
| 163 |
| 164 } // namespace test |
| 165 } // namespace crashpad |
OLD | NEW |