[OpenBIOS] C bindings

Stefan Reinauer stepan at openbios.org
Thu Oct 30 14:50:09 CET 2003


* Samuel Rydh <samuel at ibrium.se> [031030 13:03]:
> Wouldn't it make sense to add some C-bindings to the forth
> kernel? I have examined all the built-in tokens and as far
> as far as I can tell there is currently no way to call an
> external function (well, save abusing the inb/outb mechanism).

true. it is definitely needed.

> To make the C-code and the forth code interoperate, I would
> like to be able to
> 
> 1. Call C-functions from forth code by pushing the address
> of the function on the stack. Something like
> 
> 	call	( function_addr -- <whatever> )
 
see attachment.

> 2. Be able to invoke the forth interpreter from C-code
> (I think this can be implementable without modifying
> the kernel code, but I haven't looked into it yet).
 
this can be done for example with 
kernel/openbios.c:void openbios(ucell dictstart, ucell dictend)
or directly by calling enterforth(). Note that the engine does
not allow running multiple concurrent instances (yet).

   Stefan
  
-------------- next part --------------
Index: arch/unix/unix.c
===================================================================
RCS file: /srv/cvs/openbios/kernel/arch/unix/unix.c,v
retrieving revision 1.22
diff -u -r1.22 unix.c
--- arch/unix/unix.c	21 Oct 2003 20:55:33 -0000	1.22
+++ arch/unix/unix.c	30 Oct 2003 13:17:41 -0000
@@ -76,7 +76,7 @@
 	"sp@", "move", "fill", "(emit)", "(?key)", "(key)", "execute",
 	"here", "here!", "dobranch", "do?branch", "unaligned-w@",
 	"unaligned-w!", "unaligned-l@", "unaligned-l!", "ioc@", "iow@",
-	"iol@", "ioc!", "iow!", "iol!", "i", "j"
+	"iol@", "ioc!", "iow!", "iol!", "i", "j", "call"
 };
 
 /*
@@ -758,6 +758,11 @@
 
 #define USAGE   "usage: %s [options] [dictionary file|source file]\n\n"
 
+void banner(void)
+{
+	printf(BANNER);
+}
+		
 int main(int argc, char *argv[])
 {
 	struct sigaction sa;
@@ -850,6 +855,7 @@
 
 	/* set terminal to do non blocking reads */
 	init_terminal();
+	printf("BANNER: %p\n",banner);
 	read_dictionary(argv[optind]);
 	PC = findword("initialize");
 	if (PC != (ucell) (-1)) {
Index: kernel/internal.c
===================================================================
RCS file: /srv/cvs/openbios/kernel/kernel/internal.c,v
retrieving revision 1.2
diff -u -r1.2 internal.c
--- kernel/internal.c	21 Oct 2003 20:55:33 -0000	1.2
+++ kernel/internal.c	30 Oct 2003 13:17:41 -0000
@@ -152,6 +152,19 @@
 	PC = (ucell) & trampoline;
 }
 
+/*
+ * call ( ... function-ptr -- ??? ) 
+ */
+static void call(void)
+{
+	void (*funcptr) (void);
+	funcptr=(void *)POP();
+#ifdef DEBUG_INTERPRETER
+	printk("call: %x", funcptr);
+#endif
+	funcptr();
+}
+
 static void dodoes(void)
 {				/* DODOES */
 	ucell data = *(ucell *) PC + (2 * sizeof(ucell));
Index: kernel/primitives.c
===================================================================
RCS file: /srv/cvs/openbios/kernel/kernel/primitives.c,v
retrieving revision 1.10
diff -u -r1.10 primitives.c
--- kernel/primitives.c	12 Oct 2003 14:00:00 -0000	1.10
+++ kernel/primitives.c	30 Oct 2003 13:17:41 -0000
@@ -134,5 +134,6 @@
 	iowstore,		/* iow!    */
 	iolstore,		/* iol!    */
 	loop_i,			/* i       */
-	loop_j			/* j       */
+	loop_j,			/* j       */
+	call			/* call    */
 };


More information about the OpenBIOS mailing list