Skip to contentSkip to conversation

TCG support for OSX/ppc

RFC Andreas Färber 2 participants 4 messages Jul 26, 2008

lore
Share & tools
lore
#0 lore raw

Hello,

Attached is a work-in-progress patch to restore support for running QEMU on Mac OS X PowerPC (32-bit). It adjusts the stack offsets according to the following ABI document:

http://developer.apple.com/documentation/DeveloperTools/Conceptual/LowLevelABI/Articles/32bitPowerPC.html

If these numbers were confirmed to be correct, we should introduce suitable #defines to avoid some of the #ifdefs currently in the patch.

With this patch applied, I get the following immediate error when running qemu-system-sparc:

qemu: fatal: Trap 0x07 while interrupts disabled, Error state
pc: 00004120 npc: 00004124
General Registers:
%g0: 00000000 %g1: 7120010c %g2: 00000000 %g3: 71200100
%g4: 00000000 %g5: 00000000 %g6: 00000000 %g7: 00000000
Current Register Window:
%o0: 00000000 %o1: 00000000 %o2: 00000000 %o3: 00000000
%o4: 00000000 %o5: 00000000 %o6: 00000000 %o7: 00000000
%l0: 00000000 %l1: 00000000 %l2: 00000000 %l3: 00000000
%l4: 00000000 %l5: 00000000 %l6: 00000000 %l7: 00000000
%i0: 00000000 %i1: 00000000 %i2: 00000000 %i3: 00000000
%i4: 00000000 %i5: 00000000 %i6: 00000000 %i7: 00000000

Floating Point Registers:
%f00: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f04: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f08: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f12: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f16: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f20: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f24: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f28: 000000000.000000 000000000.000000 000000000.000000 000000000.000000
psr: 0x044000c0 -> Z--- SP- wim: 0x00000001
fsr: 0x00080000
../qemu-debian-sparc.command: line 3: 1259 Abort trap /Users/andreas/Q/latest/bin/qemu-system-sparc -hda /Users/andreas/Documents/QEMU/DebianSparc.qvm/Harddisk_1.qcow2 -m 256

Probably I'm missing something obvious... Any hints or requests how to improve the patch appreciated.

Andreas

#1 lore raw

Sorry, patch was missing.

tcg/ppc/tcg-target.c +20 -0
index 7dfb17f..ea420d9 100644
@@ -806,8 +806,12 @@ void tcg_target_qemu_prologue (TCGContext *s)
     int i, frame_size;
 
     frame_size = 0
+#ifdef __APPLE__
+        + 24                    /* linkage area */
+#else
         + 4                     /* back chain */
         + 4                     /* LR */
+#endif
         + TCG_STATIC_CALL_ARGS_SIZE
         + ARRAY_SIZE (tcg_target_callee_save_regs) * 4
         ;
@@ -819,10 +823,18 @@ void tcg_target_qemu_prologue (TCGContext *s)
         tcg_out32 (s, (STW
                        | RS (tcg_target_callee_save_regs[i])
                        | RA (1)
+#ifdef __APPLE__
+                       | (i * 4 + 24 + TCG_STATIC_CALL_ARGS_SIZE)
+#else
                        | (i * 4 + 8 + TCG_STATIC_CALL_ARGS_SIZE)
+#endif
                        )
             );
+#ifdef __APPLE__
+    tcg_out32 (s, STW | RS (0) | RA (1) | (frame_size + 8));
+#else
     tcg_out32 (s, STW | RS (0) | RA (1) | (frame_size + 4));
+#endif
 
     tcg_out32 (s, MTSPR | RS (3) | CTR);
     tcg_out32 (s, BCCTR | BO_ALWAYS);
@@ -832,10 +844,18 @@ void tcg_target_qemu_prologue (TCGContext *s)
         tcg_out32 (s, (LWZ
                        | RT (tcg_target_callee_save_regs[i])
                        | RA (1)
+#ifdef __APPLE__
+                       | (i * 4 + 24 + TCG_STATIC_CALL_ARGS_SIZE)
+#else
                        | (i * 4 + 8 + TCG_STATIC_CALL_ARGS_SIZE)
+#endif
                        )
             );
+#ifdef __APPLE__
+    tcg_out32 (s, LWZ | RT (0) | RA (1) | (frame_size + 8));
+#else
     tcg_out32 (s, LWZ | RT (0) | RA (1) | (frame_size + 4));
