2006-04-27 00:39:16 +08:00
|
|
|
/* 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 "openbios/config.h"
|
2010-03-14 22:21:02 +08:00
|
|
|
#include "kernel/kernel.h"
|
2006-04-27 00:39:16 +08:00
|
|
|
#include "openbios/bindings.h"
|
|
|
|
#include "sys_info.h"
|
|
|
|
#include "loadfs.h"
|
|
|
|
#include "boot.h"
|
|
|
|
#define printk printk
|
|
|
|
#define debug printk
|
|
|
|
|
|
|
|
static char *forthtext=NULL;
|
2008-11-30 19:54:01 +08:00
|
|
|
|
|
|
|
int forth_load(const char *filename)
|
2006-04-27 00:39:16 +08:00
|
|
|
{
|
|
|
|
char magic[2];
|
|
|
|
unsigned long forthsize;
|
|
|
|
int retval = -1;
|
|
|
|
|
|
|
|
if (!file_open(filename))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (lfile_read(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
forthsize = file_size();
|
2008-07-08 02:35:51 +08:00
|
|
|
|
2006-04-27 00:39:16 +08:00
|
|
|
forthtext = malloc(forthsize+1);
|
|
|
|
file_seek(0);
|
2008-07-08 02:35:51 +08:00
|
|
|
|
2006-04-27 00:39:16 +08:00
|
|
|
printk("Loading forth source ...");
|
|
|
|
if ((unsigned long)lfile_read(forthtext, forthsize) != forthsize) {
|
|
|
|
printk("Can't read forth text\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
forthtext[forthsize]=0;
|
|
|
|
printk("ok\n");
|
|
|
|
|
|
|
|
PUSH ( (ucell)forthtext );
|
|
|
|
PUSH ( (ucell)forthsize );
|
|
|
|
fword("eval2");
|
|
|
|
retval=0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
//if (forthtext)
|
|
|
|
// free(forthtext);
|
|
|
|
return retval;
|
|
|
|
}
|