Skip to contentSkip to conversation

qemu crashes after the "OpenBIOS for Sparc64" banner is printed

Qemu-devel Jakub Jermar 3 participants 10 messages Aug 28, 2008 – Aug 29, 2008

lore
Share & tools
lore
#0 lore raw

Hi,

when I build qemu-system-sparc64 from trunk and attempt to boot the HelenOS iso image, I immediately get segmentation fault. Below is the output from a gdb session, show the place of crash:

OpenBIOS for Sparc64

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7b616b0 (LWP 16553)]
change_pstate (new_pstate=21) at /home/jermar/install/qemu/target-sparc/op_helper.c:2676
2676 pstate_regs = env->pstate & 0xc01;
(gdb) bt

#0  change_pstate (new_pstate=21) at /home/jermar/install/qemu/target-sparc/op_helper.c:2676
#1  0x0814d3b4 in do_interrupt (env=0x83d9bc8) at /home/jermar/install/qemu/target-sparc/helper.c:758
#2  0x080d6510 in cpu_sparc_exec (env1=0x0) at /home/jermar/install/qemu/cpu-exec.c:320
#3  0x08055cca in main_loop () at /home/jermar/install/qemu/vl.c:7545

Backtrace stopped: previous frame inner to this frame (corrupt stack?)
2676 pstate_regs = env->pstate & 0xc01;
(gdb) print env
$1 = (struct CPUSPARCState *) 0xbfdb97c8
(gdb) print env->pstate
Cannot access memory at address 0xbfdc717c

Since I get this error so early, I think this is a generic issue. Anyone else has seen something similar?

I built qemu using gcc-3.3. The arguments I used to run qemu:
-cdrom image.iso -m 512 -boot d -nographic

Please, respond to me directly as I am not subscribed to the list.

Cheers,
Jakub

#1 lore raw
Quoted 25 lines · Jakub Jermar

Hi,

when I build qemu-system-sparc64 from trunk and attempt to boot the HelenOS iso image, I immediately get segmentation fault. Below is the output from a gdb session, show the place of crash:

OpenBIOS for Sparc64

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7b616b0 (LWP 16553)]
change_pstate (new_pstate=21) at /home/jermar/install/qemu/target-sparc/op_helper.c:2676
2676 pstate_regs = env->pstate & 0xc01;
(gdb) bt

 #0  change_pstate (new_pstate=21) at /home/jermar/install/qemu/target-sparc/op_helper.c:2676
 #1  0x0814d3b4 in do_interrupt (env=0x83d9bc8) at /home/jermar/install/qemu/target-sparc/helper.c:758
 #2  0x080d6510 in cpu_sparc_exec (env1=0x0) at /home/jermar/install/qemu/cpu-exec.c:320
 #3  0x08055cca in main_loop () at /home/jermar/install/qemu/vl.c:7545

Backtrace stopped: previous frame inner to this frame (corrupt stack?)
2676 pstate_regs = env->pstate & 0xc01;
(gdb) print env
$1 = (struct CPUSPARCState *) 0xbfdb97c8
(gdb) print env->pstate
Cannot access memory at address 0xbfdc717c

Quoted 7 lines

Since I get this error so early, I think this is a generic issue. Anyone else has seen something similar?

I built qemu using gcc-3.3. The arguments I used to run qemu:
-cdrom image.iso -m 512 -boot d -nographic

Please, respond to me directly as I am not subscribed to the list.

What host? On my amd64 and using the latest OpenBIOS I get this:

boot:
Allocated 8 Megs of memory at 0x40000000 for kernel Kernel doesn't support loading to high memory, relocating...done. Loaded kernel version 0.0.0
service close: argument count error (0 0)
HelenOS SPARC64 Bootloader
Release 0.2.0.5, revision exported
Built on 2007-06-18 23:55:43
Copyright (c) 2006 HelenOS project

System info
memory: 512M starting at 0x0000000000000000

