Make sure that __context points to it to potentially allow state to be viewed/altered beforehand.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- arch/amd64/context.c | 10 ++++++++-- arch/ppc/qemu/context.c | 13 ++++++++++--- arch/sparc32/context.c | 10 ++++++++-- arch/sparc64/context.c | 13 +++++++++---- arch/x86/context.c | 11 +++++++++-- 5 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/arch/amd64/context.c b/arch/amd64/context.c index 33ab51e..be70afe 100644 --- a/arch/amd64/context.c +++ b/arch/amd64/context.c @@ -39,6 +39,9 @@ struct context main_ctx __attribute__((section (".initctx"))) = { * it is to switch/switched. */ struct context *__context = &main_ctx;
+/* Client program context */ +static struct context *client_ctx; + /* Stack for loaded ELF image */ static uint8_t image_stack[IMAGE_STACK_SIZE];
@@ -58,6 +61,10 @@ static void start_main(void) * We have to keep it in physical address since we will relocate. */ __boot_ctx = virt_to_phys(__context);
+ /* Set up client context */ + client_ctx = init_context(image_stack, sizeof image_stack, 1); + __context = client_ctx; + /* Start the real fun */ retval = openbios();
@@ -112,9 +119,8 @@ struct context *switch_to(struct context *ctx) /* Start ELF Boot image */ uint32_t start_elf(uint32_t entry_point, uint32_t param) { - struct context *ctx; + struct context *ctx = client_ctx;
- ctx = init_context(image_stack, sizeof image_stack, 1); ctx->eip = entry_point; ctx->param[0] = param; ctx->eax = 0xe1fb007; diff --git a/arch/ppc/qemu/context.c b/arch/ppc/qemu/context.c index 78205a2..74a604f 100644 --- a/arch/ppc/qemu/context.c +++ b/arch/ppc/qemu/context.c @@ -6,6 +6,7 @@ #include "config.h" #include "kernel/kernel.h" #include "context.h" +#include "libopenbios/bindings.h" #include "libopenbios/sys_info.h"
#define MAIN_STACK_SIZE 16384 @@ -49,6 +50,9 @@ static struct context main_ctx = { * it is to switch/switched. */ struct context * volatile __context = &main_ctx;
+/* Client program context */ +static struct context *client_ctx; + /* Stack for loaded ELF image */ static uint8_t image_stack[IMAGE_STACK_SIZE];
@@ -65,6 +69,10 @@ static void start_main(void) * We have to keep it in physical address since we will relocate. */ __boot_ctx = virt_to_phys(__context);
+ /* Set up client context */ + client_ctx = init_context(image_stack, sizeof image_stack, 1); + __context = client_ctx; + /* Start the real fun */ entry();
@@ -115,7 +123,7 @@ struct context *switch_to(struct context *ctx) /* Start ELF Boot image */ unsigned int start_elf(unsigned long entry_point, unsigned long param) { - struct context *ctx; + struct context *ctx = client_ctx;
/* According to IEEE 1275, PPC bindings: * @@ -127,8 +135,7 @@ unsigned int start_elf(unsigned long entry_point, unsigned long param) * * Yaboot and Linux use r3 and r4 for initrd address and size */ - - ctx = init_context(image_stack, sizeof image_stack, 1); + ctx->pc = entry_point; ctx->regs[REG_R5] = (unsigned long)of_client_callback; ctx->regs[REG_R6] = 0; diff --git a/arch/sparc32/context.c b/arch/sparc32/context.c index 555f628..50b9edf 100644 --- a/arch/sparc32/context.c +++ b/arch/sparc32/context.c @@ -33,6 +33,9 @@ static struct context main_ctx = { * it is to switch/switched. */ struct context * volatile __context = &main_ctx;
+/* Client program context */ +static struct context *client_ctx; + /* Stack for loaded ELF image */ static uint8_t image_stack[IMAGE_STACK_SIZE];
@@ -49,6 +52,10 @@ static void start_main(void) * We have to keep it in physical address since we will relocate. */ __boot_ctx = virt_to_phys(__context);
+ /* Set up client context */ + client_ctx = init_context(image_stack, sizeof image_stack, 1); + __context = client_ctx; + /* Start the real fun */ openbios();
@@ -102,9 +109,8 @@ struct context *switch_to(struct context *ctx) /* Start ELF Boot image */ unsigned int start_elf(unsigned long entry_point, unsigned long param) { - struct context *ctx; + struct context *ctx = client_ctx;
- ctx = init_context(image_stack, sizeof image_stack, 1); ctx->pc = entry_point; ctx->regs[REG_O0] = param;
diff --git a/arch/sparc64/context.c b/arch/sparc64/context.c index 5ab0045..1283c4c 100644 --- a/arch/sparc64/context.c +++ b/arch/sparc64/context.c @@ -33,6 +33,9 @@ static struct context main_ctx = { * it is to switch/switched. */ struct context * volatile __context = &main_ctx;
+/* Client program context */ +static struct context *client_ctx; + /* Stack for loaded ELF image */ static uint8_t image_stack[IMAGE_STACK_SIZE];
@@ -53,6 +56,10 @@ static void start_main(void) * We have to keep it in physical address since we will relocate. */ __boot_ctx = virt_to_phys(__context);
+ /* Set up client context */ + client_ctx = init_context(image_stack, sizeof image_stack, 1); + __context = client_ctx; + /* Start the real fun */ openbios();
@@ -104,9 +111,8 @@ struct context *switch_to(struct context *ctx) /* Start ELF Boot image */ uint64_t start_elf(uint64_t entry_point, uint64_t param) { - struct context *ctx; + struct context *ctx = client_ctx;
- ctx = init_context(image_stack, sizeof image_stack, 1); ctx->pc = entry_point; ctx->param[0] = param; //ctx->eax = 0xe1fb007; @@ -120,9 +126,8 @@ uint64_t start_elf(uint64_t entry_point, uint64_t param) /* Start client image */ uint64_t start_client_image(uint64_t entry_point, uint64_t cif_handler) { - struct context *ctx; + struct context *ctx = client_ctx;
- ctx = init_context(image_stack, sizeof image_stack, 0); ctx->pc = entry_point; ctx->npc = entry_point+4; ctx->regs[REG_O0] = 0; diff --git a/arch/x86/context.c b/arch/x86/context.c index d543f74..de852f4 100644 --- a/arch/x86/context.c +++ b/arch/x86/context.c @@ -45,6 +45,9 @@ static struct context main_ctx __attribute__((section (".initctx"))) = { * it is to switch/switched. */ struct context *__context = &main_ctx;
+/* Client program context */ +static struct context *client_ctx; + /* Stack for loaded ELF image */ static uint8_t image_stack[IMAGE_STACK_SIZE];
@@ -64,6 +67,11 @@ static void start_main(void) __boot_ctx = virt_to_phys(__context);
init_exceptions(); + + /* Set up client context */ + client_ctx = init_context(image_stack, sizeof image_stack, 1); + __context = client_ctx; + /* Start the real fun */ retval = openbios();
@@ -117,9 +125,8 @@ struct context *switch_to(struct context *ctx) /* Start ELF Boot image */ unsigned int start_elf(unsigned long entry_point, unsigned long param) { - struct context *ctx; + struct context *ctx = client_ctx;
- ctx = init_context(image_stack, sizeof image_stack, 1); ctx->eip = entry_point; ctx->param[0] = param; ctx->eax = 0xe1fb007;