2 * sgen-archdep.h: Architecture dependent parts of SGen.
4 * Copyright 2001-2003 Ximian, Inc
5 * Copyright 2003-2010 Novell, Inc.
6 * Copyright (C) 2012 Xamarin Inc
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License 2.0 as published by the Free Software Foundation;
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License 2.0 along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __MONO_SGENARCHDEP_H__
22 #define __MONO_SGENARCHDEP_H__
24 #include <mono/utils/mono-sigcontext.h>
26 #if defined(MONO_CROSS_COMPILE)
28 #define REDZONE_SIZE 0
30 #define ARCH_NUM_REGS 0
31 #define ARCH_STORE_REGS(ptr)
32 #define ARCH_SIGCTX_SP(ctx) NULL
33 #define ARCH_SIGCTX_IP(ctx) NULL
34 #define ARCH_COPY_SIGCTX_REGS(a,ctx)
36 #elif defined(TARGET_X86)
38 #include <mono/utils/mono-context.h>
40 #define REDZONE_SIZE 0
42 #define ARCH_NUM_REGS 8
44 #ifdef MONO_ARCH_HAS_MONO_CONTEXT
50 /*FIXME, move this to mono-sigcontext as this is generaly useful.*/
51 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_ESP ((ctx)))
52 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_EIP ((ctx)))
54 #elif defined(TARGET_AMD64)
56 #include <mono/utils/mono-context.h>
58 #define REDZONE_SIZE 128
60 #define ARCH_NUM_REGS 16
63 /*FIXME, move this to mono-sigcontext as this is generaly useful.*/
64 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_RSP (ctx))
65 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_RIP (ctx))
67 #elif defined(TARGET_POWERPC)
69 #define REDZONE_SIZE 224
71 #define ARCH_NUM_REGS 32
73 #define ARCH_STORE_REGS(ptr) \
74 __asm__ __volatile__( \
80 #define ARCH_STORE_REGS(ptr) \
81 __asm__ __volatile__( \
87 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_Rn((ctx), 1))
88 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_NIP((ctx)))
89 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
91 for (__i = 0; __i < 32; ++__i) \
92 ((a)[__i]) = (gpointer) UCONTEXT_REG_Rn((ctx), __i); \
95 #elif defined(TARGET_ARM)
97 #define REDZONE_SIZE 0
100 /* We dont store ip, sp */
101 #define ARCH_NUM_REGS 14
102 #define ARCH_STORE_REGS(ptr) \
103 __asm__ __volatile__( \
106 "stmia lr!, {r0-r12}\n" \
112 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_SP((ctx)))
113 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_PC((ctx)))
114 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
115 ((a)[0]) = (gpointer) (UCONTEXT_REG_R0((ctx))); \
116 ((a)[1]) = (gpointer) (UCONTEXT_REG_R1((ctx))); \
117 ((a)[2]) = (gpointer) (UCONTEXT_REG_R2((ctx))); \
118 ((a)[3]) = (gpointer) (UCONTEXT_REG_R3((ctx))); \
119 ((a)[4]) = (gpointer) (UCONTEXT_REG_R4((ctx))); \
120 ((a)[5]) = (gpointer) (UCONTEXT_REG_R5((ctx))); \
121 ((a)[6]) = (gpointer) (UCONTEXT_REG_R6((ctx))); \
122 ((a)[7]) = (gpointer) (UCONTEXT_REG_R7((ctx))); \
123 ((a)[8]) = (gpointer) (UCONTEXT_REG_R8((ctx))); \
124 ((a)[9]) = (gpointer) (UCONTEXT_REG_R9((ctx))); \
125 ((a)[10]) = (gpointer) (UCONTEXT_REG_R10((ctx))); \
126 ((a)[11]) = (gpointer) (UCONTEXT_REG_R11((ctx))); \
127 ((a)[12]) = (gpointer) (UCONTEXT_REG_R12((ctx))); \
128 ((a)[13]) = (gpointer) (UCONTEXT_REG_LR((ctx))); \
131 #elif defined(TARGET_ARM64)
133 #include <mono/utils/mono-sigcontext.h>
136 #define REDZONE_SIZE 0
137 #elif defined(__APPLE__)
138 #define REDZONE_SIZE 128
140 #error "Not implemented."
143 #define ARCH_NUM_REGS 31
145 #define ARCH_STORE_REGS(ptr) do { g_assert_not_reached (); } while (0)
147 #define ARCH_SIGCTX_SP(ctx) UCONTEXT_REG_SP (ctx)
148 #define ARCH_SIGCTX_IP(ctx) UCONTEXT_REG_PC (ctx)
149 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { g_assert_not_reached (); } while (0)
151 #elif defined(__mips__)
153 #define REDZONE_SIZE 0
156 #define ARCH_NUM_REGS 32
159 * These casts are necessary since glibc always makes the
160 * gregs 64-bit values in userland.
162 #define ARCH_SIGCTX_SP(ctx) ((gsize) UCONTEXT_GREGS((ctx))[29])
163 #define ARCH_SIGCTX_IP(ctx) ((gsize) UCONTEXT_REG_PC((ctx)))
165 #elif defined(__s390x__)
167 #define REDZONE_SIZE 0
169 #include <mono/utils/mono-context.h>
172 #define ARCH_NUM_REGS 16
173 #define ARCH_SIGCTX_SP(ctx) ((UCONTEXT_GREGS((ctx))) [15])
174 #define ARCH_SIGCTX_IP(ctx) ((ucontext_t *) (ctx))->uc_mcontext.psw.addr
176 #elif defined(__sparc__)
178 #define REDZONE_SIZE 0
180 /* Don't bother with %g0 (%r0), it's always hard-coded to zero */
181 #define ARCH_NUM_REGS 15
183 #define ARCH_STORE_REGS(ptr) \
184 __asm__ __volatile__( \
186 "st %%g2,[%0+0x08]\n\t" \
187 "st %%g3,[%0+0x10]\n\t" \
188 "st %%g4,[%0+0x18]\n\t" \
189 "st %%g5,[%0+0x20]\n\t" \
190 "st %%g6,[%0+0x28]\n\t" \
191 "st %%g7,[%0+0x30]\n\t" \
192 "st %%o0,[%0+0x38]\n\t" \
193 "st %%o1,[%0+0x40]\n\t" \
194 "st %%o2,[%0+0x48]\n\t" \
195 "st %%o3,[%0+0x50]\n\t" \
196 "st %%o4,[%0+0x58]\n\t" \
197 "st %%o5,[%0+0x60]\n\t" \
198 "st %%o6,[%0+0x68]\n\t" \
199 "st %%o7,[%0+0x70]\n\t" \
205 #define ARCH_STORE_REGS(ptr) \
206 __asm__ __volatile__( \
208 "st %%g2,[%0+0x04]\n\t" \
209 "st %%g3,[%0+0x08]\n\t" \
210 "st %%g4,[%0+0x0c]\n\t" \
211 "st %%g5,[%0+0x10]\n\t" \
212 "st %%g6,[%0+0x14]\n\t" \
213 "st %%g7,[%0+0x18]\n\t" \
214 "st %%o0,[%0+0x1c]\n\t" \
215 "st %%o1,[%0+0x20]\n\t" \
216 "st %%o2,[%0+0x24]\n\t" \
217 "st %%o3,[%0+0x28]\n\t" \
218 "st %%o4,[%0+0x2c]\n\t" \
219 "st %%o5,[%0+0x30]\n\t" \
220 "st %%o6,[%0+0x34]\n\t" \
221 "st %%o7,[%0+0x38]\n\t" \
229 #define REG_SP REG_O6
232 #define ARCH_SIGCTX_SP(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_SP])
233 #define ARCH_SIGCTX_IP(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_PC])
234 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
235 (a)[0] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G1]); \
236 (a)[1] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G2]); \
237 (a)[2] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G3]); \
238 (a)[3] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G4]); \
239 (a)[4] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G5]); \
240 (a)[5] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G6]); \
241 (a)[6] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G7]); \
242 (a)[7] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O0]); \
243 (a)[8] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O1]); \
244 (a)[9] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O2]); \
245 (a)[10] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O3]); \
246 (a)[11] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O4]); \
247 (a)[12] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O5]); \
248 (a)[13] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O6]); \
249 (a)[14] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O7]); \
254 #endif /* __MONO_SGENARCHDEP_H__ */