forth: implement load/init-program as per IEEE-1275 specification

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>
This commit is contained in:
Mark Cave-Ayland 2016-08-28 16:06:50 +01:00
parent cf51d0eac4
commit d6a5ca977b
2 changed files with 16 additions and 23 deletions

View File

@ -9,6 +9,7 @@
#include "config.h" #include "config.h"
#include "kernel/kernel.h" #include "kernel/kernel.h"
#include "libopenbios/bindings.h" #include "libopenbios/bindings.h"
#include "libopenbios/initprogram.h"
#include "libopenbios/sys_info.h" #include "libopenbios/sys_info.h"
#include "libc/diskio.h" #include "libc/diskio.h"
#include "libopenbios/forth_load.h" #include "libopenbios/forth_load.h"
@ -16,7 +17,6 @@
#define debug printk #define debug printk
static int fd; static int fd;
static char *forthtext=NULL;
int is_forth(char *forth) int is_forth(char *forth)
{ {
@ -27,6 +27,7 @@ int forth_load(ihandle_t dev)
{ {
char magic[2]; char magic[2];
unsigned long forthsize; unsigned long forthsize;
ucell *forthtext;
int retval = -1; int retval = -1;
/* Mark the saved-program-state as invalid */ /* 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 */ /* Calculate the file size by seeking to the end of the file */
seek_io(fd, -1); seek_io(fd, -1);
forthsize = tell(fd); forthsize = tell(fd);
forthtext = malloc(forthsize+1);
seek_io(fd, 0); seek_io(fd, 0);
fword("load-base");
forthtext = (void *)POP();
printk("Loading forth source ..."); printk("Loading forth source ...");
if ((size_t)read_io(fd, forthtext, forthsize) != forthsize) { if ((size_t)read_io(fd, forthtext, forthsize) != forthsize) {
printk("Can't read forth text\n"); printk("Can't read forth text\n");
goto out; goto out;
} }
forthtext[forthsize]=0; forthtext[(forthsize / sizeof(ucell)) + 1]=0;
printk("ok\n"); printk("ok\n");
// Initialise saved-program-state // Initialise saved-program-state
PUSH((ucell)forthtext);
feval("load-state >ls.entry !");
PUSH((ucell)forthsize); PUSH((ucell)forthsize);
feval("load-state >ls.file-size !"); feval("load-state >ls.file-size !");
feval("forth load-state >ls.file-type !"); feval("forth load-state >ls.file-type !");
feval("-1 state-valid !");
retval=0;
out: out:
//if (forthtext)
// free(forthtext);
return retval; return retval;
} }
void void
forth_init_program(void) forth_init_program(void)
{ {
// Currently not implemented /* Use trampoline context to execute Forth */
feval("0 state-valid !"); PUSH((ucell)&init_forth_context);
feval("load-state >ls.entry !");
arch_init_program();
feval("-1 state-valid !");
} }

View File

@ -51,15 +51,11 @@ void load(ihandle_t dev)
{ {
/* Invoke the loaders on the specified device */ /* Invoke the loaders on the specified device */
char *param; char *param;
ucell valid = 0;
/* TODO: Currently the internal loader APIs use load-base directly, so /* TODO: Currently the internal loader APIs use load-base directly, so
drop the address */ drop the address */
POP(); POP();
/* Temporarily keep compiler quiet during transition */
valid = valid;
#ifdef CONFIG_LOADER_ELF #ifdef CONFIG_LOADER_ELF
/* Grab the boot arguments */ /* Grab the boot arguments */
@ -92,12 +88,9 @@ void load(ihandle_t dev)
#endif #endif
#ifdef CONFIG_LOADER_FORTH #ifdef CONFIG_LOADER_FORTH
forth_load(dev); if (forth_load(dev) != LOADER_NOT_SUPPORT) {
feval("state-valid @"); feval("load-state >ls.file-size @");
valid = POP(); return;
if (valid) {
feval("load-state >ls.file-size @");
return;
} }
#endif #endif