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(__i386__) || defined(TARGET_X86)
33 #include <mono/utils/mono-context.h>
35 #define REDZONE_SIZE 0
37 #define ARCH_NUM_REGS 8
39 #ifdef MONO_ARCH_HAS_MONO_CONTEXT
43 #define ARCH_STORE_REGS(ptr) __asm { \
44 __asm mov [ptr], edi \
45 __asm mov [ptr+4], esi \
46 __asm mov [ptr+8], ebx \
47 __asm mov [ptr+12], edx \
48 __asm mov [ptr+16], ecx \
49 __asm mov [ptr+20], eax \
50 __asm mov [ptr+24], ebp \
51 __asm mov [ptr+28], esp \
54 #define ARCH_STORE_REGS(ptr) \
55 __asm__ __volatile__( \
59 "mov %%edx,12(%0)\n" \
60 "mov %%ecx,16(%0)\n" \
61 "mov %%eax,20(%0)\n" \
62 "mov %%ebp,24(%0)\n" \
63 "mov %%esp,28(%0)\n" \
70 /*FIXME, move this to mono-sigcontext as this is generaly useful.*/
71 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_ESP ((ctx)))
72 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_EIP ((ctx)))
74 #elif defined(__x86_64__) || defined(TARGET_AMD64)
76 #include <mono/utils/mono-context.h>
78 #define REDZONE_SIZE 128
80 #define ARCH_NUM_REGS 16
83 /*FIXME, move this to mono-sigcontext as this is generaly useful.*/
84 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_RSP (ctx))
85 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_RIP (ctx))
87 #elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc64__)
89 #define REDZONE_SIZE 224
91 #define ARCH_NUM_REGS 32
93 #define ARCH_STORE_REGS(ptr) \
94 __asm__ __volatile__( \
100 #define ARCH_STORE_REGS(ptr) \
101 __asm__ __volatile__( \
107 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_Rn((ctx), 1))
108 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_NIP((ctx)))
109 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
111 for (__i = 0; __i < 32; ++__i) \
112 ((a)[__i]) = UCONTEXT_REG_Rn((ctx), __i); \
115 #elif defined(__arm__)
117 #define REDZONE_SIZE 0
119 /* We dont store ip, sp */
120 #define ARCH_NUM_REGS 14
121 #define ARCH_STORE_REGS(ptr) \
122 __asm__ __volatile__( \
125 "stmia lr!, {r0-r12}\n" \
131 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_SP((ctx)))
132 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_PC((ctx)))
133 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
134 ((a)[0]) = (gpointer) (UCONTEXT_REG_R0((ctx))); \
135 ((a)[1]) = (gpointer) (UCONTEXT_REG_R1((ctx))); \
136 ((a)[2]) = (gpointer) (UCONTEXT_REG_R2((ctx))); \
137 ((a)[3]) = (gpointer) (UCONTEXT_REG_R3((ctx))); \
138 ((a)[4]) = (gpointer) (UCONTEXT_REG_R4((ctx))); \
139 ((a)[5]) = (gpointer) (UCONTEXT_REG_R5((ctx))); \
140 ((a)[6]) = (gpointer) (UCONTEXT_REG_R6((ctx))); \
141 ((a)[7]) = (gpointer) (UCONTEXT_REG_R7((ctx))); \
142 ((a)[8]) = (gpointer) (UCONTEXT_REG_R8((ctx))); \
143 ((a)[9]) = (gpointer) (UCONTEXT_REG_R9((ctx))); \
144 ((a)[10]) = (gpointer) (UCONTEXT_REG_R10((ctx))); \
145 ((a)[11]) = (gpointer) (UCONTEXT_REG_R11((ctx))); \
146 ((a)[12]) = (gpointer) (UCONTEXT_REG_R12((ctx))); \
147 ((a)[13]) = (gpointer) (UCONTEXT_REG_LR((ctx))); \
150 #elif defined(__mips__)
152 #define REDZONE_SIZE 0
155 #define ARCH_NUM_REGS 32
157 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_GREGS((ctx))[29])
158 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_PC((ctx)))
160 #elif defined(__s390x__)
162 #define REDZONE_SIZE 0
164 #include <mono/utils/mono-context.h>
167 #define ARCH_NUM_REGS 16
168 #define ARCH_SIGCTX_SP(ctx) ((UCONTEXT_GREGS((ctx))) [15])
169 #define ARCH_SIGCTX_IP(ctx) ((ucontext_t *) (ctx))->uc_mcontext.psw.addr
171 #elif defined(__sparc__)
173 #define REDZONE_SIZE 0
175 /* Don't bother with %g0 (%r0), it's always hard-coded to zero */
176 #define ARCH_NUM_REGS 15
178 #define ARCH_STORE_REGS(ptr) \
179 __asm__ __volatile__( \
181 "st %%g2,[%0+0x08]\n\t" \
182 "st %%g3,[%0+0x10]\n\t" \
183 "st %%g4,[%0+0x18]\n\t" \
184 "st %%g5,[%0+0x20]\n\t" \
185 "st %%g6,[%0+0x28]\n\t" \
186 "st %%g7,[%0+0x30]\n\t" \
187 "st %%o0,[%0+0x38]\n\t" \
188 "st %%o1,[%0+0x40]\n\t" \
189 "st %%o2,[%0+0x48]\n\t" \
190 "st %%o3,[%0+0x50]\n\t" \
191 "st %%o4,[%0+0x58]\n\t" \
192 "st %%o5,[%0+0x60]\n\t" \
193 "st %%o6,[%0+0x68]\n\t" \
194 "st %%o7,[%0+0x70]\n\t" \
200 #define ARCH_STORE_REGS(ptr) \
201 __asm__ __volatile__( \
203 "st %%g2,[%0+0x04]\n\t" \
204 "st %%g3,[%0+0x08]\n\t" \
205 "st %%g4,[%0+0x0c]\n\t" \
206 "st %%g5,[%0+0x10]\n\t" \
207 "st %%g6,[%0+0x14]\n\t" \
208 "st %%g7,[%0+0x18]\n\t" \
209 "st %%o0,[%0+0x1c]\n\t" \
210 "st %%o1,[%0+0x20]\n\t" \
211 "st %%o2,[%0+0x24]\n\t" \
212 "st %%o3,[%0+0x28]\n\t" \
213 "st %%o4,[%0+0x2c]\n\t" \
214 "st %%o5,[%0+0x30]\n\t" \
215 "st %%o6,[%0+0x34]\n\t" \
216 "st %%o7,[%0+0x38]\n\t" \
223 #define ARCH_SIGCTX_SP(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_SP])
224 #define ARCH_SIGCTX_IP(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_PC])
225 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
226 (a)[0] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G1]); \
227 (a)[1] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G2]); \
228 (a)[2] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G3]); \
229 (a)[3] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G4]); \
230 (a)[4] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G5]); \
231 (a)[5] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G6]); \
232 (a)[6] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G7]); \
233 (a)[7] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O0]); \
234 (a)[8] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O1]); \
235 (a)[9] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O2]); \
236 (a)[10] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O3]); \
237 (a)[11] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O4]); \
238 (a)[12] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O5]); \
239 (a)[13] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O6]); \
240 (a)[14] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O7]); \
245 #endif /* __MONO_SGENARCHDEP_H__ */