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 #define REDZONE_SIZE 0
35 #define ARCH_NUM_REGS 7 /* we're never storing ESP */
36 #define ARCH_STORE_REGS(ptr) \
37 __asm__ __volatile__( \
38 "mov %%ecx, 0x00(%0)\n" \
39 "mov %%edx, 0x04(%0)\n" \
40 "mov %%ebx, 0x08(%0)\n" \
41 "mov %%edi, 0x0c(%0)\n" \
42 "mov %%esi, 0x10(%0)\n" \
43 "mov %%ebp, 0x14(%0)\n" \
45 : "0" (cur_thread_regs) \
48 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_ESP ((ctx)))
49 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_EIP ((ctx)))
50 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
51 (a)[0] = (gpointer) UCONTEXT_REG_EAX ((ctx)); \
52 (a)[1] = (gpointer) UCONTEXT_REG_EBX ((ctx)); \
53 (a)[2] = (gpointer) UCONTEXT_REG_ECX ((ctx)); \
54 (a)[3] = (gpointer) UCONTEXT_REG_EDX ((ctx)); \
55 (a)[4] = (gpointer) UCONTEXT_REG_ESI ((ctx)); \
56 (a)[5] = (gpointer) UCONTEXT_REG_EDI ((ctx)); \
57 (a)[6] = (gpointer) UCONTEXT_REG_EBP ((ctx)); \
60 #elif defined(__x86_64__)
62 #define REDZONE_SIZE 128
64 #define ARCH_NUM_REGS 15 /* we're never storing RSP */
65 #define ARCH_STORE_REGS(ptr) \
66 __asm__ __volatile__( \
67 "movq %%rcx, 0x00(%0)\n" \
68 "movq %%rdx, 0x08(%0)\n" \
69 "movq %%rbx, 0x10(%0)\n" \
70 "movq %%rdi, 0x18(%0)\n" \
71 "movq %%rsi, 0x20(%0)\n" \
72 "movq %%rbp, 0x28(%0)\n" \
73 "movq %%r8, 0x30(%0)\n" \
74 "movq %%r9, 0x38(%0)\n" \
75 "movq %%r10, 0x40(%0)\n" \
76 "movq %%r11, 0x48(%0)\n" \
77 "movq %%r12, 0x50(%0)\n" \
78 "movq %%r13, 0x58(%0)\n" \
79 "movq %%r14, 0x60(%0)\n" \
80 "movq %%r15, 0x68(%0)\n" \
82 : "0" (cur_thread_regs) \
85 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_RSP (ctx))
86 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_RIP (ctx))
87 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
88 ((a)[0] = (gpointer) (UCONTEXT_REG_RAX (ctx))); \
89 ((a)[1] = (gpointer) (UCONTEXT_REG_RBX (ctx))); \
90 ((a)[2] = (gpointer) (UCONTEXT_REG_RCX (ctx))); \
91 ((a)[3] = (gpointer) (UCONTEXT_REG_RDX (ctx))); \
92 ((a)[4] = (gpointer) (UCONTEXT_REG_RSI (ctx))); \
93 ((a)[5] = (gpointer) (UCONTEXT_REG_RDI (ctx))); \
94 ((a)[6] = (gpointer) (UCONTEXT_REG_RBP (ctx))); \
95 ((a)[7] = (gpointer) (UCONTEXT_REG_R8 (ctx))); \
96 ((a)[8] = (gpointer) (UCONTEXT_REG_R9 (ctx))); \
97 ((a)[9] = (gpointer) (UCONTEXT_REG_R10 (ctx))); \
98 ((a)[10] = (gpointer) (UCONTEXT_REG_R11 (ctx))); \
99 ((a)[11] = (gpointer) (UCONTEXT_REG_R12 (ctx))); \
100 ((a)[12] = (gpointer) (UCONTEXT_REG_R13 (ctx))); \
101 ((a)[13] = (gpointer) (UCONTEXT_REG_R14 (ctx))); \
102 ((a)[14] = (gpointer) (UCONTEXT_REG_R15 (ctx))); \
105 #elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc64__)
107 #define REDZONE_SIZE 224
109 #define ARCH_NUM_REGS 32
111 #define ARCH_STORE_REGS(ptr) \
112 __asm__ __volatile__( \
118 #define ARCH_STORE_REGS(ptr) \
119 __asm__ __volatile__( \
125 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_Rn((ctx), 1))
126 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_NIP((ctx)))
127 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
129 for (__i = 0; __i < 32; ++__i) \
130 ((a)[__i]) = UCONTEXT_REG_Rn((ctx), __i); \
133 #elif defined(__arm__)
135 #define REDZONE_SIZE 0
137 /* We dont store ip, sp */
138 #define ARCH_NUM_REGS 14
139 #define ARCH_STORE_REGS(ptr) \
140 __asm__ __volatile__( \
144 "stmia r12!, {r0-r11}\n" \
146 "stmia r12!, {r0, lr}\n" \
153 #define ARCH_SIGCTX_SP(ctx) (UCONTEXT_REG_SP((ctx)))
154 #define ARCH_SIGCTX_IP(ctx) (UCONTEXT_REG_PC((ctx)))
155 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
156 ((a)[0]) = (gpointer) (UCONTEXT_REG_R0((ctx))); \
157 ((a)[1]) = (gpointer) (UCONTEXT_REG_R1((ctx))); \
158 ((a)[2]) = (gpointer) (UCONTEXT_REG_R2((ctx))); \
159 ((a)[3]) = (gpointer) (UCONTEXT_REG_R3((ctx))); \
160 ((a)[4]) = (gpointer) (UCONTEXT_REG_R4((ctx))); \
161 ((a)[5]) = (gpointer) (UCONTEXT_REG_R5((ctx))); \
162 ((a)[6]) = (gpointer) (UCONTEXT_REG_R6((ctx))); \
163 ((a)[7]) = (gpointer) (UCONTEXT_REG_R7((ctx))); \
164 ((a)[8]) = (gpointer) (UCONTEXT_REG_R8((ctx))); \
165 ((a)[9]) = (gpointer) (UCONTEXT_REG_R9((ctx))); \
166 ((a)[10]) = (gpointer) (UCONTEXT_REG_R10((ctx))); \
167 ((a)[11]) = (gpointer) (UCONTEXT_REG_R11((ctx))); \
168 ((a)[12]) = (gpointer) (UCONTEXT_REG_R12((ctx))); \
169 ((a)[13]) = (gpointer) (UCONTEXT_REG_LR((ctx))); \
172 #elif defined(__s390x__)
174 #define REDZONE_SIZE 0
176 #define ARCH_NUM_REGS 16
177 #define ARCH_STORE_REGS(ptr) \
178 __asm__ __volatile__( \
179 "stg %%r0,0x00(%0)\n\t" \
180 "stg %%r1,0x08(%0)\n\t" \
181 "stg %%r2,0x10(%0)\n\t" \
182 "stg %%r3,0x18(%0)\n\t" \
183 "stg %%r4,0x20(%0)\n\t" \
184 "stg %%r5,0x28(%0)\n\t" \
185 "stg %%r6,0x30(%0)\n\t" \
186 "stg %%r7,0x38(%0)\n\t" \
187 "stg %%r8,0x40(%0)\n\t" \
188 "stg %%r9,0x48(%0)\n\t" \
189 "stg %%r10,0x50(%0)\n\t" \
190 "stg %%r11,0x58(%0)\n\t" \
191 "stg %%r12,0x60(%0)\n\t" \
192 "stg %%r13,0x68(%0)\n\t" \
193 "stg %%r14,0x70(%0)\n\t" \
194 "stg %%r15,0x78(%0)\n" \
196 : "0" (cur_thread_regs) \
199 #define ARCH_SIGCTX_SP(ctx) ((UCONTEXT_GREGS((ctx))) [15])
200 #define ARCH_SIGCTX_IP(ctx) ((ucontext_t *) (ctx))->uc_mcontext.psw.addr
201 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do { \
202 ((a)[0] = (gpointer) (UCONTEXT_GREGS((ctx))) [0]); \
203 ((a)[1] = (gpointer) (UCONTEXT_GREGS((ctx))) [1]); \
204 ((a)[2] = (gpointer) (UCONTEXT_GREGS((ctx))) [2]); \
205 ((a)[3] = (gpointer) (UCONTEXT_GREGS((ctx))) [3]); \
206 ((a)[4] = (gpointer) (UCONTEXT_GREGS((ctx))) [4]); \
207 ((a)[5] = (gpointer) (UCONTEXT_GREGS((ctx))) [5]); \
208 ((a)[6] = (gpointer) (UCONTEXT_GREGS((ctx))) [6]); \
209 ((a)[7] = (gpointer) (UCONTEXT_GREGS((ctx))) [7]); \
210 ((a)[8] = (gpointer) (UCONTEXT_GREGS((ctx))) [8]); \
211 ((a)[9] = (gpointer) (UCONTEXT_GREGS((ctx))) [9]); \
212 ((a)[10] = (gpointer) (UCONTEXT_GREGS((ctx))) [10]); \
213 ((a)[11] = (gpointer) (UCONTEXT_GREGS((ctx))) [11]); \
214 ((a)[12] = (gpointer) (UCONTEXT_GREGS((ctx))) [12]); \
215 ((a)[13] = (gpointer) (UCONTEXT_GREGS((ctx))) [13]); \
216 ((a)[14] = (gpointer) (UCONTEXT_GREGS((ctx))) [14]); \
217 ((a)[15] = (gpointer) (UCONTEXT_GREGS((ctx))) [15]); \
222 #endif /* __MONO_SGENARCHDEP_H__ */