Index: openbios-devel/arch/sparc64/aoutload.c
===================================================================
--- openbios-devel.orig/arch/sparc64/aoutload.c
+++ openbios-devel/arch/sparc64/aoutload.c
@@ -133,16 +133,10 @@ int aout_load(struct sys_info *info, con
     debug("entry point is %#lx\n", start);
     printf("Jumping to entry point...\n");
 
-#if 1
     {
-        int (*entry)(unsigned long p1, unsigned long p2, unsigned long p3,
-                      unsigned long p4, unsigned long p5);
-        extern int of_client_interface( int *params );
-
-        entry = (void *) addr_fixup(start);
-        image_retval = entry(0, 0, 0, 0, (unsigned long)&of_client_interface);
+    	extern int of_client_interface( int *params );
+    	image_retval = start_client_image(addr_fixup(start), &of_client_interface);
     }
-#endif
 
     printf("Image returned with return value %#x\n", image_retval);
     retval = 0;
Index: openbios-devel/arch/sparc64/context.c
===================================================================
--- openbios-devel.orig/arch/sparc64/context.c
+++ openbios-devel/arch/sparc64/context.c
@@ -23,7 +23,7 @@ void __exit_context(void); /* assembly r
  * to start us up.
  */
 static struct context main_ctx = {
-    .regs[REG_SP] = (uint64_t) &_estack - 2047 - 96,
+    .regs[REG_SP] = (uint64_t) &_estack - STACK_BIAS - 96,
     .pc = (uint64_t) start_main,
     .npc = (uint64_t) start_main + 4,
     .return_addr = (uint64_t) __exit_context,
@@ -31,7 +31,7 @@ static struct context main_ctx = {
 
 /* This is used by assembly routine to load/store the context which
  * it is to switch/switched.  */
-struct context *__context = &main_ctx;
+struct context * volatile __context = &main_ctx;
 
 /* Stack for loaded ELF image */
 static uint8_t image_stack[IMAGE_STACK_SIZE];
@@ -62,6 +62,11 @@ static void start_main(void)
     __context = boot_ctx;
 }
 
+static uint64_t ALIGN_SIZE(uint64_t x, uint64_t a)
+{
+    return (x + a - 1) & ~(a-1);
+}
+
 /* Setup a new context using the given stack.
  */
 struct context *
@@ -70,11 +75,11 @@ init_context(uint8_t *stack, uint64_t st
     struct context *ctx;
 
     ctx = (struct context *)
-	(stack + stack_size - (sizeof(*ctx) + num_params*sizeof(uint32_t)));
+	(stack + stack_size - ALIGN_SIZE(sizeof(*ctx) + num_params*sizeof(uint64_t), sizeof(uint64_t)));
     memset(ctx, 0, sizeof(*ctx));
 
     /* Fill in reasonable default for flat memory model */
-    ctx->regs[REG_SP] = virt_to_phys(SP_LOC(ctx));
+    ctx->regs[REG_SP] = virt_to_phys(stack - STACK_BIAS);
     ctx->return_addr = virt_to_phys(__exit_context);
 
     return ctx;
@@ -85,10 +90,11 @@ struct context *switch_to(struct context
 {
     struct context *save, *ret;
 
-    debug("switching to new context:\n");
+    debug("switching to new context: entry point %#lx stack 0x%08lx\n", ctx->pc, ctx->regs[REG_SP]);
     save = __context;
     __context = ctx;
     //asm ("pushl %cs; call __switch_context");
+    asm ("call __switch_context_nosave; nop");
     ret = __context;
     __context = save;
     return ret;
@@ -109,3 +115,18 @@ uint64_t start_elf(uint64_t entry_point,
     //return ctx->eax;
     return 0;
 }
+
+/* Start client image */
+uint64_t start_client_image(uint64_t entry_point, uint64_t cif_handler)
+{
+    struct context *ctx;
+
+    ctx = init_context(image_stack, sizeof image_stack, 0);
+    ctx->pc  = entry_point;
+    ctx->npc = entry_point+4;
+    ctx->regs[REG_O0+4] = cif_handler;
+
+    ctx = switch_to(ctx);
+
+    return 0;
+}
Index: openbios-devel/arch/sparc64/context.h
===================================================================
--- openbios-devel.orig/arch/sparc64/context.h
+++ openbios-devel/arch/sparc64/context.h
@@ -1,6 +1,8 @@
 #ifndef SPARC64_CONTEXT_H
 #define SPARC64_CONTEXT_H
 
+#define STACK_BIAS             2047
+
 struct context {
     /* General registers */
     uint64_t regs[32];
Index: openbios-devel/arch/sparc64/boot.h
===================================================================
--- openbios-devel.orig/arch/sparc64/boot.h
+++ openbios-devel/arch/sparc64/boot.h
@@ -22,8 +22,9 @@ int linux_load(struct sys_info *info, co
 int fcode_load(const char *filename);
 
 // context.c
-extern struct context *__context;
+extern struct context * volatile __context;
 uint64_t start_elf(uint64_t entry_point, uint64_t param);
+uint64_t start_client_image(uint64_t entry_point, uint64_t cif_handler);
 
 // boot.c
 extern struct sys_info sys_info;
