1 /* tag: forth source loader
3 * Copyright (C) 2004 Stefan Reinauer
5 * See the file "COPYING" for further information about
6 * the copyright and warranty status of this work.
10 #include "kernel/kernel.h"
11 #include "libopenbios/bindings.h"
12 #include "libopenbios/sys_info.h"
13 #include "libc/diskio.h"
14 #include "libopenbios/forth_load.h"
19 static char *forthtext=NULL;
21 int is_forth(char *forth)
23 return (forth[0] == '\\' && forth[1] == ' ');
26 int forth_load(ihandle_t dev)
29 unsigned long forthsize;
32 /* Mark the saved-program-state as invalid */
33 feval("0 state-valid !");
40 if (read_io(fd, magic, 2) != 2) {
41 debug("Can't read magic header\n");
42 retval = LOADER_NOT_SUPPORT;
46 if (!is_forth(magic)) {
47 debug("No forth source image\n");
48 retval = LOADER_NOT_SUPPORT;
52 /* Calculate the file size by seeking to the end of the file */
55 forthtext = malloc(forthsize+1);
58 printk("Loading forth source ...");
59 if ((size_t)read_io(fd, forthtext, forthsize) != forthsize) {
60 printk("Can't read forth text\n");
63 forthtext[forthsize]=0;
66 // Initialise saved-program-state
67 PUSH((ucell)forthtext);
68 feval("saved-program-state >sps.entry !");
69 PUSH((ucell)forthsize);
70 feval("saved-program-state >sps.file-size !");
71 feval("forth saved-program-state >sps.file-type !");
73 feval("-1 state-valid !");
84 forth_init_program(void)
86 // Currently not implemented
87 feval("0 state-valid !");