summaryrefslogtreecommitdiffstats
path: root/qemu/roms/openbios/libopenbios/forth_load.c
diff options
context:
space:
mode:
authorYang Zhang <yang.z.zhang@intel.com>2015-08-28 09:58:54 +0800
committerYang Zhang <yang.z.zhang@intel.com>2015-09-01 12:44:00 +0800
commite44e3482bdb4d0ebde2d8b41830ac2cdb07948fb (patch)
tree66b09f592c55df2878107a468a91d21506104d3f /qemu/roms/openbios/libopenbios/forth_load.c
parent9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (diff)
Add qemu 2.4.0
Change-Id: Ic99cbad4b61f8b127b7dc74d04576c0bcbaaf4f5 Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Diffstat (limited to 'qemu/roms/openbios/libopenbios/forth_load.c')
-rw-r--r--qemu/roms/openbios/libopenbios/forth_load.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/qemu/roms/openbios/libopenbios/forth_load.c b/qemu/roms/openbios/libopenbios/forth_load.c
new file mode 100644
index 000000000..c3a1929f2
--- /dev/null
+++ b/qemu/roms/openbios/libopenbios/forth_load.c
@@ -0,0 +1,88 @@
+/* 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 "libopenbios/forth_load.h"
+#define printk printk
+#define debug printk
+
+static int fd;
+static char *forthtext=NULL;
+
+int is_forth(char *forth)
+{
+ return (forth[0] == '\\' && forth[1] == ' ');
+}
+
+int forth_load(ihandle_t dev)
+{
+ char magic[2];
+ unsigned long forthsize;
+ int retval = -1;
+
+ /* Mark the saved-program-state as invalid */
+ feval("0 state-valid !");
+
+ fd = open_ih(dev);
+ if (fd == -1) {
+ goto out;
+ }
+
+ if (read_io(fd, magic, 2) != 2) {
+ debug("Can't read magic header\n");
+ retval = LOADER_NOT_SUPPORT;
+ goto out;
+ }
+
+ if (!is_forth(magic)) {
+ 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 ((size_t)read_io(fd, forthtext, forthsize) != forthsize) {
+ printk("Can't read forth text\n");
+ goto out;
+ }
+ forthtext[forthsize]=0;
+ printk("ok\n");
+
+ // 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 !");
+
+ retval=0;
+
+out:
+ //if (forthtext)
+ // free(forthtext);
+ return retval;
+}
+
+void
+forth_init_program(void)
+{
+ // Currently not implemented
+ feval("0 state-valid !");
+}