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
48 #define ARCH_STORE_REGS(ptr) __asm { \
49 __asm mov [ptr], edi \
50 __asm mov [ptr+4], esi \
51 __asm mov [ptr+8], ebx \
52 __asm mov [ptr+12], edx \
53 __asm mov [ptr+16], ecx \
54 __asm mov [ptr+20], eax \
55 __asm mov [ptr+24], ebp \
56 __asm mov [ptr+28], esp \
59 #define ARCH_STORE_REGS(ptr) \
60 __asm__ __volatile__( \
64 "mov %%edx,12(%0)\n" \
65 "mov %%ecx,16(%0)\n" \
66 "mov %%eax,20(%0)\n" \
67 "mov %%ebp,24(%0)\n" \
68 "mov %%esp,28(%0)\n" \
75 /*FIXME, move this to mono-sigcontext as this is generaly useful.*/
76 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_ESP ((ctx)))
77 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_EIP ((ctx)))
79 #elif defined(TARGET_AMD64)
81 #include <mono/utils/mono-context.h>
83 #define REDZONE_SIZE 128
85 #define ARCH_NUM_REGS 16
88 /*FIXME, move this to mono-sigcontext as this is generaly useful.*/
89 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_RSP (ctx))
90 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_RIP (ctx))
92 #elif defined(TARGET_PPC)
94 #define REDZONE_SIZE 224
96 #define ARCH_NUM_REGS 32
98 #define ARCH_STORE_REGS(ptr) \
99 __asm__ __volatile__( \
105 #define ARCH_STORE_REGS(ptr) \
106 __asm__ __volatile__( \
112 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_Rn((ctx), 1))
113 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_NIP((ctx)))
114 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
116 for (__i = 0; __i < 32; ++__i) \
117 ((a)[__i]) = UCONTEXT_REG_Rn((ctx), __i); \
120 #elif defined(TARGET_ARM)
122 #define REDZONE_SIZE 0
125 /* We dont store ip, sp */
126 #define ARCH_NUM_REGS 14
127 #define ARCH_STORE_REGS(ptr) \
128 __asm__ __volatile__( \
131 "stmia lr!, {r0-r12}\n" \
137 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_SP((ctx)))
138 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_PC((ctx)))
139 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
140 ((a)[0]) = (gpointer) (UCONTEXT_REG_R0((ctx))); \
141 ((a)[1]) = (gpointer) (UCONTEXT_REG_R1((ctx))); \
142 ((a)[2]) = (gpointer) (UCONTEXT_REG_R2((ctx))); \
143 ((a)[3]) = (gpointer) (UCONTEXT_REG_R3((ctx))); \
144 ((a)[4]) = (gpointer) (UCONTEXT_REG_R4((ctx))); \
145 ((a)[5]) = (gpointer) (UCONTEXT_REG_R5((ctx))); \
146 ((a)[6]) = (gpointer) (UCONTEXT_REG_R6((ctx))); \
147 ((a)[7]) = (gpointer) (UCONTEXT_REG_R7((ctx))); \
148 ((a)[8]) = (gpointer) (UCONTEXT_REG_R8((ctx))); \
149 ((a)[9]) = (gpointer) (UCONTEXT_REG_R9((ctx))); \
150 ((a)[10]) = (gpointer) (UCONTEXT_REG_R10((ctx))); \
151 ((a)[11]) = (gpointer) (UCONTEXT_REG_R11((ctx))); \
152 ((a)[12]) = (gpointer) (UCONTEXT_REG_R12((ctx))); \
153 ((a)[13]) = (gpointer) (UCONTEXT_REG_LR((ctx))); \
156 #elif defined(__mips__)
158 #define REDZONE_SIZE 0
161 #define ARCH_NUM_REGS 32
163 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_GREGS((ctx))[29])
164 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_PC((ctx)))
166 #elif defined(__s390x__)
168 #define REDZONE_SIZE 0
170 #include <mono/utils/mono-context.h>
173 #define ARCH_NUM_REGS 16
174 #define ARCH_SIGCTX_SP(ctx) ((UCONTEXT_GREGS((ctx))) [15])
175 #define ARCH_SIGCTX_IP(ctx) ((ucontext_t *) (ctx))->uc_mcontext.psw.addr
177 #elif defined(__sparc__)
179 #define REDZONE_SIZE 0
181 /* Don't bother with %g0 (%r0), it's always hard-coded to zero */
182 #define ARCH_NUM_REGS 15
184 #define ARCH_STORE_REGS(ptr) \
185 __asm__ __volatile__( \
187 "st %%g2,[%0+0x08]\n\t" \
188 "st %%g3,[%0+0x10]\n\t" \
189 "st %%g4,[%0+0x18]\n\t" \
190 "st %%g5,[%0+0x20]\n\t" \
191 "st %%g6,[%0+0x28]\n\t" \
192 "st %%g7,[%0+0x30]\n\t" \
193 "st %%o0,[%0+0x38]\n\t" \
194 "st %%o1,[%0+0x40]\n\t" \
195 "st %%o2,[%0+0x48]\n\t" \
196 "st %%o3,[%0+0x50]\n\t" \
197 "st %%o4,[%0+0x58]\n\t" \
198 "st %%o5,[%0+0x60]\n\t" \
199 "st %%o6,[%0+0x68]\n\t" \
200 "st %%o7,[%0+0x70]\n\t" \
206 #define ARCH_STORE_REGS(ptr) \
207 __asm__ __volatile__( \
209 "st %%g2,[%0+0x04]\n\t" \
210 "st %%g3,[%0+0x08]\n\t" \
211 "st %%g4,[%0+0x0c]\n\t" \
212 "st %%g5,[%0+0x10]\n\t" \
213 "st %%g6,[%0+0x14]\n\t" \
214 "st %%g7,[%0+0x18]\n\t" \
215 "st %%o0,[%0+0x1c]\n\t" \
216 "st %%o1,[%0+0x20]\n\t" \
217 "st %%o2,[%0+0x24]\n\t" \
218 "st %%o3,[%0+0x28]\n\t" \
219 "st %%o4,[%0+0x2c]\n\t" \
220 "st %%o5,[%0+0x30]\n\t" \
221 "st %%o6,[%0+0x34]\n\t" \
222 "st %%o7,[%0+0x38]\n\t" \
229 #define ARCH_SIGCTX_SP(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_SP])
230 #define ARCH_SIGCTX_IP(ctx) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_PC])
231 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
232 (a)[0] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G1]); \
233 (a)[1] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G2]); \
234 (a)[2] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G3]); \
235 (a)[3] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G4]); \
236 (a)[4] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G5]); \
237 (a)[5] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G6]); \
238 (a)[6] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G7]); \
239 (a)[7] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O0]); \
240 (a)[8] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O1]); \
241 (a)[9] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O2]); \
242 (a)[10] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O3]); \
243 (a)[11] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O4]); \
244 (a)[12] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O5]); \
245 (a)[13] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O6]); \
246 (a)[14] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O7]); \
251 #endif /* __MONO_SGENARCHDEP_H__ */