~vdupras/duskos

92deb8bb98e88adf900387837561c18684d5dd53 — Virgil Dupras a month ago 2e0d6f7
Move boot.fs to fs/ and split it in three

First, the "low" part of the boot, then, the filesystem implementation, and
then the "high" part of the boot, which implements f<< from fopen and fread and
then interprets init.fs.
5 files changed, 29 insertions(+), 24 deletions(-)

M .gitignore
M Makefile
A fs/fs/linux.fs
A fs/xcomp/boothi.fs
R boot.fs => fs/xcomp/bootlo.fs
M .gitignore => .gitignore +1 -0
@@ 1,3 1,4 @@
/dusk
/fatfs
/boot.fs
*.o

M Makefile => Makefile +4 -0
@@ 1,10 1,14 @@
TARGETS = dusk
BOOTFS_SRC = fs/xcomp/bootlo.fs fs/fs/linux.fs fs/xcomp/boothi.fs
all: $(TARGETS)

dusk: dusk.asm boot.fs fatfs
	nasm -f elf32 dusk.asm -o dusk.o
	ld -m elf_i386 dusk.o -o $@

boot.fs: $(BOOTFS_SRC)
	cat $(BOOTFS_SRC) > $@

fatfs: fs
	dd if=/dev/zero of=$@ bs=4M count=1
	mformat -d 1 -i $@ ::

A fs/fs/linux.fs => fs/fs/linux.fs +10 -0
@@ 0,0 1,10 @@
\ Filesystem implemented as Linux system calls
\ Requires a "lnxcall" word in the kernel

: fclose ( fd -- ) 6 ( close ) swap 0 0 ( close fd 0 0 ) lnxcall drop ;
create _ 'C' c, 'a' c, 'n' c, ''' c, 't' c, $20 c, 'o' c, 'p' c, 'e' c, 'n' c,
: zfopen ( zfname -- fd )
  5 ( open ) swap 0 0 ( open cstr noflag O_RDONLY ) lnxcall
  dup 0< if _ 10 rtype abort then ;
create _ 1 allot
: fread ( fd -- c-or-0 ) 3 ( read ) swap _ 1 lnxcall 1 = if _ c@ else 0 then ;

A fs/xcomp/boothi.fs => fs/xcomp/boothi.fs +14 -0
@@ 0,0 1,14 @@
0 value curfd \ file descriptor of the file currently being read
0 value floaded \ address of the current "loaded file" structure
0 value fecho
: f< ( -- c ) curfd fread fecho if dup emit then ;
: fload ( fname -- )
  floaded here to floaded , ( fname )
  dup c@ 1+ move, 0 c, ( )
  curfd >r
  floaded 5 + zfopen to curfd
  to' in< @ >r ['] f< to in<
  begin maybeword ?dup if runword 0 else 1 then until
  r> to in< curfd fclose r> to curfd ;
: f<< word fload ;
f<< init.fs

R boot.fs => fs/xcomp/bootlo.fs +0 -24
@@ 104,27 104,3 @@ alias else endof immediate

\ doc comment placeholder
alias \ \\

\ File I/O
: fclose ( fd -- ) 6 ( close ) swap 0 0 ( close fd 0 0 ) lnxcall drop ;
create _ 'C' c, 'a' c, 'n' c, ''' c, 't' c, $20 c, 'o' c, 'p' c, 'e' c, 'n' c,
: zfopen ( zfname -- fd )
  5 ( open ) swap 0 0 ( open cstr noflag O_RDONLY ) lnxcall
  dup 0< if _ 10 rtype abort then ;
create _ 1 allot
: fread ( fd -- c-or-0 ) 3 ( read ) swap _ 1 lnxcall 1 = if _ c@ else 0 then ;

0 value curfd \ file descriptor of the file currently being read
0 value floaded \ address of the current "loaded file" structure
0 value fecho
: f< ( -- c ) curfd fread fecho if dup emit then ;
: fload ( fname -- )
  floaded here to floaded , ( fname )
  dup c@ 1+ move, 0 c, ( )
  curfd >r
  floaded 5 + zfopen to curfd
  to' in< @ >r ['] f< to in<
  begin maybeword ?dup if runword 0 else 1 then until
  r> to in< curfd fclose r> to curfd ;
: f<< word fload ;
f<< init.fs