+#endif
     tcg_out32 (s, MTSPR | RS (0) | LR);
     tcg_out32 (s, ADDI | RT (1) | RA (1) | frame_size);
     tcg_out32 (s, BCLR | BO_ALWAYS);
tcg/ppc/tcg-target.h +4 -0
index e21b992..0a9dfd8 100644
@@ -65,7 +65,11 @@ enum {
 /* used for function call generation */
 #define TCG_REG_CALL_STACK TCG_REG_R1
 #define TCG_TARGET_STACK_ALIGN 16
+#ifdef __APPLE__
+#define TCG_TARGET_CALL_STACK_OFFSET 24
+#else
 #define TCG_TARGET_CALL_STACK_OFFSET 8
+#endif
 #define TCG_TARGET_CALL_ALIGN_ARGS 1
 
 /* optional instructions */

Am 26.07.2008 um 12:23 schrieb Andreas Färber:

Quoted 43 lines

Hello,

Attached is a work-in-progress patch to restore support for running QEMU on Mac OS X PowerPC (32-bit). It adjusts the stack offsets according to the following ABI document:

http://developer.apple.com/documentation/DeveloperTools/Conceptual/LowLevelABI/Articles/32bitPowerPC.html

If these numbers were confirmed to be correct, we should introduce suitable #defines to avoid some of the #ifdefs currently in the patch.

With this patch applied, I get the following immediate error when running qemu-system-sparc:

qemu: fatal: Trap 0x07 while interrupts disabled, Error state
pc: 00004120 npc: 00004124
General Registers:
%g0: 00000000 %g1: 7120010c %g2: 00000000 %g3: 71200100
%g4: 00000000 %g5: 00000000 %g6: 00000000 %g7: 00000000
Current Register Window:
%o0: 00000000 %o1: 00000000 %o2: 00000000 %o3: 00000000
%o4: 00000000 %o5: 00000000 %o6: 00000000 %o7: 00000000
%l0: 00000000 %l1: 00000000 %l2: 00000000 %l3: 00000000
%l4: 00000000 %l5: 00000000 %l6: 00000000 %l7: 00000000
%i0: 00000000 %i1: 00000000 %i2: 00000000 %i3: 00000000
%i4: 00000000 %i5: 00000000 %i6: 00000000 %i7: 00000000

Floating Point Registers:
%f00: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f04: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f08: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f12: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f16: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f20: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f24: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f28: 000000000.000000 000000000.000000 000000000.000000 000000000.000000
psr: 0x044000c0 -> Z--- SP- wim: 0x00000001
fsr: 0x00080000
../qemu-debian-sparc.command: line 3: 1259 Abort trap /Users/andreas/Q/latest/bin/qemu-system-sparc -hda /Users/andreas/Documents/QEMU/DebianSparc.qvm/Harddisk_1.qcow2 -m 256

Probably I'm missing something obvious... Any hints or requests how to improve the patch appreciated.

Andreas

#2 lore raw
In reply to Andreas Färber
Quoted 16 lines · Andreas Färber

With this patch applied, I get the following immediate error when running
qemu-system-sparc:

qemu: fatal: Trap 0x07 while interrupts disabled, Error state
pc: 00004120 npc: 00004124
General Registers:

 %g0: 00000000   %g1: 7120010c   %g2: 00000000   %g3: 71200100
 %g4: 00000000   %g5: 00000000   %g6: 00000000   %g7: 00000000
 Current Register Window:
 %o0: 00000000   %o1: 00000000   %o2: 00000000   %o3: 00000000
 %o4: 00000000   %o5: 00000000   %o6: 00000000   %o7: 00000000
 %l0: 00000000   %l1: 00000000   %l2: 00000000   %l3: 00000000
 %l4: 00000000   %l5: 00000000   %l6: 00000000   %l7: 00000000
 %i0: 00000000   %i1: 00000000   %i2: 00000000   %i3: 00000000
 %i4: 00000000   %i5: 00000000   %i6: 00000000   %i7: 00000000
Quoted 15 lines

Floating Point Registers:
%f00: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f04: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f08: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f12: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f16: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f20: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f24: 000000000.000000 000000000.000000 000000000.000000 000000000.000000 %f28: 000000000.000000 000000000.000000 000000000.000000 000000000.000000
psr: 0x044000c0 -> Z--- SP- wim: 0x00000001
fsr: 0x00080000
../qemu-debian-sparc.command: line 3: 1259 Abort trap
/Users/andreas/Q/latest/bin/qemu-system-sparc -hda /Users/andreas/Documents/QEMU/DebianSparc.qvm/Harddisk_1.qcow2 -m 256

The trap is for unaligned access in 0x4120:
0x0000411c: lduba [ %g1 ] #ASI_M_BYPASS, %g2
0x00004120: stba %g0, [ %g1 ] #ASI_M_BYPASS

%g1 is used for unsigned byte load in 0x411c and the address is correct (NVRAM Sparc structure). I would start debugging by looking at how the store is implemented (out_asm).

Quoted 2 lines

Probably I'm missing something obvious... Any hints or requests how to
improve the patch appreciated.

Instead of using 24 or 8 in tcg-target.c, you could use TCG_TARGET_CALL_STACK_OFFSET. I don't know where 8 vs 4 in LWZ/STW comes from, but you could introduce a define there as well.

#3 lore raw

Thanks for your comments,

Am 26.07.2008 um 13:18 schrieb Blue Swirl:

Quoted 5 lines
Quoted 2 lines

Probably I'm missing something obvious... Any hints or requests how to improve the patch appreciated.

Instead of using 24 or 8 in tcg-target.c, you could use TCG_TARGET_CALL_STACK_OFFSET.

To my confusion tcg-target.h is not included from tcg-target.c, but your suggestion seems to work nontheless.

Quoted 2 lines

I don't know where 8 vs 4 in LWZ/STW
comes from, but you could introduce a define there as well.

I interpreted the +4 as the Link Register offset, is that wrong? Patch updated with defines.

Andreas

tcg/ppc/tcg-target.c +5 -6
index 7dfb17f..66eb7dd 100644
@@ -806,8 +806,7 @@ void tcg_target_qemu_prologue (TCGContext *s)
     int i, frame_size;
 
     frame_size = 0
-        + 4                     /* back chain */
-        + 4                     /* LR */
+        + TCG_TARGET_CALL_STACK_OFFSET
         + TCG_STATIC_CALL_ARGS_SIZE
         + ARRAY_SIZE (tcg_target_callee_save_regs) * 4
         ;
@@ -819,10 +818,10 @@ void tcg_target_qemu_prologue (TCGContext *s)
         tcg_out32 (s, (STW
                        | RS (tcg_target_callee_save_regs[i])
                        | RA (1)
-                       | (i * 4 + 8 + TCG_STATIC_CALL_ARGS_SIZE)
+                       | (i * 4 + TCG_TARGET_CALL_STACK_OFFSET + TCG_STATIC_CALL_ARGS_SIZE)
                        )
             );
-    tcg_out32 (s, STW | RS (0) | RA (1) | (frame_size + 4));
+    tcg_out32 (s, STW | RS (0) | RA (1) | (frame_size + TCG_TARGET_CALL_LR_OFFSET));
 
     tcg_out32 (s, MTSPR | RS (3) | CTR);
     tcg_out32 (s, BCCTR | BO_ALWAYS);
@@ -832,10 +831,10 @@ void tcg_target_qemu_prologue (TCGContext *s)
         tcg_out32 (s, (LWZ
                        | RT (tcg_target_callee_save_regs[i])
                        | RA (1)
-                       | (i * 4 + 8 + TCG_STATIC_CALL_ARGS_SIZE)
+                       | (i * 4 + TCG_TARGET_CALL_STACK_OFFSET + TCG_STATIC_CALL_ARGS_SIZE)
                        )
             );
-    tcg_out32 (s, LWZ | RT (0) | RA (1) | (frame_size + 4));
+    tcg_out32 (s, LWZ | RT (0) | RA (1) | (frame_size + TCG_TARGET_CALL_LR_OFFSET));
     tcg_out32 (s, MTSPR | RS (0) | LR);
     tcg_out32 (s, ADDI | RT (1) | RA (1) | frame_size);
     tcg_out32 (s, BCLR | BO_ALWAYS);
tcg/ppc/tcg-target.h +6 -0
index e21b992..7e2c8bd 100644
@@ -65,7 +65,13 @@ enum {
 /* used for function call generation */
 #define TCG_REG_CALL_STACK TCG_REG_R1
 #define TCG_TARGET_STACK_ALIGN 16
+#ifdef __APPLE__
+#define TCG_TARGET_CALL_STACK_OFFSET 24
+#define TCG_TARGET_CALL_LR_OFFSET 8
+#else
 #define TCG_TARGET_CALL_STACK_OFFSET 8
+#define TCG_TARGET_CALL_LR_OFFSET 4
+#endif
 #define TCG_TARGET_CALL_ALIGN_ARGS 1
 
 /* optional instructions */