2005-07-20 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / mini / mini-ppc.h
index 1d16c30ecceacafa5a586b749ad45878a15f3fc4..8487d4c1fb0834f8556dd64d0d7b1ec40b5aaf6f 100644 (file)
@@ -7,6 +7,9 @@
 #define MONO_MAX_IREGS 32
 #define MONO_MAX_FREGS 32
 
+#define MONO_SAVED_GREGS 19
+#define MONO_SAVED_FREGS 18
+
 #define MONO_ARCH_FRAME_ALIGNMENT 4
 
 /* fixme: align to 16byte instead of 32byte (we align to 32byte to get 
@@ -21,8 +24,8 @@ struct MonoLMF {
        MonoMethod *method;
        gulong     ebp;
        gulong     eip;
-       gulong     iregs [19]; /* 13..31 */
-       gdouble    fregs [20]; /* 14..31 */
+       gulong     iregs [MONO_SAVED_GREGS]; /* 13..31 */
+       gdouble    fregs [MONO_SAVED_FREGS]; /* 14..31 */
 };
 
 /* we define our own structure and we'll copy the data
@@ -34,8 +37,8 @@ struct MonoLMF {
 typedef struct {
        gulong sc_ir;          // pc 
        gulong sc_sp;          // r1
-       gulong regs [19];
-       double fregs [20];
+       gulong regs [MONO_SAVED_GREGS];
+       double fregs [MONO_SAVED_FREGS];
 } MonoContext;
 
 typedef struct MonoCompileArch {
@@ -76,8 +79,54 @@ typedef struct MonoCompileArch {
 #endif
 
 #define MONO_ARCH_USE_SIGACTION 1
+#define MONO_ARCH_NEED_DIV_CHECK 1
 
 #define PPC_NUM_REG_ARGS (PPC_LAST_ARG_REG-PPC_FIRST_ARG_REG+1)
 #define PPC_NUM_REG_FPARGS (PPC_LAST_FPARG_REG-PPC_FIRST_FPARG_REG+1)
 
+/* we have the stack pointer, not the base pointer in sigcontext */
+#define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->sc_ir = (int)ip; } while (0); 
+#define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->sc_sp = (int)bp; } while (0); 
+
+#define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->sc_ir))
+#define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->sc_sp))
+#define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->sc_sp))
+
+#ifdef __APPLE__
+
+typedef struct {
+       unsigned long sp;
+       unsigned long unused1;
+       unsigned long lr;
+} MonoPPCStackFrame;
+
+#define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do {       \
+               MonoPPCStackFrame *sframe;      \
+               __asm__ volatile("lwz   %0,0(r1)" : "=r" (sframe));     \
+               MONO_CONTEXT_SET_BP ((ctx), sframe->sp);        \
+               sframe = (MonoPPCStackFrame*)sframe->sp;        \
+               MONO_CONTEXT_SET_IP ((ctx), sframe->lr);        \
+       } while (0)
+
+#else
+
+typedef struct {
+       unsigned long sp;
+       unsigned long lr;
+} MonoPPCStackFrame;
+
+#define MONO_INIT_CONTEXT_FROM_FUNC(ctx,func) do {     \
+               MonoPPCStackFrame *sframe;      \
+               __asm__ volatile("lwz   %0,0(1)" : "=r" (sframe));      \
+               MONO_CONTEXT_SET_BP ((ctx), sframe->sp);        \
+               sframe = (MonoPPCStackFrame*)sframe->sp;        \
+               MONO_CONTEXT_SET_IP ((ctx), sframe->lr);        \
+       } while (0)
+
+#endif
+
+#define mono_find_jit_info mono_arch_find_jit_info
+#define CUSTOM_STACK_WALK 1
+#define CUSTOM_EXCEPTION_HANDLING 1
+
 #endif /* __MONO_MINI_PPC_H__ */