~vdupras/duskos

6a091fb48d5b9e58f35c15536d4eaae564cd6fb9 — Virgil Dupras 15 days ago f440785
Make bootfs into a structbind
M fs/doc/arch.txt => fs/doc/arch.txt +4 -4
@@ 138,10 138,10 @@ For now, Dusk can only boot from a FAT12 volume. To do so, it needs the "fatlo"
code, a read-only subset of its FAT implementation, to be embedded in the boot
code. This piece of code lives in fs/fatlo.fs

The glue file plugs the Filesystem structure into the "bootfs" pointer.  It also
has the responsibility of adding references to embedded files in "floaded" so
that they aren't loaded twice in memory. In the PC target, this is sourced from
xcomp/pc/glue.fs
The glue file creates a "bootfs" structbind from the Filesystem structure. It
also has the responsibility of adding references to embedded files in "floaded"
so that they aren't loaded twice in memory. In the PC target, this is sourced
from xcomp/pc/glue.fs

The "boothi" part does very little: it loads /sys/file.fs and then /init.fs, and
then calls init. It ends with a failsafe to ensure that an interactive interpret

M fs/doc/deploy.txt => fs/doc/deploy.txt +2 -2
@@ 87,8 87,8 @@ other sectors too? Well, that sounds good, it looks like you can plug fatlo in.

For this, I recommend looking at how the PC platform does it. It should look the
same for all targets: we stream bootlo in, then the storage driver, then fatlo,
then the "glue" file, which create an instance of Filesystem and place it in the
"bootfs" value.
then the "glue" file, which create an instance of Filesystem as well as a
"bootfs" structbind to it.

If you look at PC's glue.fs, you'll also see something about "floaded," the goal
of that is to "register" files in the boot stream as "loaded" so that "?f<<"

M fs/doc/lib/file.txt => fs/doc/lib/file.txt +6 -4
@@ 15,16 15,18 @@ capabilities to a memory buffer. It extends File with those words:
## DriveFile

DriveFile is a structure allowing direct access to a Drive through the
convenience of a File API. It's buffer size is the drive's sector size.
convenience of a File API. Its buffer size is the drive's sector size. It lives
on top of a SectorWindow (lib/drive) and by defaults targets the whole drive,
although the :move word can be used to reduce the scope of the file.

Fields:

drv    The Drive being interfaced.
sec    Sector number currently in buffer, -1 if none.
dirty? Whether the buffer has changed since it was loaded from the drive.
secwin The target SectorWindow.

Words:

:new ( drv -- hdl )
  Create a new DriveFile interfacing Drive "drv".

:move ( fsec cnt self -- )
  Calls secwin's :move and seek pos 0.

M fs/doc/sys/file.txt => fs/doc/sys/file.txt +1 -1
@@ 168,7 168,7 @@ on to a Path reference a little longer, you should copy it elsewhere.

The File subsystem has 2 important global variables:

bootfs is a pointer to the Filesystem structure from which the system was
bootfs is a structbind to the Filesystem structure from which the system was
booted. It's used only until the File subsystem is initialized.

curpath is a Path bind that points to the "current directory". It is initialized

