[OpenBIOS] sparc32 __context initialization

Artyom Tarasenko atar4qemu at gmail.com
Wed Feb 9 18:10:12 CET 2011

According to the IEEE-1275 SPARC supplement, the default load address
is the virtual address 0x4000, so looks like we don't have to map the
addresses 0x0 - 0x3fff.

I thought it might be useful actually not to map at least the page 0,
as it would help to catch null pointer dereferences.

So, I went on and made a trivial modification:

--- arch/sparc32/lib.c  (revision 1024)
+++ arch/sparc32/lib.c  (working copy)
@@ -461,7 +461,7 @@
     map_pages(pa, va, size, ofmem_arch_default_translation_mode(pa));

     // 1:1 mapping for RAM
-    map_pages(0, 0, LOWMEMSZ, ofmem_arch_default_translation_mode(0));
+    map_pages(0x4000, 0x4000, LOWMEMSZ,

      * Flush cache

Surprisingly, with this modification a null pointer dereference
happens much earlier than I'd expected: for some reason  __context
doesn't get initialized in arch/sparc32/context.c, so OpenBIOS dies
before saying hello.

If I initialize it in start_main the same way it should have been
initialized statically,

+    __context = &main_ctx;

then OpenBIOS starts and is able to boot at least Debian.
Any idea what might be wrong with the current static initialization?
For convenience I paste the code from arch/sparc32/context.c :

static struct context main_ctx = {
    .regs[REG_SP] = (uint32_t) &_estack - 96,
    .pc = (uint32_t) start_main,
    .npc = (uint32_t) start_main + 4,
    .return_addr = (uint32_t) __exit_context,

/* This is used by assembly routine to load/store the context which
 * it is to switch/switched.  */
struct context *__context = &main_ctx;

Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/

More information about the OpenBIOS mailing list