Memory statistics
kernel entry point at 0x0000000000400000 0x0000000000008e78: boot info structure 0x00000000000092cc: kernel image (size 459416 bytes) 0x0000000000079564: ns image (size 221421 bytes) 0x00000000000af651: init image (size 221340 bytes) 0x00000000000e56ed: fb image (size 239587 bytes) 0x000000000011fed0: kbd image (size 254904 bytes) 0x000000000015e288: console image (size 404892 bytes) 0x00000000001c1024: tetris image (size 239492 bytes) 0x00000000001fb7a8: tester image (size 238840 bytes) 0x0000000000235ca0: klog image (size 204910 bytes)

Copying components
kernel...done.
ns...done.
init...done.
fb...done.
kbd...done.
console...done.
tetris...done.
tester...done.
klog...done.

Canonizing OpenFirmware device tree...done.

Checking for secondary processors...done.

Booting the kernel...

Using the version in pc-bios it does not get this far, but does not crash either:
boot:
Allocated 8 Megs of memory at 0x40000000 for kernel Kernel doesn't support loading to high memory, relocating...done. Loaded kernel version 0.0.0
service close: argument count error (0 0)
HelenOS SPARC64 Bootloader
Release 0.2.0.5, revision exported
Built on 2007-06-18 23:55:43
Copyright (c) 2006 HelenOS project
Error: no memory detected, halting.

#2 lore raw

Blue Swirl wrote:
<snip>

Quoted 1 line

What host? On my amd64 and using the latest OpenBIOS I get this:

Oops, the host is ia32 and the OpenBIOS is the one from qemu's current trunk. I will try it on amd64 shortly.

Btw, couldn't you update the openbios version in qemu? It will allow me to make sure that HelenOS on qemu/sparc64 makes it to the point where it probes the framebuffer and eventually write a small driver for it.

Thanks,
Jakub

#3 lore raw
Quoted 8 lines · Jakub Jermar

Blue Swirl wrote:
<snip>

Quoted 2 lines

What host? On my amd64 and using the latest OpenBIOS I get this:

Oops, the host is ia32 and the OpenBIOS is the one from qemu's current trunk. I will try it on amd64 shortly.

It should work on i386 too. It just seems that some bugs on i386 can't be reproduced on amd64 32-bit chroot.

Quoted 3 lines

Btw, couldn't you update the openbios version in qemu? It will allow me to make sure that HelenOS on qemu/sparc64 makes it to the point where it probes the framebuffer and eventually write a small driver for it.

Well, if the firmware configuration device is committed, I'll update OpenBIOS to the new system and then probably update the image.

I wouldn't trust the Qemu version of VGA on Sparc64 yet, there could be some wrong assumptions. Once a real kernel can boot, initialize the VGA and preferably start X, then we should know that it's realistic.

#4 lore raw
Quoted 1 line · Blue Swirl
Quoted 1 line
Quoted 1 line

What host? On my amd64 and using the latest OpenBIOS I get this:

It works on amd64 for me too, so it's an ia32 issue.
If I sent you an ia32 coredump, would that be of any help to you?

Quoted 3 lines

I wouldn't trust the Qemu version of VGA on Sparc64 yet, there could be some wrong assumptions. Once a real kernel can boot, initialize the VGA and preferably start X, then we should know that it's realistic.

