OLD | NEW |
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 #ifndef NATIVE_CLIENT_TESTS_COMMON_REGISTER_SET_H_ | 7 #ifndef NATIVE_CLIENT_TESTS_COMMON_REGISTER_SET_H_ |
8 #define NATIVE_CLIENT_TESTS_COMMON_REGISTER_SET_H_ | 8 #define NATIVE_CLIENT_TESTS_COMMON_REGISTER_SET_H_ |
9 | 9 |
10 #include "native_client/src/include/nacl/nacl_exception.h" | 10 #include "native_client/src/include/nacl/nacl_exception.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 * def_func which saves all registers on the stack and passes them to | 224 * def_func which saves all registers on the stack and passes them to |
225 * callee_func in the form of a "struct NaClSignalContext *". | 225 * callee_func in the form of a "struct NaClSignalContext *". |
226 */ | 226 */ |
227 | 227 |
228 #define REGS_SAVER_FUNC(def_func, callee_func) \ | 228 #define REGS_SAVER_FUNC(def_func, callee_func) \ |
229 void def_func(void); \ | 229 void def_func(void); \ |
230 REGS_SAVER_FUNC_NOPROTO(def_func, callee_func) | 230 REGS_SAVER_FUNC_NOPROTO(def_func, callee_func) |
231 | 231 |
232 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 32 | 232 #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 32 |
233 | 233 |
| 234 #if defined(NONSFI_MODE) && NONSFI_MODE |
| 235 /* |
| 236 * Look up GOT for PIC. |
| 237 */ |
| 238 #define STORE_PROG_CTR(def_func) \ |
| 239 "call 0f\n" \ |
| 240 "0: popl %eax\n" \ |
| 241 "1: addl $_GLOBAL_OFFSET_TABLE_ + (1b - 0b), %eax\n" \ |
| 242 "movl " #def_func "@GOT(%eax), %eax\n" \ |
| 243 "movl %eax, 0x20(%esp)\n" |
| 244 |
| 245 #else |
| 246 #define STORE_PROG_CTR(def_func) "movl $" #def_func ", 0x20(%esp)\n" |
| 247 #endif |
| 248 |
234 # define REGS_SAVER_FUNC_NOPROTO(def_func, callee_func) \ | 249 # define REGS_SAVER_FUNC_NOPROTO(def_func, callee_func) \ |
235 void callee_func(struct NaClSignalContext *regs); \ | 250 void callee_func(struct NaClSignalContext *regs); \ |
236 __asm__( \ | 251 __asm__( \ |
237 ".pushsection .text, \"ax\", @progbits\n" \ | 252 ".pushsection .text, \"ax\", @progbits\n" \ |
238 ".p2align 5\n" \ | 253 ".p2align 5\n" \ |
239 ".global " #def_func "\n"\ | 254 ".global " #def_func "\n"\ |
240 #def_func ":\n" \ | 255 #def_func ":\n" \ |
241 /* Push most of "struct NaClSignalContext" in reverse order. */ \ | 256 /* Push most of "struct NaClSignalContext" in reverse order. */ \ |
242 "push $0\n" /* Leave space for flags */ \ | 257 "push $0\n" /* Leave space for flags */ \ |
243 "push $" #def_func "\n" /* Fill out prog_ctr with known value */ \ | 258 /* TODO(uekawa): allow use of @got or use something else. */ \ |
| 259 "push $0 \n" /* Leave space for prog_ctr */ \ |
244 "push %edi\n" \ | 260 "push %edi\n" \ |
245 "push %esi\n" \ | 261 "push %esi\n" \ |
246 "push %ebp\n" \ | 262 "push %ebp\n" \ |
247 "push %esp\n" \ | 263 "push %esp\n" \ |
248 "push %ebx\n" \ | 264 "push %ebx\n" \ |
249 "push %edx\n" \ | 265 "push %edx\n" \ |
250 "push %ecx\n" \ | 266 "push %ecx\n" \ |
251 "push %eax\n" \ | 267 "push %eax\n" \ |
252 /* Save flags. */ \ | 268 /* Save flags. */ \ |
253 SAVE_X86_FLAGS_INTO_REG("%eax") \ | 269 SAVE_X86_FLAGS_INTO_REG("%eax") \ |
254 "movl %eax, 0x24(%esp)\n" \ | 270 "movl %eax, 0x24(%esp)\n" \ |
| 271 STORE_PROG_CTR(def_func) /* Fill out prog_ctr with known value */ \ |
255 /* Adjust saved %esp value to account for preceding pushes. */ \ | 272 /* Adjust saved %esp value to account for preceding pushes. */ \ |
256 "addl $5 * 4, 0x10(%esp)\n" \ | 273 "addl $5 * 4, 0x10(%esp)\n" \ |
257 /* Save argument to callee_func() temporarily. */ \ | 274 /* Save argument to callee_func() temporarily. */ \ |
258 "mov %esp, %eax\n" \ | 275 "mov %esp, %eax\n" \ |
259 /* Align the stack pointer and leave space for an argument. */ \ | 276 /* Align the stack pointer and leave space for an argument. */ \ |
260 "pushl $0\n" \ | 277 "pushl $0\n" \ |
261 "and $~15, %esp\n" \ | 278 "and $~15, %esp\n" \ |
262 /* Set argument to callee_func(). */ \ | 279 /* Set argument to callee_func(). */ \ |
263 "mov %eax, (%esp)\n" \ | 280 "mov %eax, (%esp)\n" \ |
264 "call " #callee_func "\n" \ | 281 "call " #callee_func "\n" \ |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 void RegsUnsetNonCalleeSavedRegisters(struct NaClSignalContext *regs); | 458 void RegsUnsetNonCalleeSavedRegisters(struct NaClSignalContext *regs); |
442 | 459 |
443 /* | 460 /* |
444 * For a function called with register state |regs|, extract the first | 461 * For a function called with register state |regs|, extract the first |
445 * argument. This is useful for a function entry point defined by | 462 * argument. This is useful for a function entry point defined by |
446 * REGS_SAVER_FUNC. | 463 * REGS_SAVER_FUNC. |
447 */ | 464 */ |
448 uintptr_t RegsGetArg1(const struct NaClSignalContext *regs); | 465 uintptr_t RegsGetArg1(const struct NaClSignalContext *regs); |
449 | 466 |
450 #endif | 467 #endif |
OLD | NEW |