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
40 /*FIXME, move this to mono-sigcontext as this is generaly useful.*/
41 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_ESP ((ctx)))
42 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_EIP ((ctx)))
44 #elif defined(__x86_64__)
46 #include <mono/utils/mono-context.h>
48 #define REDZONE_SIZE 128
50 #define ARCH_NUM_REGS 16
53 /*FIXME, move this to mono-sigcontext as this is generaly useful.*/
54 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_RSP (ctx))
55 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_RIP (ctx))
57 #elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc64__)
59 #define REDZONE_SIZE 224
61 #define ARCH_NUM_REGS 32
63 #define ARCH_STORE_REGS(ptr) \
64 __asm__ __volatile__( \
70 #define ARCH_STORE_REGS(ptr) \
71 __asm__ __volatile__( \
77 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_Rn((ctx), 1))
78 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_NIP((ctx)))
79 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
81 for (__i = 0; __i < 32; ++__i) \
82 ((a)[__i]) = UCONTEXT_REG_Rn((ctx), __i); \
85 #elif defined(__arm__)
87 #define REDZONE_SIZE 0
89 /* We dont store ip, sp */
90 #define ARCH_NUM_REGS 14
91 #define ARCH_STORE_REGS(ptr) \
92 __asm__ __volatile__( \
95 "stmia lr!, {r0-r12}\n" \
101 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_SP((ctx)))
102 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_PC((ctx)))
103 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
104 ((a)[0]) = (gpointer) (UCONTEXT_REG_R0((ctx))); \
105 ((a)[1]) = (gpointer) (UCONTEXT_REG_R1((ctx))); \
106 ((a)[2]) = (gpointer) (UCONTEXT_REG_R2((ctx))); \
107 ((a)[3]) = (gpointer) (UCONTEXT_REG_R3((ctx))); \
108 ((a)[4]) = (gpointer) (UCONTEXT_REG_R4((ctx))); \
109 ((a)[5]) = (gpointer) (UCONTEXT_REG_R5((ctx))); \
110 ((a)[6]) = (gpointer) (UCONTEXT_REG_R6((ctx))); \
111 ((a)[7]) = (gpointer) (UCONTEXT_REG_R7((ctx))); \
112 ((a)[8]) = (gpointer) (UCONTEXT_REG_R8((ctx))); \
113 ((a)[9]) = (gpointer) (UCONTEXT_REG_R9((ctx))); \
114 ((a)[10]) = (gpointer) (UCONTEXT_REG_R10((ctx))); \
115 ((a)[11]) = (gpointer) (UCONTEXT_REG_R11((ctx))); \
116 ((a)[12]) = (gpointer) (UCONTEXT_REG_R12((ctx))); \
117 ((a)[13]) = (gpointer) (UCONTEXT_REG_LR((ctx))); \
120 #elif defined(__s390x__)
122 #define REDZONE_SIZE 0
124 #include <mono/utils/mono-context.h>
127 #define ARCH_NUM_REGS 16
128 #define ARCH_SIGCTX_SP(ctx) ((UCONTEXT_GREGS((ctx))) [15])
129 #define ARCH_SIGCTX_IP(ctx) ((ucontext_t *) (ctx))->uc_mcontext.psw.addr
131 #elif defined(__sparc__)
133 #define REDZONE_SIZE 0
135 /* Don't bother with %g0 (%r0), it's always hard-coded to zero */
136 #define ARCH_NUM_REGS 15
138 #define ARCH_STORE_REGS(ptr) \
139 __asm__ __volatile__( \
141 "st %%g2,[%0+0x08]\n\t" \
142 "st %%g3,[%0+0x10]\n\t" \
143 "st %%g4,[%0+0x18]\n\t" \
144 "st %%g5,[%0+0x20]\n\t" \
145 "st %%g6,[%0+0x28]\n\t" \
146 "st %%g7,[%0+0x30]\n\t" \
147 "st %%o0,[%0+0x38]\n\t" \
148 "st %%o1,[%0+0x40]\n\t" \
149 "st %%o2,[%0+0x48]\n\t" \
150 "st %%o3,[%0+0x50]\n\t" \
151 "st %%o4,[%0+0x58]\n\t" \
152 "st %%o5,[%0+0x60]\n\t" \
153 "st %%o6,[%0+0x68]\n\t" \
154 "st %%o7,[%0+0x70]\n\t" \
160 #define ARCH_STORE_REGS(ptr) \
161 __asm__ __volatile__( \
163 "st %%g2,[%0+0x04]\n\t" \
164 "st %%g3,[%0+0x08]\n\t" \
165 "st %%g4,[%0+0x0c]\n\t" \
166 "st %%g5,[%0+0x10]\n\t" \
167 "st %%g6,[%0+0x14]\n\t" \
168 "st %%g7,[%0+0x18]\n\t" \
169 "st %%o0,[%0+0x1c]\n\t" \
170 "st %%o1,[%0+0x20]\n\t" \
171 "st %%o2,[%0+0x24]\n\t" \
172 "st %%o3,[%0+0x28]\n\t" \
173 "st %%o4,[%0+0x2c]\n\t" \
174 "st %%o5,[%0+0x30]\n\t" \
175 "st %%o6,[%0+0x34]\n\t" \
176 "st %%o7,[%0+0x38]\n\t" \
183 #define ARCH_SIGCTX_SP(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_SP])
184 #define ARCH_SIGCTX_IP(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_PC])
185 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
186 (a)[0] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G1]); \
187 (a)[1] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G2]); \
188 (a)[2] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G3]); \
189 (a)[3] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G4]); \
190 (a)[4] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G5]); \
191 (a)[5] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G6]); \
192 (a)[6] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G7]); \
193 (a)[7] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O0]); \
194 (a)[8] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O1]); \
195 (a)[9] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O2]); \
196 (a)[10] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O3]); \
197 (a)[11] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O4]); \
198 (a)[12] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O5]); \
199 (a)[13] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O6]); \
200 (a)[14] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O7]); \
205 #endif /* __MONO_SGENARCHDEP_H__ */