2010-05-14 Rodrigo Kumpera <rkumpera@novell.com>
[mono-project.git] / mono / metadata / sgen-archdep.h
blob090b80c7d78147b101a3e67ca9be66d1f2fd1d4e
1 /*
2 * SGen is licensed under the terms of the MIT X11 license
4 * Copyright 2001-2003 Ximian, Inc
5 * Copyright 2003-2010 Novell, Inc.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #ifndef __MONO_SGENARCHDEP_H__
27 #define __MONO_SGENARCHDEP_H__
29 #include <mono/utils/mono-sigcontext.h>
31 #ifdef __i386__
33 #define REDZONE_SIZE 0
35 #define ARCH_NUM_REGS 7 /* we're never storing ESP */
36 #define ARCH_STORE_REGS(ptr) \
37 __asm__ __volatile__( \
38 "mov %%ecx, 0x00(%0)\n" \
39 "mov %%edx, 0x04(%0)\n" \
40 "mov %%ebx, 0x08(%0)\n" \
41 "mov %%edi, 0x0c(%0)\n" \
42 "mov %%esi, 0x10(%0)\n" \
43 "mov %%ebp, 0x14(%0)\n" \
44 : "=&a" (ptr) \
45 : "0" (cur_thread_regs) \
46 : "memory" \
48 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_ESP ((ctx)))
49 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_EIP ((ctx)))
50 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
51 (a)[0] = (gpointer) UCONTEXT_REG_EAX ((ctx)); \
52 (a)[1] = (gpointer) UCONTEXT_REG_EBX ((ctx)); \
53 (a)[2] = (gpointer) UCONTEXT_REG_ECX ((ctx)); \
54 (a)[3] = (gpointer) UCONTEXT_REG_EDX ((ctx)); \
55 (a)[4] = (gpointer) UCONTEXT_REG_ESI ((ctx)); \
56 (a)[5] = (gpointer) UCONTEXT_REG_EDI ((ctx)); \
57 (a)[6] = (gpointer) UCONTEXT_REG_EBP ((ctx)); \
58 } while (0)
60 #elif defined(__x86_64__)
62 #define REDZONE_SIZE 128
64 #define ARCH_NUM_REGS 15 /* we're never storing RSP */
65 #define ARCH_STORE_REGS(ptr) \
66 __asm__ __volatile__( \
67 "movq %%rcx, 0x00(%0)\n" \
68 "movq %%rdx, 0x08(%0)\n" \
69 "movq %%rbx, 0x10(%0)\n" \
70 "movq %%rdi, 0x18(%0)\n" \
71 "movq %%rsi, 0x20(%0)\n" \
72 "movq %%rbp, 0x28(%0)\n" \
73 "movq %%r8, 0x30(%0)\n" \
74 "movq %%r9, 0x38(%0)\n" \
75 "movq %%r10, 0x40(%0)\n" \
76 "movq %%r11, 0x48(%0)\n" \
77 "movq %%r12, 0x50(%0)\n" \
78 "movq %%r13, 0x58(%0)\n" \
79 "movq %%r14, 0x60(%0)\n" \
80 "movq %%r15, 0x68(%0)\n" \
81 : "=&a" (ptr) \
82 : "0" (cur_thread_regs) \
83 : "memory" \
85 #define ARCH_SIGCTX_SP(ctx) ((UCONTEXT_GREGS((ctx))) [REG_RSP])
86 #define ARCH_SIGCTX_IP(ctx) ((UCONTEXT_GREGS((ctx))) [REG_RIP])
87 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
88 ((a)[0] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_RAX]); \
89 ((a)[1] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_RBX]); \
90 ((a)[2] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_RCX]); \
91 ((a)[3] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_RDX]); \
92 ((a)[4] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_RSI]); \
93 ((a)[5] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_RDI]); \
94 ((a)[6] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_RBP]); \
95 ((a)[7] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_R8]); \
96 ((a)[8] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_R9]); \
97 ((a)[9] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_R10]); \
98 ((a)[10] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_R11]); \
99 ((a)[11] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_R12]); \
100 ((a)[12] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_R13]); \
101 ((a)[13] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_R14]); \
102 ((a)[14] = (gpointer) (UCONTEXT_GREGS((ctx))) [REG_R15]); \
103 } while (0)
105 #elif defined(__ppc__)
107 #define REDZONE_SIZE 224
109 #define ARCH_NUM_REGS 32
110 #define ARCH_STORE_REGS(ptr) \
111 __asm__ __volatile__( \
112 "stmw r0, 0(%0)\n" \
114 : "b" (ptr) \
116 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_Rn((ctx), 1))
117 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_NIP((ctx)))
118 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
119 int __i; \
120 for (__i = 0; __i < 32; ++__i) \
121 ((a)[__i]) = UCONTEXT_REG_Rn((ctx), __i); \
122 } while (0)
124 #endif
126 #endif /* __MONO_SGENARCHDEP_H__ */