summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--share/examples/bootforth/boot.4th6
-rw-r--r--share/examples/bootforth/loader.rc6
-rw-r--r--sys/boot/alpha/cdboot/version1
-rw-r--r--sys/boot/alpha/loader/version1
-rw-r--r--sys/boot/common/loader.814
-rw-r--r--sys/boot/ficl/loader.c73
-rw-r--r--sys/boot/forth/loader.4th8
-rw-r--r--sys/boot/forth/pnp.4th2
-rw-r--r--sys/boot/forth/support.4th23
-rw-r--r--sys/boot/i386/loader/version1
10 files changed, 102 insertions, 33 deletions
diff --git a/share/examples/bootforth/boot.4th b/share/examples/bootforth/boot.4th
index 631775b..8f26e0d 100644
--- a/share/examples/bootforth/boot.4th
+++ b/share/examples/bootforth/boot.4th
@@ -7,15 +7,15 @@
cr .( Loading Forth extensions:)
cr .( - screen.4th...)
-s" /boot/screen.4th" fopen dup fload fclose
+s" /boot/screen.4th" O_RDONLY fopen dup fload fclose
\ Load frame support
cr .( - frames.4th...)
-s" /boot/frames.4th" fopen dup fload fclose
+s" /boot/frames.4th" O_RDONLY fopen dup fload fclose
\ Load our little menu
cr .( - menu.4th...)
-s" /boot/menu.4th" fopen dup fload fclose
+s" /boot/menu.4th" O_RDONLY fopen dup fload fclose
\ Show it
cr
diff --git a/share/examples/bootforth/loader.rc b/share/examples/bootforth/loader.rc
index d216a46..617bc3d 100644
--- a/share/examples/bootforth/loader.rc
+++ b/share/examples/bootforth/loader.rc
@@ -13,15 +13,15 @@ include /boot/loader.4th
\ Load the screen manipulation words
cr .( - screen.4th...)
-s" /boot/screen.4th" fopen dup fload fclose
+s" /boot/screen.4th" O_RDONLY fopen dup fload fclose
\ Load frame support
cr .( - frames.4th...)
-s" /boot/frames.4th" fopen dup fload fclose
+s" /boot/frames.4th" O_RDONLY fopen dup fload fclose
\ Load our little menu
cr .( - menuconf.4th...)
-s" /boot/menuconf.4th" fopen dup fload fclose
+s" /boot/menuconf.4th" O_RDONLY fopen dup fload fclose
\ Initialize loader.4th stuff
diff --git a/sys/boot/alpha/cdboot/version b/sys/boot/alpha/cdboot/version
index a544d7f..028be8b 100644
--- a/sys/boot/alpha/cdboot/version
+++ b/sys/boot/alpha/cdboot/version
@@ -3,6 +3,7 @@ $FreeBSD$
NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE. The format of this
file is important. Make sure the current version number is on line 6.
+1.2: New calling conventions for fopen.
1.1: New semantics for finding the kernel, new boot.
1.0: Released working DEC Alpha version.
0.1: Initial i386 version, germinated from the NetBSD i386
diff --git a/sys/boot/alpha/loader/version b/sys/boot/alpha/loader/version
index c4eced4..d16c215 100644
--- a/sys/boot/alpha/loader/version
+++ b/sys/boot/alpha/loader/version
@@ -3,6 +3,7 @@ $FreeBSD$
NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE. The format of this
file is important. Make sure the current version number is on line 6.
+1.2: New calling conventions for fopen.
1.1: New semantics for finding the kernel, new boot.
1.0: Released working DEC Alpha version.
0.3: Set/getenv&cia, copyin/out.
diff --git a/sys/boot/common/loader.8 b/sys/boot/common/loader.8
index 1d70aca..85c214f 100644
--- a/sys/boot/common/loader.8
+++ b/sys/boot/common/loader.8
@@ -642,9 +642,19 @@ Reads a single character from a file.
.It Ic fload Pq Ar fd --
Process file
.Em fd .
-.It Ic fopen Pq Ar addr len -- fd
+.It Ic fopen Pq Ar addr len mode Li -- Ar fd
Open a file.
-Returns a file descriptor, or -1 in case of failure.
+Returns a file descriptor, or \-1 in case of failure. The
+.Ar mode
+parameter selects whether the file is to be opened for read access, write
+access, or both.
+The constants
+.Dv O_RDONLY , O_WRONLY ,
+and
+.Dv O_RDWR
+are defined in
+.Pa /boot/support.4th ,
+indicating read only, write only, and read-write access, respectively.
.It Xo
.Ic fread
.Pq Ar fd addr len -- len'
diff --git a/sys/boot/ficl/loader.c b/sys/boot/ficl/loader.c
index 43db67f..54380b2 100644
--- a/sys/boot/ficl/loader.c
+++ b/sys/boot/ficl/loader.c
@@ -371,22 +371,37 @@ static void displayCellNoPad(FICL_VM *pVM)
/* fopen - open a file and return new fd on stack.
*
- * fopen ( count ptr -- fd )
+ * fopen ( ptr count mode -- fd )
*/
static void pfopen(FICL_VM *pVM)
{
- int fd;
- char *p;
+ int mode, fd, count;
+ char *ptr, *name;
#if FICL_ROBUST > 1
- vmCheckStack(pVM, 2, 1);
+ vmCheckStack(pVM, 3, 1);
#endif
- (void)stackPopINT(pVM->pStack); /* don't need count value */
- p = stackPopPtr(pVM->pStack);
- fd = open(p, O_RDONLY);
+
+ mode = stackPopINT(pVM->pStack); /* get mode */
+ count = stackPopINT(pVM->pStack); /* get count */
+ ptr = stackPopPtr(pVM->pStack); /* get ptr */
+
+ if ((count < 0) || (ptr == NULL)) {
+ stackPushINT(pVM->pStack, -1);
+ return;
+ }
+
+ /* ensure that the string is null terminated */
+ name = (char *)malloc(count+1);
+ bcopy(ptr,name,count);
+ name[count] = 0;
+
+ /* open the file */
+ fd = open(name, mode);
+ free(name);
stackPushINT(pVM->pStack, fd);
return;
- }
+}
/* fclose - close a file who's fd is on stack.
*
@@ -444,6 +459,46 @@ static void pfload(FICL_VM *pVM)
return;
}
+/* fwrite - write file contents
+ *
+ * fwrite ( fd buf nbytes -- nwritten )
+ */
+static void pfwrite(FICL_VM *pVM)
+{
+ int fd, len;
+ char *buf;
+
+#if FICL_ROBUST > 1
+ vmCheckStack(pVM, 3, 1);
+#endif
+ len = stackPopINT(pVM->pStack); /* get number of bytes to read */
+ buf = stackPopPtr(pVM->pStack); /* get buffer */
+ fd = stackPopINT(pVM->pStack); /* get fd */
+ if (len > 0 && buf && fd != -1)
+ stackPushINT(pVM->pStack, write(fd, buf, len));
+ else
+ stackPushINT(pVM->pStack, -1);
+ return;
+}
+
+/* fseek - seek to a new position in a file
+ *
+ * fseek ( fd ofs whence -- pos )
+ */
+static void pfseek(FICL_VM *pVM)
+{
+ int fd, pos, whence;
+
+#if FICL_ROBUST > 1
+ vmCheckStack(pVM, 3, 1);
+#endif
+ whence = stackPopINT(pVM->pStack);
+ pos = stackPopINT(pVM->pStack);
+ fd = stackPopINT(pVM->pStack);
+ stackPushINT(pVM->pStack, lseek(fd, pos, whence));
+ return;
+}
+
/* key - get a character from stdin
*
* key ( -- char )
@@ -568,6 +623,8 @@ void ficlCompilePlatform(FICL_SYSTEM *pSys)
dictAppendWord(dp, "fread", pfread, FW_DEFAULT);
dictAppendWord(dp, "fload", pfload, FW_DEFAULT);
dictAppendWord(dp, "fkey", fkey, FW_DEFAULT);
+ dictAppendWord(dp, "fseek", pfseek, FW_DEFAULT);
+ dictAppendWord(dp, "fwrite", pfwrite, FW_DEFAULT);
dictAppendWord(dp, "key", key, FW_DEFAULT);
dictAppendWord(dp, "key?", keyQuestion, FW_DEFAULT);
dictAppendWord(dp, "ms", ms, FW_DEFAULT);
diff --git a/sys/boot/forth/loader.4th b/sys/boot/forth/loader.4th
index f4d7666..3349c1f 100644
--- a/sys/boot/forth/loader.4th
+++ b/sys/boot/forth/loader.4th
@@ -26,8 +26,8 @@
s" arch-alpha" environment? [if] [if]
s" loader_version" environment? [if]
- 11 < [if]
- .( Loader version 1.1+ required) cr
+ 12 < [if]
+ .( Loader version 1.2+ required) cr
abort
[then]
[else]
@@ -38,8 +38,8 @@ s" arch-alpha" environment? [if] [if]
s" arch-i386" environment? [if] [if]
s" loader_version" environment? [if]
- 10 < [if]
- .( Loader version 1.0+ required) cr
+ 11 < [if]
+ .( Loader version 1.1+ required) cr
abort
[then]
[else]
diff --git a/sys/boot/forth/pnp.4th b/sys/boot/forth/pnp.4th
index a9f2899..395164d 100644
--- a/sys/boot/forth/pnp.4th
+++ b/sys/boot/forth/pnp.4th
@@ -158,7 +158,7 @@ only forth also support-functions
: load-pnp
0 to end_of_file?
reset_line_reading
- s" /boot/pnpid.conf" fopen fd !
+ s" /boot/pnpid.conf" O_RDONLY fopen fd !
fd @ -1 <> if
begin
end_of_file? 0=
diff --git a/sys/boot/forth/support.4th b/sys/boot/forth/support.4th
index 7988012..d711094 100644
--- a/sys/boot/forth/support.4th
+++ b/sys/boot/forth/support.4th
@@ -80,6 +80,16 @@
8 constant before_load_error
9 constant after_load_error
+\ I/O constants
+
+0 constant SEEK_SET
+1 constant SEEK_CUR
+2 constant SEEK_END
+
+0 constant O_RDONLY
+1 constant O_WRONLY
+2 constant O_RDWR
+
\ Crude structure support
: structure:
@@ -931,23 +941,12 @@ support-functions definitions
only forth also support-functions definitions
-: create_null_terminated_string { addr len -- addr' len }
- len char+ allocate if out_of_memory throw then
- >r
- addr r@ len move
- 0 r@ len + c!
- r> len
-;
-
\ Interface to loading conf files
: load_conf ( addr len -- )
0 to end_of_file?
reset_line_reading
- create_null_terminated_string
- over >r
- fopen fd !
- r> free-memory
+ O_RDONLY fopen fd !
fd @ -1 = if open_error throw then
['] process_conf catch
fd @ fclose
diff --git a/sys/boot/i386/loader/version b/sys/boot/i386/loader/version
index 44d3b96..7a2acaf 100644
--- a/sys/boot/i386/loader/version
+++ b/sys/boot/i386/loader/version
@@ -3,6 +3,7 @@ $FreeBSD$
NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE. The format of this
file is important. Make sure the current version number is on line 6.
+1.1: New calling conventions for fopen.
1.0: New semantics for finding the kernel, new boot.
0.8: Set/getenv & cia, copyin/out.
0.7: Supports large KVM
OpenPOWER on IntegriCloud