Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: tests/common/register_set.c

Issue 12781011: [MIPS] Implement register_set.{c,h} parts for MIPS (Closed) Base URL: http://git.chromium.org/native_client/src/native_client.git@master
Patch Set: Nits. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/common/register_set.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #include "native_client/tests/common/register_set.h" 7 #include "native_client/tests/common/register_set.h"
8 8
9 #include <assert.h> 9 #include <assert.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 DEFINE_REG(r7), 80 DEFINE_REG(r7),
81 DEFINE_REG(r8), 81 DEFINE_REG(r8),
82 DEFINE_REG(r9), 82 DEFINE_REG(r9),
83 DEFINE_REG(r10), 83 DEFINE_REG(r10),
84 DEFINE_REG(r11), 84 DEFINE_REG(r11),
85 DEFINE_REG(r12), 85 DEFINE_REG(r12),
86 DEFINE_REG(stack_ptr), 86 DEFINE_REG(stack_ptr),
87 DEFINE_REG(lr), 87 DEFINE_REG(lr),
88 DEFINE_REG(prog_ctr), 88 DEFINE_REG(prog_ctr),
89 DEFINE_REG(cpsr) 89 DEFINE_REG(cpsr)
90 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_mips
91 DEFINE_REG(zero),
92 DEFINE_REG(at),
93 DEFINE_REG(v0),
94 DEFINE_REG(v1),
95 DEFINE_REG(a0),
96 DEFINE_REG(a1),
97 DEFINE_REG(a2),
98 DEFINE_REG(a3),
99 DEFINE_REG(t0),
100 DEFINE_REG(t1),
101 DEFINE_REG(t2),
102 DEFINE_REG(t3),
103 DEFINE_REG(t4),
104 DEFINE_REG(t5),
105 DEFINE_REG(t6),
106 DEFINE_REG(t7),
107 DEFINE_REG(s0),
108 DEFINE_REG(s1),
109 DEFINE_REG(s2),
110 DEFINE_REG(s3),
111 DEFINE_REG(s4),
112 DEFINE_REG(s5),
113 DEFINE_REG(s6),
114 DEFINE_REG(s7),
115 DEFINE_REG(t8),
116 DEFINE_REG(t9),
117 DEFINE_REG(k0),
118 DEFINE_REG(k1),
119 DEFINE_REG(global_ptr),
120 DEFINE_REG(stack_ptr),
121 DEFINE_REG(frame_ptr),
122 DEFINE_REG(return_addr),
123 DEFINE_REG(prog_ctr)
90 #else 124 #else
91 # error Unsupported architecture 125 # error Unsupported architecture
92 #endif 126 #endif
93 }; 127 };
94 128
95 #undef DEFINE_REG 129 #undef DEFINE_REG
96 130
97 /* Flags readable and writable by untrusted code. */ 131 /* Flags readable and writable by untrusted code. */
98 const uint8_t kX86FlagBits[5] = { 0, 2, 6, 7, 11 }; 132 const uint8_t kX86FlagBits[5] = { 0, 2, 6, 7, 11 };
99 /* 133 /*
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 fprintf(stderr, " %s=0x%llx (%lld)\n", 186 fprintf(stderr, " %s=0x%llx (%lld)\n",
153 kRegs[regnum].reg_name, value, value); 187 kRegs[regnum].reg_name, value, value);
154 } 188 }
155 } 189 }
156 190
157 static void RegsNormalizeFlags(struct NaClSignalContext *regs) { 191 static void RegsNormalizeFlags(struct NaClSignalContext *regs) {
158 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 192 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86
159 regs->flags &= kX86KnownFlagsMask; 193 regs->flags &= kX86KnownFlagsMask;
160 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm 194 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm
161 regs->cpsr &= REGS_ARM_USER_CPSR_FLAGS_MASK; 195 regs->cpsr &= REGS_ARM_USER_CPSR_FLAGS_MASK;
196 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_mips
197 /* No flags field on MIPS. */
198 UNREFERENCED_PARAMETER(regs);
162 #endif 199 #endif
163 } 200 }
164 201
165 void RegsAssertEqual(const struct NaClSignalContext *actual, 202 void RegsAssertEqual(const struct NaClSignalContext *actual,
166 const struct NaClSignalContext *expected) { 203 const struct NaClSignalContext *expected) {
167 int match = 1; 204 int match = 1;
168 unsigned int regnum; 205 unsigned int regnum;
169 206
170 /* Make a copy so that we can ignore some of the x86/ARM flags. */ 207 /* Make a copy so that we can ignore some of the x86/ARM flags. */
171 struct NaClSignalContext copy_actual = *actual; 208 struct NaClSignalContext copy_actual = *actual;
172 struct NaClSignalContext copy_expected = *expected; 209 struct NaClSignalContext copy_expected = *expected;
173 RegsNormalizeFlags(&copy_actual); 210 RegsNormalizeFlags(&copy_actual);
174 RegsNormalizeFlags(&copy_expected); 211 RegsNormalizeFlags(&copy_expected);
175 212
176 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm 213 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm
177 /* 214 /*
178 * We skip comparison of r9 because it is not supposed to be 215 * We skip comparison of r9 because it is not supposed to be
179 * settable or readable by untrusted code. However, for debugging 216 * settable or readable by untrusted code. However, for debugging
180 * purposes we still include r9 in register dumps printed by 217 * purposes we still include r9 in register dumps printed by
181 * RegsDump(), so r9 remains listed in kRegs[]. 218 * RegsDump(), so r9 remains listed in kRegs[].
182 */ 219 */
183 copy_expected.r9 = copy_actual.r9; 220 copy_expected.r9 = copy_actual.r9;
221 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_mips
222 /*
223 * The registers below are all read-only, so we skip their comparison. We
224 * expect t6 and t7 to hold control flow masks. For t8, which holds TLS
225 * index, we skip comparison. Zero register holds zero always. All of the
226 * above named registers are not settable by untrusted code. We also skip
227 * comparison for k0 and k1 registers because those are registers reserved for
228 * use by interrupt/trap handler and therefore volatile.
229 * However, for debugging purposes we still include those in register dumps
230 * printed by RegsDump(), so they remain listed in kRegs[].
231 */
232 copy_expected.zero = 0;
233 copy_expected.t6 = NACL_CONTROL_FLOW_MASK;
234 copy_expected.t7 = NACL_DATA_FLOW_MASK;
235 copy_expected.t8 = copy_actual.t8;
236 copy_expected.k0 = copy_actual.k0;
237 copy_expected.k1 = copy_actual.k1;
184 #endif 238 #endif
185 239
186 for (regnum = 0; regnum < NACL_ARRAY_SIZE(kRegs); regnum++) { 240 for (regnum = 0; regnum < NACL_ARRAY_SIZE(kRegs); regnum++) {
187 if (RegsGetRegValue(&copy_actual, regnum) != 241 if (RegsGetRegValue(&copy_actual, regnum) !=
188 RegsGetRegValue(&copy_expected, regnum)) { 242 RegsGetRegValue(&copy_expected, regnum)) {
189 fprintf(stderr, "Mismatch in register %s\n", kRegs[regnum].reg_name); 243 fprintf(stderr, "Mismatch in register %s\n", kRegs[regnum].reg_name);
190 match = 0; 244 match = 0;
191 } 245 }
192 } 246 }
193 if (!match) { 247 if (!match) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 regs->r11 = 0; 287 regs->r11 = 0;
234 regs->flags = 0; 288 regs->flags = 0;
235 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm 289 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm
236 regs->r0 = 0; 290 regs->r0 = 0;
237 regs->r1 = 0; 291 regs->r1 = 0;
238 regs->r2 = 0; 292 regs->r2 = 0;
239 regs->r3 = 0; 293 regs->r3 = 0;
240 regs->r12 = 0; 294 regs->r12 = 0;
241 regs->lr = 0; 295 regs->lr = 0;
242 regs->cpsr = 0; 296 regs->cpsr = 0;
297 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_mips
298 regs->zero = 0;
299 regs->at = 0;
300 regs->v0 = 0;
301 regs->v1 = 0;
302 regs->a0 = 0;
303 regs->a1 = 0;
304 regs->a2 = 0;
305 regs->a3 = 0;
306 regs->t0 = 0;
307 regs->t1 = 0;
308 regs->t2 = 0;
309 regs->t3 = 0;
310 regs->t4 = 0;
311 regs->t5 = 0;
312 regs->t9 = 0;
313 regs->k0 = 0;
314 regs->k1 = 0;
315 regs->global_ptr = 0;
316 regs->return_addr = 0;
243 #else 317 #else
244 # error Unsupported architecture 318 # error Unsupported architecture
245 #endif 319 #endif
246 } 320 }
247 321
248 #if defined(__native_client__) 322 #if defined(__native_client__)
249 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 32 323 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 32
250 324
251 uintptr_t RegsGetArg1(const struct NaClSignalContext *regs) { 325 uintptr_t RegsGetArg1(const struct NaClSignalContext *regs) {
252 return ((uint32_t *) regs->stack_ptr)[1]; 326 return ((uint32_t *) regs->stack_ptr)[1];
253 } 327 }
254 328
255 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 64 329 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 64
256 330
257 uintptr_t RegsGetArg1(const struct NaClSignalContext *regs) { 331 uintptr_t RegsGetArg1(const struct NaClSignalContext *regs) {
258 return regs->rdi; 332 return regs->rdi;
259 } 333 }
260 334
261 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm 335 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm
262 336
263 uintptr_t RegsGetArg1(const struct NaClSignalContext *regs) { 337 uintptr_t RegsGetArg1(const struct NaClSignalContext *regs) {
264 return regs->r0; 338 return regs->r0;
265 } 339 }
266 340
341 #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_mips
342
343 uintptr_t RegsGetArg1(const struct NaClSignalContext *regs) {
344 return regs->a0;
345 }
346
267 #else 347 #else
268 # error Unsupported architecture 348 # error Unsupported architecture
269 #endif 349 #endif
270 #endif 350 #endif
OLDNEW
« no previous file with comments | « tests/common/register_set.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698