Implement wine_call_on_stack for ppc

Simon Richter Simon.Richter at hogyros.de
Sat May 31 03:50:36 CDT 2008


This function was missing for PowerPC, so winelib failed to compile.

The implementation stores the LR into the callee's stack frame, as per
the ABI and saves the pointer to the "old" stack at SP - 4 (which should
be accessible), then switches to the new stack, creates a "bottom" frame
and a frame for wine_call_on_stack (so wine_call_on_stack shows up in
the backtrace, allowing the "run until return" debugger command to work
in the callee). The return value in r3 does not need to be touched.
---
 libs/wine/port.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/libs/wine/port.c b/libs/wine/port.c
index 81e7166..859818f 100644
--- a/libs/wine/port.c
+++ b/libs/wine/port.c
@@ -182,6 +182,23 @@ __ASM_GLOBAL_FUNC( wine_call_on_stack,
                    "popq %rbx\n\t"
                    "popq %rbp\n\t"
                    "ret")
+#elif defined(__powerpc__) && defined(__GNUC__)
+__ASM_GLOBAL_FUNC( wine_call_on_stack,
+                   "mflr 0\n\t"         /* get return address */
+                   "stw 0, 4(1)\n\t"    /* save return address */
+                   "subi 5, 5, 16\n\t" /* reserve space on new stack */
+                   "stw 1, 12(5)\n\t"   /* store old sp */
+                   "mtctr 3\n\t"        /* func -> ctr */
+                   "mr 3,4\n\t"         /* args -> function param 1 (r3) */
+                   "mr 1,5\n\t"         /* stack */
+                   "li 0, 0\n\t"        /* zero */
+                   "stw 0, 0(1)\n\t"    /* bottom of stack */
+                   "stwu 1, -16(1)\n\t" /* create a frame for this function */
+                   "bctrl\n\t"          /* call ctr */
+                   "lwz 1, 28(1)\n\t"   /* fetch old sp */
+                   "lwz 0, 4(1)\n\t"    /* fetch return address */
+                   "mtlr 0\n\t"         /* return address -> lr */
+                   "blr")               /* return */
 #else
 #error You must implement wine_switch_to_stack for your platform
 #endif
-- 
1.5.5.2




More information about the wine-patches mailing list