2 * SGen is licensed under the terms of the MIT X11 license
4 * Copyright 2001-2003 Ximian, Inc
5 * Copyright 2003-2010 Novell, Inc.
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 #if defined(MONO_CROSS_COMPILE)
33 #define REDZONE_SIZE 0
35 #define ARCH_NUM_REGS 0
36 #define ARCH_STORE_REGS(ptr)
37 #define ARCH_SIGCTX_SP(ctx) NULL
38 #define ARCH_SIGCTX_IP(ctx) NULL
39 #define ARCH_COPY_SIGCTX_REGS(a,ctx)
41 #elif defined(TARGET_X86)
43 #include <mono/utils/mono-context.h>
45 #define REDZONE_SIZE 0
47 #define ARCH_NUM_REGS 8
49 #ifdef MONO_ARCH_HAS_MONO_CONTEXT
53 #define ARCH_STORE_REGS(ptr) __asm { \
54 __asm mov [ptr], edi \
55 __asm mov [ptr+4], esi \
56 __asm mov [ptr+8], ebx \
57 __asm mov [ptr+12], edx \
58 __asm mov [ptr+16], ecx \
59 __asm mov [ptr+20], eax \
60 __asm mov [ptr+24], ebp \
61 __asm mov [ptr+28], esp \
64 #define ARCH_STORE_REGS(ptr) \
65 __asm__ __volatile__( \
69 "mov %%edx,12(%0)\n" \
70 "mov %%ecx,16(%0)\n" \
71 "mov %%eax,20(%0)\n" \
72 "mov %%ebp,24(%0)\n" \
73 "mov %%esp,28(%0)\n" \
80 /*FIXME, move this to mono-sigcontext as this is generaly useful.*/
81 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_ESP ((ctx)))
82 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_EIP ((ctx)))
84 #elif defined(TARGET_AMD64)
86 #include <mono/utils/mono-context.h>
88 #define REDZONE_SIZE 128
90 #define ARCH_NUM_REGS 16
93 /*FIXME, move this to mono-sigcontext as this is generaly useful.*/
94 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_RSP (ctx))
95 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_RIP (ctx))
97 #elif defined(TARGET_PPC)
99 #define REDZONE_SIZE 224
101 #define ARCH_NUM_REGS 32
103 #define ARCH_STORE_REGS(ptr) \
104 __asm__ __volatile__( \
110 #define ARCH_STORE_REGS(ptr) \
111 __asm__ __volatile__( \
117 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_Rn((ctx), 1))
118 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_NIP((ctx)))
119 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
121 for (__i = 0; __i < 32; ++__i) \
122 ((a)[__i]) = UCONTEXT_REG_Rn((ctx), __i); \
125 #elif defined(TARGET_ARM)
127 #define REDZONE_SIZE 0
130 /* We dont store ip, sp */
131 #define ARCH_NUM_REGS 14
132 #define ARCH_STORE_REGS(ptr) \
133 __asm__ __volatile__( \
136 "stmia lr!, {r0-r12}\n" \
142 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_SP((ctx)))
143 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_PC((ctx)))
144 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
145 ((a)[0]) = (gpointer) (UCONTEXT_REG_R0((ctx))); \
146 ((a)[1]) = (gpointer) (UCONTEXT_REG_R1((ctx))); \
147 ((a)[2]) = (gpointer) (UCONTEXT_REG_R2((ctx))); \
148 ((a)[3]) = (gpointer) (UCONTEXT_REG_R3((ctx))); \
149 ((a)[4]) = (gpointer) (UCONTEXT_REG_R4((ctx))); \
150 ((a)[5]) = (gpointer) (UCONTEXT_REG_R5((ctx))); \
151 ((a)[6]) = (gpointer) (UCONTEXT_REG_R6((ctx))); \
152 ((a)[7]) = (gpointer) (UCONTEXT_REG_R7((ctx))); \
153 ((a)[8]) = (gpointer) (UCONTEXT_REG_R8((ctx))); \
154 ((a)[9]) = (gpointer) (UCONTEXT_REG_R9((ctx))); \
155 ((a)[10]) = (gpointer) (UCONTEXT_REG_R10((ctx))); \
156 ((a)[11]) = (gpointer) (UCONTEXT_REG_R11((ctx))); \
157 ((a)[12]) = (gpointer) (UCONTEXT_REG_R12((ctx))); \
158 ((a)[13]) = (gpointer) (UCONTEXT_REG_LR((ctx))); \
161 #elif defined(__mips__)
163 #define REDZONE_SIZE 0
166 #define ARCH_NUM_REGS 32
168 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_GREGS((ctx))[29])
169 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_PC((ctx)))
171 #elif defined(__s390x__)
173 #define REDZONE_SIZE 0
175 #include <mono/utils/mono-context.h>
178 #define ARCH_NUM_REGS 16
179 #define ARCH_SIGCTX_SP(ctx) ((UCONTEXT_GREGS((ctx))) [15])
180 #define ARCH_SIGCTX_IP(ctx) ((ucontext_t *) (ctx))->uc_mcontext.psw.addr
182 #elif defined(__sparc__)
184 #define REDZONE_SIZE 0
186 /* Don't bother with %g0 (%r0), it's always hard-coded to zero */
187 #define ARCH_NUM_REGS 15
189 #define ARCH_STORE_REGS(ptr) \
190 __asm__ __volatile__( \
192 "st %%g2,[%0+0x08]\n\t" \
193 "st %%g3,[%0+0x10]\n\t" \
194 "st %%g4,[%0+0x18]\n\t" \
195 "st %%g5,[%0+0x20]\n\t" \
196 "st %%g6,[%0+0x28]\n\t" \
197 "st %%g7,[%0+0x30]\n\t" \
198 "st %%o0,[%0+0x38]\n\t" \
199 "st %%o1,[%0+0x40]\n\t" \
200 "st %%o2,[%0+0x48]\n\t" \
201 "st %%o3,[%0+0x50]\n\t" \
202 "st %%o4,[%0+0x58]\n\t" \
203 "st %%o5,[%0+0x60]\n\t" \
204 "st %%o6,[%0+0x68]\n\t" \
205 "st %%o7,[%0+0x70]\n\t" \
211 #define ARCH_STORE_REGS(ptr) \
212 __asm__ __volatile__( \
214 "st %%g2,[%0+0x04]\n\t" \
215 "st %%g3,[%0+0x08]\n\t" \
216 "st %%g4,[%0+0x0c]\n\t" \
217 "st %%g5,[%0+0x10]\n\t" \
218 "st %%g6,[%0+0x14]\n\t" \
219 "st %%g7,[%0+0x18]\n\t" \
220 "st %%o0,[%0+0x1c]\n\t" \
221 "st %%o1,[%0+0x20]\n\t" \
222 "st %%o2,[%0+0x24]\n\t" \
223 "st %%o3,[%0+0x28]\n\t" \
224 "st %%o4,[%0+0x2c]\n\t" \
225 "st %%o5,[%0+0x30]\n\t" \
226 "st %%o6,[%0+0x34]\n\t" \
227 "st %%o7,[%0+0x38]\n\t" \
234 #define ARCH_SIGCTX_SP(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_SP])
235 #define ARCH_SIGCTX_IP(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_PC])
236 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
237 (a)[0] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G1]); \
238 (a)[1] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G2]); \
239 (a)[2] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G3]); \
240 (a)[3] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G4]); \
241 (a)[4] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G5]); \
242 (a)[5] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G6]); \
243 (a)[6] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G7]); \
244 (a)[7] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O0]); \
245 (a)[8] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O1]); \
246 (a)[9] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O2]); \
247 (a)[10] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O3]); \
248 (a)[11] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O4]); \
249 (a)[12] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O5]); \
250 (a)[13] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O6]); \
251 (a)[14] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O7]); \
256 #endif /* __MONO_SGENARCHDEP_H__ */