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

Side by Side Diff: tests/debug_stub/debugger_test.c

Issue 107313005: [MIPS] Add support for debug stub test (Closed) Base URL: http://git.chromium.org/native_client/src/native_client.git@master
Patch Set: Minor code style update. Created 6 years, 12 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
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 <pthread.h> 7 #include <pthread.h>
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 19 matching lines...) Expand all
30 #if defined(__i386__) || defined(__x86_64__) 30 #if defined(__i386__) || defined(__x86_64__)
31 __asm__(".pushsection .text, \"ax\", @progbits\n" 31 __asm__(".pushsection .text, \"ax\", @progbits\n"
32 "fault_addr:\n" 32 "fault_addr:\n"
33 "hlt\n" 33 "hlt\n"
34 ".popsection\n"); 34 ".popsection\n");
35 #elif defined(__arm__) 35 #elif defined(__arm__)
36 __asm__(".pushsection .text, \"ax\", %progbits\n" 36 __asm__(".pushsection .text, \"ax\", %progbits\n"
37 "fault_addr:\n" 37 "fault_addr:\n"
38 ".word " NACL_TO_STRING(NACL_INSTR_ARM_BREAKPOINT) "\n" 38 ".word " NACL_TO_STRING(NACL_INSTR_ARM_BREAKPOINT) "\n"
39 ".popsection\n"); 39 ".popsection\n");
40 #elif defined(__mips__)
41 __asm__(".pushsection .text, \"ax\", %progbits\n"
42 "fault_addr:\n"
43 ".word 0x0000000d\n"
Mark Seaborn 2013/12/26 17:01:13 Can you comment the instruction that this encodes?
petarj 2013/12/26 18:36:24 Done.
44 ".popsection\n");
40 #else 45 #else
41 # error Update fault_addr for other architectures 46 # error Update fault_addr for other architectures
42 #endif 47 #endif
43 48
44 void set_registers_and_stop(void) { 49 void set_registers_and_stop(void) {
45 struct NaClSignalContext regs; 50 struct NaClSignalContext regs;
46 memset(&regs, 0, sizeof(regs)); 51 memset(&regs, 0, sizeof(regs));
47 52
48 /* 53 /*
49 * We set most registers to fixed values before faulting, so that we 54 * We set most registers to fixed values before faulting, so that we
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 * Skip r9 because it is not supposed to be settable or readable by 98 * Skip r9 because it is not supposed to be settable or readable by
94 * untrusted code. 99 * untrusted code.
95 */ 100 */
96 regs.r10 = 0xa000000b; 101 regs.r10 = 0xa000000b;
97 regs.r11 = 0xb000000c; 102 regs.r11 = 0xb000000c;
98 regs.r12 = 0xc000000d; 103 regs.r12 = 0xc000000d;
99 /* stack_ptr's test value must be within the sandbox address space. */ 104 /* stack_ptr's test value must be within the sandbox address space. */
100 regs.stack_ptr = 0x12345678; 105 regs.stack_ptr = 0x12345678;
101 regs.lr = 0xe000000f; 106 regs.lr = 0xe000000f;
102 regs.cpsr = (1 << 29) | (1 << 27); /* C and Q flags */ 107 regs.cpsr = (1 << 29) | (1 << 27); /* C and Q flags */
108 #elif defined(__mips__)
109 /* Skip zero register because it can not be set. */
110 regs.at = 0x11000220;
111 regs.v0 = 0x22000330;
112 regs.v1 = 0x33000440;
113 regs.a0 = 0x44000550;
114 regs.a1 = 0x55000660;
115 regs.a2 = 0x66000770;
116 regs.a3 = 0x77000880;
117 regs.t0 = 0x88000990;
118 regs.t1 = 0x99000AA0;
119 regs.t2 = 0xAA000BB0;
120 regs.t3 = 0xBB000CC0;
121 regs.t4 = 0xCC000DD0;
122 regs.t5 = 0xDD000EE0;
123 /* Skip t6, t7 and t8, because they can not be set by untrusted code. */
124 regs.s0 = 0x11100222;
125 regs.s1 = 0x22200333;
126 regs.s2 = 0x33300444;
127 regs.s3 = 0x44400555;
128 regs.s4 = 0x55500666;
129 regs.s5 = 0x66600777;
130 regs.s6 = 0x77700888;
131 regs.s7 = 0x88800999;
132 regs.t9 = 0xAAA00BBB;
133 /* Skip k0 and k1 registers, since they can be changed by kernel. */
Mark Seaborn 2013/12/26 17:01:13 "can only"?
petarj 2013/12/26 18:36:24 See the comment elsewhere.
134 regs.global_ptr = 0xDDD00EEE;
135 regs.stack_ptr = 0x2EE00FFF;
136 regs.frame_ptr = 0xFFF00000;
137 regs.return_addr = 0x0A0A0A0A;
103 #else 138 #else
104 # error Update set_registers_and_stop for other architectures 139 # error Update set_registers_and_stop for other architectures
105 #endif 140 #endif
106 JUMP_WITH_REGS(&regs, fault_addr); 141 JUMP_WITH_REGS(&regs, fault_addr);
107 } 142 }
108 143
109 void test_jump_to_address_zero(void) { 144 void test_jump_to_address_zero(void) {
110 /* 145 /*
111 * "volatile" tells Clang/LLVM not to optimize this call away and 146 * "volatile" tells Clang/LLVM not to optimize this call away and
112 * replace it with an illegal instruction, which produces different 147 * replace it with an illegal instruction, which produces different
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 ".byte 0x81, 0xeb, 0x14, 0x9f, 0x04, 0x08\n" /* sub $0x8049f14,%ebx */ 184 ".byte 0x81, 0xeb, 0x14, 0x9f, 0x04, 0x08\n" /* sub $0x8049f14,%ebx */
150 ".byte 0x5b\n"); /* pop %ebx */ 185 ".byte 0x5b\n"); /* pop %ebx */
151 #elif defined(__x86_64__) 186 #elif defined(__x86_64__)
152 __asm__( 187 __asm__(
153 ".byte 0xf4\n" /* hlt */ 188 ".byte 0xf4\n" /* hlt */
154 ".byte 0x53\n" /* push %rbx */ 189 ".byte 0x53\n" /* push %rbx */
155 ".byte 0x48, 0x39, 0xd8\n" /* cmp %rbx,%rax */ 190 ".byte 0x48, 0x39, 0xd8\n" /* cmp %rbx,%rax */
156 ".byte 0x48, 0x83, 0xeb, 0x01\n" /* sub $0x1,%rbx */ 191 ".byte 0x48, 0x83, 0xeb, 0x01\n" /* sub $0x1,%rbx */
157 ".byte 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00\n" /* nopw 0x0(%rax,%rax,1) */ 192 ".byte 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00\n" /* nopw 0x0(%rax,%rax,1) */
158 ".byte 0x5b\n"); /* pop %rbx */ 193 ".byte 0x5b\n"); /* pop %rbx */
159 #elif defined(__arm__) 194 #elif defined(__arm__)
Mark Seaborn 2013/12/26 17:01:13 "|| defined(__mips__)" for brevity?
petarj 2013/12/26 18:36:24 Done.
160 printf("Single-stepping is not supported on ARM\n"); 195 printf("Single-stepping is not supported on ARM\n");
161 exit(1); 196 exit(1);
197 #elif defined(__mips__)
198 printf("Single-stepping is not supported on MIPS\n");
199 exit(1);
162 #else 200 #else
163 # error Update test_single_step for other architectures 201 # error Update test_single_step for other architectures
164 #endif 202 #endif
165 } 203 }
166 204
167 void test_interrupt(void) { 205 void test_interrupt(void) {
168 /* 206 /*
169 * 'volatile' is needed for clang optimizer to get this right. 207 * 'volatile' is needed for clang optimizer to get this right.
170 * TODO(robertm): http://code.google.com/p/nativeclient/issues/detail?id=2912 208 * TODO(robertm): http://code.google.com/p/nativeclient/issues/detail?id=2912
171 */ 209 */
(...skipping 10 matching lines...) Expand all
182 #elif defined(__arm__) 220 #elif defined(__arm__)
183 /* 221 /*
184 * Arrange the breakpoint so that the test can skip over it by 222 * Arrange the breakpoint so that the test can skip over it by
185 * jumping to the next bundle. This means we never have to set the 223 * jumping to the next bundle. This means we never have to set the
186 * program counter to within a bundle, which could be unsafe, 224 * program counter to within a bundle, which could be unsafe,
187 * because BKPTs guard data literals in the ARM sandbox. 225 * because BKPTs guard data literals in the ARM sandbox.
188 */ 226 */
189 __asm__(".p2align 4\n" 227 __asm__(".p2align 4\n"
190 ".word " NACL_TO_STRING(NACL_INSTR_ARM_BREAKPOINT) "\n" 228 ".word " NACL_TO_STRING(NACL_INSTR_ARM_BREAKPOINT) "\n"
191 ".p2align 4\n"); 229 ".p2align 4\n");
230 #elif defined(__mips__)
231 __asm__(".p2align 4\n"
232 ".word 0x0000000d\n"
Mark Seaborn 2013/12/26 17:01:13 ditto
petarj 2013/12/26 18:36:24 Done.
233 ".p2align 4\n");
192 #else 234 #else
193 # error Unsupported architecture 235 # error Unsupported architecture
194 #endif 236 #endif
195 } 237 }
196 238
197 void *child_thread_func(void *thread_arg) { 239 void *child_thread_func(void *thread_arg) {
198 for (;;) { 240 for (;;) {
199 g_child_thread_var++; 241 g_child_thread_var++;
200 breakpoint(); 242 breakpoint();
201 } 243 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (strcmp(argv[1], "test_interrupt") == 0) { 286 if (strcmp(argv[1], "test_interrupt") == 0) {
245 test_interrupt(); 287 test_interrupt();
246 return 0; 288 return 0;
247 } 289 }
248 if (strcmp(argv[1], "test_suspending_threads") == 0) { 290 if (strcmp(argv[1], "test_suspending_threads") == 0) {
249 test_suspending_threads(); 291 test_suspending_threads();
250 return 0; 292 return 0;
251 } 293 }
252 return 1; 294 return 1;
253 } 295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698