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>
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
42 #define ARCH_STORE_REGS(ptr) \
43 __asm__ __volatile__( \
47 "mov %%edx,12(%0)\n" \
48 "mov %%ecx,16(%0)\n" \
49 "mov %%eax,20(%0)\n" \
50 "mov %%ebp,24(%0)\n" \
51 "mov %%esp,28(%0)\n" \
57 /*FIXME, move this to mono-sigcontext as this is generaly useful.*/
58 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_ESP ((ctx)))
59 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_EIP ((ctx)))
61 #elif defined(__x86_64__)
63 #include <mono/utils/mono-context.h>
65 #define REDZONE_SIZE 128
67 #define ARCH_NUM_REGS 16
70 /*FIXME, move this to mono-sigcontext as this is generaly useful.*/
71 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_RSP (ctx))
72 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_RIP (ctx))
74 #elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc64__)
76 #define REDZONE_SIZE 224
78 #define ARCH_NUM_REGS 32
80 #define ARCH_STORE_REGS(ptr) \
81 __asm__ __volatile__( \
87 #define ARCH_STORE_REGS(ptr) \
88 __asm__ __volatile__( \
94 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_Rn((ctx), 1))
95 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_NIP((ctx)))
96 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
98 for (__i = 0; __i < 32; ++__i) \
99 ((a)[__i]) = UCONTEXT_REG_Rn((ctx), __i); \
102 #elif defined(__arm__)
104 #define REDZONE_SIZE 0
106 /* We dont store ip, sp */
107 #define ARCH_NUM_REGS 14
108 #define ARCH_STORE_REGS(ptr) \
109 __asm__ __volatile__( \
112 "stmia lr!, {r0-r12}\n" \
118 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_SP((ctx)))
119 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_PC((ctx)))
120 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
121 ((a)[0]) = (gpointer) (UCONTEXT_REG_R0((ctx))); \
122 ((a)[1]) = (gpointer) (UCONTEXT_REG_R1((ctx))); \
123 ((a)[2]) = (gpointer) (UCONTEXT_REG_R2((ctx))); \
124 ((a)[3]) = (gpointer) (UCONTEXT_REG_R3((ctx))); \
125 ((a)[4]) = (gpointer) (UCONTEXT_REG_R4((ctx))); \
126 ((a)[5]) = (gpointer) (UCONTEXT_REG_R5((ctx))); \
127 ((a)[6]) = (gpointer) (UCONTEXT_REG_R6((ctx))); \
128 ((a)[7]) = (gpointer) (UCONTEXT_REG_R7((ctx))); \
129 ((a)[8]) = (gpointer) (UCONTEXT_REG_R8((ctx))); \
130 ((a)[9]) = (gpointer) (UCONTEXT_REG_R9((ctx))); \
131 ((a)[10]) = (gpointer) (UCONTEXT_REG_R10((ctx))); \
132 ((a)[11]) = (gpointer) (UCONTEXT_REG_R11((ctx))); \
133 ((a)[12]) = (gpointer) (UCONTEXT_REG_R12((ctx))); \
134 ((a)[13]) = (gpointer) (UCONTEXT_REG_LR((ctx))); \
137 #elif defined(__mips__)
139 #define REDZONE_SIZE 0
142 #define ARCH_NUM_REGS 32
144 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_GREGS((ctx))[29])
145 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_PC((ctx)))
147 #elif defined(__s390x__)
149 #define REDZONE_SIZE 0
151 #include <mono/utils/mono-context.h>
154 #define ARCH_NUM_REGS 16
155 #define ARCH_SIGCTX_SP(ctx) ((UCONTEXT_GREGS((ctx))) [15])
156 #define ARCH_SIGCTX_IP(ctx) ((ucontext_t *) (ctx))->uc_mcontext.psw.addr
158 #elif defined(__sparc__)
160 #define REDZONE_SIZE 0
162 /* Don't bother with %g0 (%r0), it's always hard-coded to zero */
163 #define ARCH_NUM_REGS 15
165 #define ARCH_STORE_REGS(ptr) \
166 __asm__ __volatile__( \
168 "st %%g2,[%0+0x08]\n\t" \
169 "st %%g3,[%0+0x10]\n\t" \
170 "st %%g4,[%0+0x18]\n\t" \
171 "st %%g5,[%0+0x20]\n\t" \
172 "st %%g6,[%0+0x28]\n\t" \
173 "st %%g7,[%0+0x30]\n\t" \
174 "st %%o0,[%0+0x38]\n\t" \
175 "st %%o1,[%0+0x40]\n\t" \
176 "st %%o2,[%0+0x48]\n\t" \
177 "st %%o3,[%0+0x50]\n\t" \
178 "st %%o4,[%0+0x58]\n\t" \
179 "st %%o5,[%0+0x60]\n\t" \
180 "st %%o6,[%0+0x68]\n\t" \
181 "st %%o7,[%0+0x70]\n\t" \
187 #define ARCH_STORE_REGS(ptr) \
188 __asm__ __volatile__( \
190 "st %%g2,[%0+0x04]\n\t" \
191 "st %%g3,[%0+0x08]\n\t" \
192 "st %%g4,[%0+0x0c]\n\t" \
193 "st %%g5,[%0+0x10]\n\t" \
194 "st %%g6,[%0+0x14]\n\t" \
195 "st %%g7,[%0+0x18]\n\t" \
196 "st %%o0,[%0+0x1c]\n\t" \
197 "st %%o1,[%0+0x20]\n\t" \
198 "st %%o2,[%0+0x24]\n\t" \
199 "st %%o3,[%0+0x28]\n\t" \
200 "st %%o4,[%0+0x2c]\n\t" \
201 "st %%o5,[%0+0x30]\n\t" \
202 "st %%o6,[%0+0x34]\n\t" \
203 "st %%o7,[%0+0x38]\n\t" \
210 #define ARCH_SIGCTX_SP(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_SP])
211 #define ARCH_SIGCTX_IP(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_PC])
212 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
213 (a)[0] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G1]); \
214 (a)[1] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G2]); \
215 (a)[2] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G3]); \
216 (a)[3] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G4]); \
217 (a)[4] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G5]); \
218 (a)[5] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G6]); \
219 (a)[6] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G7]); \
220 (a)[7] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O0]); \
221 (a)[8] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O1]); \
222 (a)[9] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O2]); \
223 (a)[10] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O3]); \
224 (a)[11] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O4]); \
225 (a)[12] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O5]); \
226 (a)[13] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O6]); \
227 (a)[14] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O7]); \
232 #endif /* __MONO_SGENARCHDEP_H__ */