That would imply that the HelenOS kernel is somewhat unreal, which is not easily possible since it can drive real UltraSPARC machines :-) (And yes, on a real machine, it doesn't end with the "Booting the kernel..." message).

A simple unaccelerated framebuffer support is not a big deal, all we need is an address, width, height and color depth and maybe a heads up if the device is weird (such as the Creator 3D).

Cheers,
Jakub

#5 lore raw
Quoted 11 lines · Jakub Jermar
Quoted 6 lines · Blue Swirl
Quoted 5 lines
Quoted 4 lines

What host? On my amd64 and using the latest OpenBIOS I get this:

It works on amd64 for me too, so it's an ia32 issue. If I sent you an ia32 coredump, would that be of any help to you?

No thanks, I can no reproduce it. Maybe the reason can be found with bisection.

Quoted 9 lines
Quoted 4 lines

I wouldn't trust the Qemu version of VGA on Sparc64 yet, there could be some wrong assumptions. Once a real kernel can boot, initialize the VGA and preferably start X, then we should know that it's realistic.

That would imply that the HelenOS kernel is somewhat unreal, which is not easily possible since it can drive real UltraSPARC machines :-) (And yes, on a real machine, it doesn't end with the "Booting the kernel..." message).

I just meant that you should not use Qemu as reference. If your VGA code runs unmodified in Qemu, it's a sign that we could trust Qemu/Sparc64 VGA coupling.

Quoted 3 lines

A simple unaccelerated framebuffer support is not a big deal, all we need is an address, width, height and color depth and maybe a heads up if the device is weird (such as the Creator 3D).

The current Sun4u machine uses only PC devices. It's of course possible to add other devices, but I'd rather do later, after for example working PCI or even interrupt controller.

#6 lore raw
Quoted 11 lines · Blue Swirl
Quoted 9 lines · Jakub Jermar
Quoted 6 lines · Blue Swirl
Quoted 5 lines
Quoted 4 lines

What host? On my amd64 and using the latest OpenBIOS I get this:

Quoted 5 lines
Quoted 2 lines

It works on amd64 for me too, so it's an ia32 issue. If I sent you an ia32 coredump, would that be of any help to you?

No thanks, I can no reproduce it. Maybe the reason can be found with bisection.

f2bc7e7fa175b61a20c6f10c324d7c4d68af676f is first bad commit commit f2bc7e7fa175b61a20c6f10c324d7c4d68af676f

Author: blueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>
Date:   Tue May 27 17:35:30 2008 +0000

Move non-op functions from op_helper.c to helper.c and vice versa. Rearrange interrupt handling to match other targets.

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4590
c046a42c-6fe2-441c-8c8c-71466251a162

:100644 100644 65af9a6d879e922ad0e90bd110f087ac81032bcf
5e64fa43cae3b7fc12507621351cd4d0b82cb4b0 M cpu-exec.c
:040000 040000 f519a87338e29fd5d3a642698fd4dd405bf19024
adfd50c255dccdee1098c3131cca5c20453d19f9 M target-sparc

#7 lore raw
Quoted 28 lines · Blue Swirl
Quoted 11 lines · Blue Swirl
Quoted 9 lines · Jakub Jermar
Quoted 6 lines · Blue Swirl
Quoted 5 lines
Quoted 4 lines

What host? On my amd64 and using the latest OpenBIOS I get this:

Quoted 5 lines
Quoted 2 lines

It works on amd64 for me too, so it's an ia32 issue. If I sent you an ia32 coredump, would that be of any help to you?

No thanks, I can no reproduce it. Maybe the reason can be found with bisection.

f2bc7e7fa175b61a20c6f10c324d7c4d68af676f is first bad commit
commit f2bc7e7fa175b61a20c6f10c324d7c4d68af676f
Author: blueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>
Date: Tue May 27 17:35:30 2008 +0000

Move non-op functions from op_helper.c to helper.c and vice versa. Rearrange interrupt handling to match other targets.

Quoted 7 lines

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4590
c046a42c-6fe2-441c-8c8c-71466251a162

:100644 100644 65af9a6d879e922ad0e90bd110f087ac81032bcf
5e64fa43cae3b7fc12507621351cd4d0b82cb4b0 M cpu-exec.c
:040000 040000 f519a87338e29fd5d3a642698fd4dd405bf19024
adfd50c255dccdee1098c3131cca5c20453d19f9 M target-sparc

Surprisingly it was moving of do_interrupt to helper.c that caused the bug. Moving it back to op_helper.c allows Sparc64 to boot. I'm still trying to understand the real cause of the bug and to find if there is some other way of fixing this. This kind of voodoo makes me nervous.

target-sparc/helper.c +0 -229
Index: qemu/target-sparc/helper.c
===================================================================
@@ -639,235 +639,6 @@
 }
 #endif
 
