sparc32: move /uuid property setup to openbios.c
[openbios.git] / libopenbios / forth_load.c
blobc3a1929f2d69e68cc1978d6e10b540ff59c1c7ec
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.
7 */
9 #include "config.h"
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"
15 #define printk printk
16 #define debug printk
18 static int fd;
19 static char *forthtext=NULL;
21 int is_forth(char *forth)
23 return (forth[0] == '\\' && forth[1] == ' ');
26 int forth_load(ihandle_t dev)
28 char magic[2];
29 unsigned long forthsize;
30 int retval = -1;
32 /* Mark the saved-program-state as invalid */
33 feval("0 state-valid !");
35 fd = open_ih(dev);
36 if (fd == -1) {
37 goto out;
40 if (read_io(fd, magic, 2) != 2) {
41 debug("Can't read magic header\n");
42 retval = LOADER_NOT_SUPPORT;
43 goto out;
46 if (!is_forth(magic)) {
47 debug("No forth source image\n");
48 retval = LOADER_NOT_SUPPORT;
49 goto out;
52 /* Calculate the file size by seeking to the end of the file */
53 seek_io(fd, -1);
54 forthsize = tell(fd);
55 forthtext = malloc(forthsize+1);
56 seek_io(fd, 0);
58 printk("Loading forth source ...");
59 if ((size_t)read_io(fd, forthtext, forthsize) != forthsize) {
60 printk("Can't read forth text\n");
61 goto out;
63 forthtext[forthsize]=0;
64 printk("ok\n");
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 !");
75 retval=0;
77 out:
78 //if (forthtext)
79 // free(forthtext);
80 return retval;
83 void
84 forth_init_program(void)
86 // Currently not implemented
87 feval("0 state-valid !");