load should place the file at load-base, whilst init-program should parse the memory at load-base and set up the context accordingly.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- libopenbios/forth_load.c | 26 +++++++++++++------------- libopenbios/load.c | 13 +++---------- 2 files changed, 16 insertions(+), 23 deletions(-)
diff --git a/libopenbios/forth_load.c b/libopenbios/forth_load.c index 35835fb..4433635 100644 --- a/libopenbios/forth_load.c +++ b/libopenbios/forth_load.c @@ -9,6 +9,7 @@ #include "config.h" #include "kernel/kernel.h" #include "libopenbios/bindings.h" +#include "libopenbios/initprogram.h" #include "libopenbios/sys_info.h" #include "libc/diskio.h" #include "libopenbios/forth_load.h" @@ -16,7 +17,6 @@ #define debug printk
static int fd; -static char *forthtext=NULL;
int is_forth(char *forth) { @@ -27,6 +27,7 @@ int forth_load(ihandle_t dev) { char magic[2]; unsigned long forthsize; + ucell *forthtext; int retval = -1;
/* Mark the saved-program-state as invalid */ @@ -52,37 +53,36 @@ int forth_load(ihandle_t dev) /* Calculate the file size by seeking to the end of the file */ seek_io(fd, -1); forthsize = tell(fd); - forthtext = malloc(forthsize+1); seek_io(fd, 0);
+ fword("load-base"); + forthtext = (void *)POP(); + printk("Loading forth source ..."); if ((size_t)read_io(fd, forthtext, forthsize) != forthsize) { printk("Can't read forth text\n"); goto out; } - forthtext[forthsize]=0; + forthtext[(forthsize / sizeof(ucell)) + 1]=0; printk("ok\n");
// Initialise saved-program-state - PUSH((ucell)forthtext); - feval("load-state >ls.entry !"); PUSH((ucell)forthsize); feval("load-state >ls.file-size !"); feval("forth load-state >ls.file-type !");
- feval("-1 state-valid !"); - - retval=0; - out: - //if (forthtext) - // free(forthtext); return retval; }
void forth_init_program(void) { - // Currently not implemented - feval("0 state-valid !"); + /* Use trampoline context to execute Forth */ + PUSH((ucell)&init_forth_context); + feval("load-state >ls.entry !"); + + arch_init_program(); + + feval("-1 state-valid !"); } diff --git a/libopenbios/load.c b/libopenbios/load.c index 1d64cc7..048f459 100644 --- a/libopenbios/load.c +++ b/libopenbios/load.c @@ -51,15 +51,11 @@ void load(ihandle_t dev) { /* Invoke the loaders on the specified device */ char *param; - ucell valid = 0;
/* TODO: Currently the internal loader APIs use load-base directly, so drop the address */ POP();
- /* Temporarily keep compiler quiet during transition */ - valid = valid; - #ifdef CONFIG_LOADER_ELF
/* Grab the boot arguments */ @@ -92,12 +88,9 @@ void load(ihandle_t dev) #endif
#ifdef CONFIG_LOADER_FORTH - forth_load(dev); - feval("state-valid @"); - valid = POP(); - if (valid) { - feval("load-state >ls.file-size @"); - return; + if (forth_load(dev) != LOADER_NOT_SUPPORT) { + feval("load-state >ls.file-size @"); + return; } #endif