Fix ARCH_STORE_REGS on arm
[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 #define USE_MONO_CTX
39
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)))
43
44 #elif defined(__x86_64__)
45
46 #include <mono/utils/mono-context.h>
47
48 #define REDZONE_SIZE    128
49
50 #define ARCH_NUM_REGS 16
51 #define USE_MONO_CTX
52
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))
56
57 #elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc64__)
58
59 #define REDZONE_SIZE    224
60
61 #define ARCH_NUM_REGS 32
62 #ifdef __APPLE__
63 #define ARCH_STORE_REGS(ptr)    \
64         __asm__ __volatile__(   \
65                 "stmw r0, 0(%0)\n"      \
66                 :                       \
67                 : "b" (ptr)             \
68         )
69 #else
70 #define ARCH_STORE_REGS(ptr)    \
71         __asm__ __volatile__(   \
72                 "stmw 0, 0(%0)\n"       \
73                 :                       \
74                 : "b" (ptr)             \
75         )
76 #endif
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 {       \
80         int __i;        \
81         for (__i = 0; __i < 32; ++__i)  \
82                 ((a)[__i]) = UCONTEXT_REG_Rn((ctx), __i);       \
83         } while (0)
84
85 #elif defined(__arm__)
86
87 #define REDZONE_SIZE    0
88
89 /* We dont store ip, sp */
90 #define ARCH_NUM_REGS 14
91 #define ARCH_STORE_REGS(ptr)            \
92         __asm__ __volatile__(                   \
93                 "push {lr}\n"                           \
94                 "mov lr, %0\n"                          \
95                 "stmia lr!, {r0-r12}\n"         \
96                 "pop {lr}\n"                            \
97                 :                                                       \
98                 : "r" (ptr)                                     \
99         )
100
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)));        \
118         } while (0)
119
120 #elif defined(__s390x__)
121
122 #define REDZONE_SIZE    0
123
124 #define ARCH_NUM_REGS 16        
125 #define ARCH_STORE_REGS(ptr)    \
126         __asm__ __volatile__(   \
127                 "stg    %%r0,0x00(%0)\n\t"      \
128                 "stg    %%r1,0x08(%0)\n\t"      \
129                 "stg    %%r2,0x10(%0)\n\t"      \
130                 "stg    %%r3,0x18(%0)\n\t"      \
131                 "stg    %%r4,0x20(%0)\n\t"      \
132                 "stg    %%r5,0x28(%0)\n\t"      \
133                 "stg    %%r6,0x30(%0)\n\t"      \
134                 "stg    %%r7,0x38(%0)\n\t"      \
135                 "stg    %%r8,0x40(%0)\n\t"      \
136                 "stg    %%r9,0x48(%0)\n\t"      \
137                 "stg    %%r10,0x50(%0)\n\t"     \
138                 "stg    %%r11,0x58(%0)\n\t"     \
139                 "stg    %%r12,0x60(%0)\n\t"     \
140                 "stg    %%r13,0x68(%0)\n\t"     \
141                 "stg    %%r14,0x70(%0)\n\t"     \
142                 "stg    %%r15,0x78(%0)\n"       \
143                 : "=&a" (ptr)                   \
144                 : "0" (cur_thread_regs)         \
145                 : "memory"                      \
146         )
147 #define ARCH_SIGCTX_SP(ctx)     ((UCONTEXT_GREGS((ctx))) [15])
148 #define ARCH_SIGCTX_IP(ctx)     ((ucontext_t *) (ctx))->uc_mcontext.psw.addr
149 #define ARCH_COPY_SIGCTX_REGS(a,ctx) do {               \
150         ((a)[0] = (gpointer) (UCONTEXT_GREGS((ctx))) [0]);              \
151         ((a)[1] = (gpointer) (UCONTEXT_GREGS((ctx))) [1]);              \
152         ((a)[2] = (gpointer) (UCONTEXT_GREGS((ctx))) [2]);              \
153         ((a)[3] = (gpointer) (UCONTEXT_GREGS((ctx))) [3]);              \
154         ((a)[4] = (gpointer) (UCONTEXT_GREGS((ctx))) [4]);              \
155         ((a)[5] = (gpointer) (UCONTEXT_GREGS((ctx))) [5]);              \
156         ((a)[6] = (gpointer) (UCONTEXT_GREGS((ctx))) [6]);              \
157         ((a)[7] = (gpointer) (UCONTEXT_GREGS((ctx))) [7]);              \
158         ((a)[8] = (gpointer) (UCONTEXT_GREGS((ctx))) [8]);              \
159         ((a)[9] = (gpointer) (UCONTEXT_GREGS((ctx))) [9]);              \
160         ((a)[10] = (gpointer) (UCONTEXT_GREGS((ctx))) [10]);            \
161         ((a)[11] = (gpointer) (UCONTEXT_GREGS((ctx))) [11]);            \
162         ((a)[12] = (gpointer) (UCONTEXT_GREGS((ctx))) [12]);            \
163         ((a)[13] = (gpointer) (UCONTEXT_GREGS((ctx))) [13]);            \
164         ((a)[14] = (gpointer) (UCONTEXT_GREGS((ctx))) [14]);            \
165         ((a)[15] = (gpointer) (UCONTEXT_GREGS((ctx))) [15]);            \
166         } while (0)
167
168 #endif
169
170 #endif /* __MONO_SGENARCHDEP_H__ */