-#ifdef TARGET_SPARC64
-#ifdef DEBUG_PCALL
-static const char * const excp_names[0x80] = {
-    [TT_TFAULT] = "Instruction Access Fault",
-    [TT_TMISS] = "Instruction Access MMU Miss",
-    [TT_CODE_ACCESS] = "Instruction Access Error",
-    [TT_ILL_INSN] = "Illegal Instruction",
-    [TT_PRIV_INSN] = "Privileged Instruction",
-    [TT_NFPU_INSN] = "FPU Disabled",
-    [TT_FP_EXCP] = "FPU Exception",
-    [TT_TOVF] = "Tag Overflow",
-    [TT_CLRWIN] = "Clean Windows",
-    [TT_DIV_ZERO] = "Division By Zero",
-    [TT_DFAULT] = "Data Access Fault",
-    [TT_DMISS] = "Data Access MMU Miss",
-    [TT_DATA_ACCESS] = "Data Access Error",
-    [TT_DPROT] = "Data Protection Error",
-    [TT_UNALIGNED] = "Unaligned Memory Access",
-    [TT_PRIV_ACT] = "Privileged Action",
-    [TT_EXTINT | 0x1] = "External Interrupt 1",
-    [TT_EXTINT | 0x2] = "External Interrupt 2",
-    [TT_EXTINT | 0x3] = "External Interrupt 3",
-    [TT_EXTINT | 0x4] = "External Interrupt 4",
-    [TT_EXTINT | 0x5] = "External Interrupt 5",
-    [TT_EXTINT | 0x6] = "External Interrupt 6",
-    [TT_EXTINT | 0x7] = "External Interrupt 7",
-    [TT_EXTINT | 0x8] = "External Interrupt 8",
-    [TT_EXTINT | 0x9] = "External Interrupt 9",
-    [TT_EXTINT | 0xa] = "External Interrupt 10",
-    [TT_EXTINT | 0xb] = "External Interrupt 11",
-    [TT_EXTINT | 0xc] = "External Interrupt 12",
-    [TT_EXTINT | 0xd] = "External Interrupt 13",
-    [TT_EXTINT | 0xe] = "External Interrupt 14",
-    [TT_EXTINT | 0xf] = "External Interrupt 15",
-};
-#endif
-
-void do_interrupt(CPUState *env)
-{
-    int intno = env->exception_index;
-
-#ifdef DEBUG_PCALL
-    if (loglevel & CPU_LOG_INT) {
-        static int count;
-        const char *name;
-
-        if (intno < 0 || intno >= 0x180)
-            name = "Unknown";
-        else if (intno >= 0x100)
-            name = "Trap Instruction";
-        else if (intno >= 0xc0)
-            name = "Window Fill";
-        else if (intno >= 0x80)
-            name = "Window Spill";
-        else {
-            name = excp_names[intno];
-            if (!name)
-                name = "Unknown";
-        }
-
-        fprintf(logfile, "%6d: %s (v=%04x) pc=%016" PRIx64 " npc=%016" PRIx64
-                " SP=%016" PRIx64 "\n",
-                count, name, intno,
-                env->pc,
-                env->npc, env->regwptr[6]);
-        cpu_dump_state(env, logfile, fprintf, 0);
-#if 0
-        {
-            int i;
-            uint8_t *ptr;
-
-            fprintf(logfile, "       code=");
-            ptr = (uint8_t *)env->pc;
-            for(i = 0; i < 16; i++) {
-                fprintf(logfile, " %02x", ldub(ptr + i));
-            }
-            fprintf(logfile, "\n");
-        }
-#endif
-        count++;
-    }
-#endif
-#if !defined(CONFIG_USER_ONLY)
-    if (env->tl >= env->maxtl) {
-        cpu_abort(env, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
-                  " Error state", env->exception_index, env->tl, env->maxtl);
-        return;
-    }
-#endif
-    if (env->tl < env->maxtl - 1) {
-        env->tl++;
-    } else {
-        env->pstate |= PS_RED;
-        if (env->tl < env->maxtl)
-            env->tl++;
-    }
-    env->tsptr = &env->ts[env->tl & MAXTL_MASK];
-    env->tsptr->tstate = ((uint64_t)GET_CCR(env) << 32) |
-        ((env->asi & 0xff) << 24) | ((env->pstate & 0xf3f) << 8) |
-        GET_CWP64(env);
-    env->tsptr->tpc = env->pc;
-    env->tsptr->tnpc = env->npc;
-    env->tsptr->tt = intno;
-    if (!(env->def->features & CPU_FEATURE_GL)) {
-        switch (intno) {
-        case TT_IVEC:
-            change_pstate(PS_PEF | PS_PRIV | PS_IG);
-            break;
-        case TT_TFAULT:
-        case TT_TMISS:
-        case TT_DFAULT:
-        case TT_DMISS:
-        case TT_DPROT:
-            change_pstate(PS_PEF | PS_PRIV | PS_MG);
-            break;
-        default:
-            change_pstate(PS_PEF | PS_PRIV | PS_AG);
-            break;
-        }
-    }
-    if (intno == TT_CLRWIN)
-        cpu_set_cwp(env, cpu_cwp_dec(env, env->cwp - 1));
-    else if ((intno & 0x1c0) == TT_SPILL)
-        cpu_set_cwp(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
-    else if ((intno & 0x1c0) == TT_FILL)
-        cpu_set_cwp(env, cpu_cwp_inc(env, env->cwp + 1));
-    env->tbr &= ~0x7fffULL;
-    env->tbr |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5);
-    env->pc = env->tbr;
-    env->npc = env->pc + 4;
-    env->exception_index = 0;
-}
-#else
-#ifdef DEBUG_PCALL
-static const char * const excp_names[0x80] = {
-    [TT_TFAULT] = "Instruction Access Fault",
-    [TT_ILL_INSN] = "Illegal Instruction",
-    [TT_PRIV_INSN] = "Privileged Instruction",
-    [TT_NFPU_INSN] = "FPU Disabled",
-    [TT_WIN_OVF] = "Window Overflow",
-    [TT_WIN_UNF] = "Window Underflow",
-    [TT_UNALIGNED] = "Unaligned Memory Access",
-    [TT_FP_EXCP] = "FPU Exception",
-    [TT_DFAULT] = "Data Access Fault",
-    [TT_TOVF] = "Tag Overflow",
-    [TT_EXTINT | 0x1] = "External Interrupt 1",
-    [TT_EXTINT | 0x2] = "External Interrupt 2",
-    [TT_EXTINT | 0x3] = "External Interrupt 3",
-    [TT_EXTINT | 0x4] = "External Interrupt 4",
-    [TT_EXTINT | 0x5] = "External Interrupt 5",
-    [TT_EXTINT | 0x6] = "External Interrupt 6",
-    [TT_EXTINT | 0x7] = "External Interrupt 7",
-    [TT_EXTINT | 0x8] = "External Interrupt 8",
-    [TT_EXTINT | 0x9] = "External Interrupt 9",
-    [TT_EXTINT | 0xa] = "External Interrupt 10",
-    [TT_EXTINT | 0xb] = "External Interrupt 11",
-    [TT_EXTINT | 0xc] = "External Interrupt 12",
-    [TT_EXTINT | 0xd] = "External Interrupt 13",
-    [TT_EXTINT | 0xe] = "External Interrupt 14",
-    [TT_EXTINT | 0xf] = "External Interrupt 15",
-    [TT_TOVF] = "Tag Overflow",
-    [TT_CODE_ACCESS] = "Instruction Access Error",
-    [TT_DATA_ACCESS] = "Data Access Error",
-    [TT_DIV_ZERO] = "Division By Zero",
-    [TT_NCP_INSN] = "Coprocessor Disabled",
-};
-#endif
-
-void do_interrupt(CPUState *env)
-{
-    int cwp, intno = env->exception_index;
-
-#ifdef DEBUG_PCALL
-    if (loglevel & CPU_LOG_INT) {
-        static int count;
-        const char *name;
-
-        if (intno < 0 || intno >= 0x100)
-            name = "Unknown";
-        else if (intno >= 0x80)
-            name = "Trap Instruction";
-        else {
-            name = excp_names[intno];
-            if (!name)
-                name = "Unknown";
-        }
-
-        fprintf(logfile, "%6d: %s (v=%02x) pc=%08x npc=%08x SP=%08x\n",
-                count, name, intno,
-                env->pc,
-                env->npc, env->regwptr[6]);
-        cpu_dump_state(env, logfile, fprintf, 0);
-#if 0
-        {
-            int i;
-            uint8_t *ptr;
-
-            fprintf(logfile, "       code=");
-            ptr = (uint8_t *)env->pc;
-            for(i = 0; i < 16; i++) {
-                fprintf(logfile, " %02x", ldub(ptr + i));
-            }
-            fprintf(logfile, "\n");
-        }
-#endif
-        count++;
-    }
-#endif
-#if !defined(CONFIG_USER_ONLY)
-    if (env->psret == 0) {
-        cpu_abort(env, "Trap 0x%02x while interrupts disabled, Error state",
-                  env->exception_index);
-        return;
-    }
-#endif
-    env->psret = 0;
-    cwp = cpu_cwp_dec(env, env->cwp - 1);
-    cpu_set_cwp(env, cwp);
-    env->regwptr[9] = env->pc;
-    env->regwptr[10] = env->npc;
-    env->psrps = env->psrs;
-    env->psrs = 1;
-    env->tbr = (env->tbr & TBR_BASE_MASK) | (intno << 4);
-    env->pc = env->tbr;
-    env->npc = env->pc + 4;
-    env->exception_index = 0;
-}
-#endif
-
 void memcpy32(target_ulong *dst, const target_ulong *src)
 {
     dst[0] = src[0];
target-sparc/op_helper.c +228 -0

234 lines not on this page · raw message

#8 lore raw
Quoted 4 lines

Surprisingly it was moving of do_interrupt to helper.c that caused the bug. Moving it back to op_helper.c allows Sparc64 to boot. I'm still trying to understand the real cause of the bug and to find if there is some other way of fixing this. This kind of voodoo makes me nervous.

do_interrupt calls change_pstate, which relies on global register state. Global register state is only valid when called directly from translated code or other code that includes exec.h.

You should never call code in op_helper.c from outside that file (or cpu-exec.h). The easy way to enforce this is to put teh declarations for functions defined in op_helper.h in exec.h, not helper.h or cpu.h. Failure to follow this rule results in bugs like the one you've encountered.

helper.h is included multiple times, so should really just contain DEF_HELPER statements.

Paul

#9 lore raw
Quoted 10 lines · Paul Brook
Quoted 4 lines

Surprisingly it was moving of do_interrupt to helper.c that caused the bug. Moving it back to op_helper.c allows Sparc64 to boot. I'm still trying to understand the real cause of the bug and to find if there is some other way of fixing this. This kind of voodoo makes me nervous.

do_interrupt calls change_pstate, which relies on global register state.
Global register state is only valid when called directly from translated code or other code that includes exec.h.

Quoted 7 lines

You should never call code in op_helper.c from outside that file (or cpu-exec.h). The easy way to enforce this is to put teh declarations for functions defined in op_helper.h in exec.h, not helper.h or cpu.h. Failure to follow this rule results in bugs like the one you've encountered.

helper.h is included multiple times, so should really just contain DEF_HELPER statements.

Thanks, great advice. I'll check all exported functions.