Files
openbios/arch/x86/forthload.c
Mark Cave-Ayland 8a6d445d38 Introduce the concept of the OF saved-program-state structure and modify all of the loaders (except PPC) to make use of it.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>


git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@708 f158a5a8-5612-0410-a976-696ce0be7e32
2010-03-26 21:17:32 +00:00

81 lines
1.8 KiB
C

/* tag: forth source loader
*
* Copyright (C) 2004 Stefan Reinauer
*
* See the file "COPYING" for further information about
* the copyright and warranty status of this work.
*/
#include "config.h"
#include "kernel/kernel.h"
#include "libopenbios/bindings.h"
#include "libopenbios/sys_info.h"
#include "libc/diskio.h"
#include "boot.h"
#define printk printk
#define debug printk
static char *forthtext=NULL;
static int fd;
int forth_load(struct sys_info *info, const char *filename, const char *cmdline)
{
char magic[2];
unsigned long forthsize;
int retval = -1;
/* Mark the saved-program-state as invalid */
feval("0 state-valid !");
fd = open_io(filename);
if (!fd)
goto out;
if (read_io(fd, magic, 2) != 2) {
debug("Can't read magic header\n");
retval = LOADER_NOT_SUPPORT;
goto out;
}
if (magic[0] != '\\' || magic[1] != ' ') {
debug("No forth source image\n");
retval = LOADER_NOT_SUPPORT;
goto out;
}
/* 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);
printk("Loading forth source ...");
if (read_io(fd, forthtext, forthsize) != forthsize) {
printk("Can't read forth text\n");
goto out;
}
forthtext[forthsize]=0;
printk("ok\n");
close_io(fd);
// Initialise saved-program-state
PUSH((ucell)forthtext);
feval("saved-program-state >sps.entry !");
PUSH((ucell)forthsize);
feval("saved-program-state >sps.file-size !");
feval("forth saved-program-state >sps.file-type !");
feval("-1 state-valid !");
PUSH ( (ucell)forthtext );
PUSH ( (ucell)forthsize );
fword("eval2");
retval=0;
out:
//if (forthtext)
// free(forthtext);
return retval;
}