M fs/lib/file.fs => fs/lib/file.fs +1 -0
@@ 19,6 19,7 @@ extends File struct[ MemFile
extends File struct[ DriveFile
  sfield secwin
  : :secwin [compile] secwin [compile] SectorWindow ; immediate
  : :move dup :secwin :move 0 :seek ;
  : flush :secwin :flush ;
  : seek ( pos self -- ) to pos ;
  : readbuf ( n self -- a? read-n )

M fs/sys/file.fs => fs/sys/file.fs +3 -4
@@ 1,5 1,4 @@
0 S" sys" bootfs Filesystem :child S" io.fs" bootfs Filesystem :child
  bootfs swap fload
bootfs :self 0 S" sys" bootfs :child S" io.fs" bootfs :child fload

struct[ FSInfo
  sfield name


@@ 9,7 8,7 @@ struct[ FSInfo

26 const MAXFSCNT
create filesystems MAXFSCNT CELLSZ * allot0
bootfs filesystems ! \ record our boot FS in the list
bootfs :self filesystems ! \ record our boot FS in the list

struct+[ Filesystem
  : :?newfile ( dirid name fs -- id )


@@ 22,7 21,7 @@ struct[ Path
  sfield fs
  sfield id

  create _curpath bootfs , 0 ,
  create _curpath bootfs :self , 0 ,

  $400 const BUFSZ
  create _paths BUFSZ SZ * allot

M fs/xcomp/boothi.fs => fs/xcomp/boothi.fs +3 -5
@@ 1,5 1,3 @@
0 S" sys" bootfs Filesystem :child S" file.fs" bootfs Filesystem :child
  bootfs swap fload
0 S" init.fs" bootfs Filesystem :child bootfs swap fload
init
." Still on BootIn after init? shutting down." bye
bootfs :self 0 S" sys" bootfs :child S" file.fs" bootfs :child fload
bootfs :self 0 S" init.fs" bootfs :child fload
init ." Booting error" bye

M fs/xcomp/bootlo.fs => fs/xcomp/bootlo.fs +0 -3
@@ 450,9 450,6 @@ struct[ Filesystem
    '" child" , '" info" , '" open" , '" iter" ,
    '" newfile" , '" newdir" , '" remove" , ;
]struct
\ bootfs holds a reference to boot FS. This is used until the full sys/file
\ subsystem takes over with Path mechanics.
0 value bootfs
extends IO struct[ File
  sfield pos
  sfield size

M fs/xcomp/i386/pc/build.fs => fs/xcomp/i386/pc/build.fs +3 -3
@@ 34,7 34,7 @@ org value kernel

: setupFAT ( drv clustercnt -- fat )
  ." creating FAT and copying files\n"
  createFAT bootfs over copyfs ;
  createFAT bootfs :self over copyfs ;

: spitfile ( fpath dst -- ) >r
  curpath :find# Path :open begin ( fc )


@@ 44,8 44,8 @@ org value kernel

: combineInit ( fname1 fname2 fat -- ) >r swap >r >r \ V1=fat V2=f1 V3=f2
  0 S" init.fs" V1 Filesystem :?newfile V1 swap Path :new
  V2 bootfs 0 Path :new Path :find# Path :copyfile
  V3 bootfs 0 Path :new Path :find#
  V2 bootfs :self 0 Path :new Path :find# Path :copyfile
  V3 bootfs :self 0 Path :new Path :find#
  S" /init.fs" V1 0 Path :new Path :find# Path :appendfile
  2rdrop rdrop ;


M fs/xcomp/i386/pc/glue.fs => fs/xcomp/i386/pc/glue.fs +5 -6
@@ 1,7 1,6 @@
\ Glue code that goes between the filesystem part and boothi
INT13hDrive FAT :mountvolume ( fs ) to bootfs
0 S" drv" bootfs Filesystem :child S" pc" bootfs Filesystem :child
  S" int13h.fs" bootfs Filesystem :child floaded,
0 S" lib" bootfs Filesystem :child
  S" drivelo.fs" bootfs Filesystem :child floaded,
0 S" fs" bootfs Filesystem :child S" fatlo.fs" bootfs Filesystem :child floaded,
INT13hDrive FAT :mountvolume ( fs ) structbind FAT bootfs
0 S" drv" bootfs :child S" pc" bootfs :child
  S" int13h.fs" bootfs :child floaded,
0 S" lib" bootfs :child S" drivelo.fs" bootfs :child floaded,
0 S" fs" bootfs :child S" fatlo.fs" bootfs :child floaded,

M fs/xcomp/i386/pc/init.fs => fs/xcomp/i386/pc/init.fs +4 -4
@@ 14,16 14,16 @@ grid :self dup to console writeio to stdio writeio
\ Floppy boot drive
\ f<< /drv/pc/fdc.fs
\ floppy :init
\ floppy :self bootfs to Filesystem drv
\ floppy :self to bootfs drv

f<< /drv/pc/pci.fs
\ IDE boot drive
f<< /drv/pc/ata.fs
ATA0:0 ATADrive :reset drop ATA0:0 bootfs to Filesystem drv
ATA0:0 ATADrive :reset drop ATA0:0 to bootfs drv

\ AHCI boot drive
\ f<< /drv/pc/ahci.fs
\ 0 AHCIDrive :new dup bootfs to Filesystem drv ( drv )
\ 0 AHCIDrive :new dup to bootfs drv ( drv )
\ AHCIDrive :enable

\ Now that int13h won't be used anymore, it's safe to configure the PIC


@@ 31,7 31,7 @@ f<< /drv/pc/pic.fs
pic$ idt$

f<< /fs/fat.fs
bootfs FAT :patchlo
bootfs :patchlo

f<< /sys/kbd.fs
f<< /sys/mouse.fs

M posix/glue.fs => posix/glue.fs +1 -1
@@ 9,7 9,7 @@ extends Filesystem struct[ POSIXFS
  alias abort remove
  : :new 0 Filesystem :new S[ :[methods] ]S c@+ -move, ;
]struct
POSIXFS :new to bootfs
POSIXFS :new structbind POSIXFS bootfs

: mountImage ( imgname -- drv )
  _mountdrv here 512 , -1 , ['] _drv@ , ['] _drv! , ;