merge -r 53370:58178
[mono.git] / mono / mini / mini-ppc.h
1 #ifndef __MONO_MINI_PPC_H__
2 #define __MONO_MINI_PPC_H__
3
4 #include <mono/arch/ppc/ppc-codegen.h>
5 #include <glib.h>
6
7 #define MONO_MAX_IREGS 32
8 #define MONO_MAX_FREGS 32
9
10 #define MONO_SAVED_GREGS 19
11 #define MONO_SAVED_FREGS 18
12
13 #define MONO_ARCH_FRAME_ALIGNMENT 4
14
15 /* fixme: align to 16byte instead of 32byte (we align to 32byte to get 
16  * reproduceable results for benchmarks */
17 #define MONO_ARCH_CODE_ALIGNMENT 32
18
19 void ppc_patch (guchar *code, guchar *target);
20
21 struct MonoLMF {
22         gpointer    previous_lmf;
23         gpointer    lmf_addr;
24         MonoMethod *method;
25         gulong     ebp;
26         gulong     eip;
27         gulong     iregs [MONO_SAVED_GREGS]; /* 13..31 */
28         gdouble    fregs [MONO_SAVED_FREGS]; /* 14..31 */
29 };
30
31 /* we define our own structure and we'll copy the data
32  * from sigcontext/ucontext/mach when we need it.
33  * This also makes us save stack space and time when copying
34  * We might also want to add an additional field to propagate
35  * the original context from the signal handler.
36  */
37 typedef struct {
38         gulong sc_ir;          // pc 
39         gulong sc_sp;          // r1
40         gulong regs [MONO_SAVED_GREGS];
41         double fregs [MONO_SAVED_FREGS];
42 } MonoContext;
43
44 typedef struct MonoCompileArch {
45 } MonoCompileArch;
46
47 #define MONO_ARCH_EMULATE_FCONV_TO_I8 1
48 #define MONO_ARCH_EMULATE_LCONV_TO_R8 1
49 #define MONO_ARCH_EMULATE_LCONV_TO_R4 1
50 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN 1
51 #define MONO_ARCH_EMULATE_FREM 1
52 #define MONO_ARCH_BIGMUL_INTRINS 1
53
54 /* deal with some of the ABI differences here */
55 #ifdef __APPLE__
56 #define PPC_RET_ADDR_OFFSET 8
57 #define PPC_STACK_ALIGNMENT 16
58 #define PPC_STACK_PARAM_OFFSET 24
59 #define PPC_MINIMAL_STACK_SIZE 24
60 #define PPC_FIRST_ARG_REG ppc_r3
61 #define PPC_LAST_ARG_REG ppc_r10
62 #define PPC_FIRST_FPARG_REG ppc_f1
63 #define PPC_LAST_FPARG_REG ppc_f13
64 #define PPC_PASS_STRUCTS_BY_VALUE 1
65 #else
66 /* Linux */
67 #define PPC_RET_ADDR_OFFSET 4
68 #define PPC_STACK_ALIGNMENT 16
69 #define PPC_STACK_PARAM_OFFSET 8
70 #define PPC_MINIMAL_STACK_SIZE 8
71 #define PPC_FIRST_ARG_REG ppc_r3
72 #define PPC_LAST_ARG_REG ppc_r10
73 #define PPC_FIRST_FPARG_REG ppc_f1
74 #define PPC_LAST_FPARG_REG ppc_f8
75 /* set the next to 0 once inssel-ppc.brg is updated */
76 #define PPC_PASS_STRUCTS_BY_VALUE 1
77 #define PPC_SMALL_RET_STRUCT_IN_REG 1
78
79 #endif
80
81 #define MONO_ARCH_USE_SIGACTION 1
82 #define MONO_ARCH_NEED_DIV_CHECK 1
83
84 #define PPC_NUM_REG_ARGS (PPC_LAST_ARG_REG-PPC_FIRST_ARG_REG+1)
85 #define PPC_NUM_REG_FPARGS (PPC_LAST_FPARG_REG-PPC_FIRST_FPARG_REG+1)
86
87 /* we have the stack pointer, not the base pointer in sigcontext */
88 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->sc_ir = (int)ip; } while (0); 
89 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->sc_sp = (int)bp; } while (0); 
90
91 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->sc_ir))
92 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->sc_sp))
93 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->sc_sp))
94
95 #ifdef __APPLE__
96
97 typedef struct {
98         unsigned long sp;
99         unsigned long unused1;
100         unsigned long lr;
101 } MonoPPCStackFrame;
102
103 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do {        \
104                 MonoPPCStackFrame *sframe;      \
105                 __asm__ volatile("lwz   %0,0(r1)" : "=r" (sframe));     \
106                 MONO_CONTEXT_SET_BP ((ctx), sframe->sp);        \
107                 sframe = (MonoPPCStackFrame*)sframe->sp;        \
108                 MONO_CONTEXT_SET_IP ((ctx), sframe->lr);        \
109         } while (0)
110
111 #else
112
113 typedef struct {
114         unsigned long sp;
115         unsigned long lr;
116 } MonoPPCStackFrame;
117
118 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,func) do {      \
119                 MonoPPCStackFrame *sframe;      \
120                 __asm__ volatile("lwz   %0,0(1)" : "=r" (sframe));      \
121                 MONO_CONTEXT_SET_BP ((ctx), sframe->sp);        \
122                 sframe = (MonoPPCStackFrame*)sframe->sp;        \
123                 MONO_CONTEXT_SET_IP ((ctx), sframe->lr);        \
124         } while (0)
125
126 #endif
127
128 #define mono_find_jit_info mono_arch_find_jit_info
129 #define CUSTOM_STACK_WALK 1
130 #define CUSTOM_EXCEPTION_HANDLING 1
131
132 #endif /* __MONO_MINI_PPC_H__ */