Update mcs/class/Commons.Xml.Relaxng/Commons.Xml.Relaxng/RelaxngPattern.cs
[mono.git] / mono / metadata / sgen-archdep.h
1 /*
2  * SGen is licensed under the terms of the MIT X11 license
3  *
4  * Copyright 2001-2003 Ximian, Inc
5  * Copyright 2003-2010 Novell, Inc.
6  * 
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:
14  * 
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  * 
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.
25  */
26 #ifndef __MONO_SGENARCHDEP_H__
27 #define __MONO_SGENARCHDEP_H__
28
29 #include <mono/utils/mono-sigcontext.h>
30
31 #ifdef __i386__
32
33 #include <mono/utils/mono-context.h>
34
35 #define REDZONE_SIZE    0
36
37 #define ARCH_NUM_REGS 8
38
39 #ifdef MONO_ARCH_HAS_MONO_CONTEXT
40 #define USE_MONO_CTX
41 #else
42 #define ARCH_STORE_REGS(ptr)    \
43         __asm__ __volatile__(   \
44                 "mov %%edi,0(%0)\n"     \
45                 "mov %%esi,4(%0)\n"     \
46                 "mov %%ebx,8(%0)\n"     \
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"    \
52                 :                       \
53                 : "r" (ptr)     \
54         )
55 #endif
56
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)))
60
61 #elif defined(__x86_64__)
62
63 #include <mono/utils/mono-context.h>
64
65 #define REDZONE_SIZE    128
66
67 #define ARCH_NUM_REGS 16
68 #define USE_MONO_CTX
69
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))
73
74 #elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc64__)
75
76 #define REDZONE_SIZE    224
77
78 #define ARCH_NUM_REGS 32
79 #ifdef __APPLE__
80 #define ARCH_STORE_REGS(ptr)    \
81         __asm__ __volatile__(   \
82                 "stmw r0, 0(%0)\n"      \
83                 :                       \
84                 : "b" (ptr)             \
85         )
86 #else
87 #define ARCH_STORE_REGS(ptr)    \
88         __asm__ __volatile__(   \
89                 "stmw 0, 0(%0)\n"       \
90                 :                       \
91                 : "b" (ptr)             \
92         )
93 #endif
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 {       \
97         int __i;        \
98         for (__i = 0; __i < 32; ++__i)  \
99                 ((a)[__i]) = UCONTEXT_REG_Rn((ctx), __i);       \
100         } while (0)
101
102 #elif defined(__arm__)
103
104 #define REDZONE_SIZE    0
105
106 /* We dont store ip, sp */
107 #define ARCH_NUM_REGS 14
108 #define ARCH_STORE_REGS(ptr)            \
109         __asm__ __volatile__(                   \
110                 "push {lr}\n"                           \
111                 "mov lr, %0\n"                          \
112                 "stmia lr!, {r0-r12}\n"         \
113                 "pop {lr}\n"                            \
114                 :                                                       \
115                 : "r" (ptr)                                     \
116         )
117
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)));        \
135         } while (0)
136
137 #elif defined(__mips__)
138
139 #define REDZONE_SIZE    0
140
141 #define USE_MONO_CTX
142 #define ARCH_NUM_REGS 32
143
144 #define ARCH_SIGCTX_SP(ctx)     (UCONTEXT_GREGS((ctx))[29])
145 #define ARCH_SIGCTX_IP(ctx)     (UCONTEXT_REG_PC((ctx)))
146
147 #elif defined(__s390x__)
148
149 #define REDZONE_SIZE    0
150
151 #include <mono/utils/mono-context.h>
152
153 #define USE_MONO_CTX
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
157
158 #elif defined(__sparc__)
159
160 #define REDZONE_SIZE    0
161
162 /* Don't bother with %g0 (%r0), it's always hard-coded to zero */
163 #define ARCH_NUM_REGS 15        
164 #ifdef __sparcv9
165 #define ARCH_STORE_REGS(ptr)    \
166         __asm__ __volatile__(   \
167                 "st %%g1,[%0]\n\t"      \
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" \
182                 :                       \
183                 : "r" (ptr)             \
184                 : "memory"                      \
185         )
186 #else
187 #define ARCH_STORE_REGS(ptr)    \
188         __asm__ __volatile__(   \
189                 "st %%g1,[%0]\n\t"      \
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" \
204                 :                       \
205                 : "r" (ptr)             \
206                 : "memory"                      \
207         )
208 #endif
209
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]);       \
228         } while (0)
229
230 #endif
231
232 #endif /* __MONO_SGENARCHDEP_H__ */