duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 2f8570f3d01abf983e0f2e686db97cf54387dd6f
parent f9c41b78964717d10d7f20d8be6846f003cb7f1e
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Wed, 31 Aug 2022 16:28:28 -0400

PC self-hosting: second step

Write the MBR and kernel to reserved sectors of the FAT.

The only things left to do to get rid of "mtools" is to fix test breakage
around the ".." dir entry and to construct the root "init.fs" file from within
build.fs.

Diffstat:
Mfs/fs/fat.fs | 2+-
Mfs/xcomp/pc/build.fs | 45+++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/fs/fs/fat.fs b/fs/fs/fat.fs @@ -60,7 +60,7 @@ $e5 const DIRFREE over w! ( a ) r@ FATLO :)buf 1- = if \ end-of-sector cross-over! r@ writecursector r@ FATLO bufsec 1+ 0 r@ FATLO :readsector - r@ FATLO :)buf c@ dup .x1 nl> r@ FATLO :buf( c! then + r@ FATLO :)buf c@ r@ FATLO :buf( c! then rdrop ; : FAT16! ( entry cluster self -- ) FATLO :FAT16' w! ; : FAT! ( entry cluster self -- ) >r diff --git a/fs/xcomp/pc/build.fs b/fs/xcomp/pc/build.fs @@ -1,12 +1,53 @@ ?f<< /fs/fat.fs ?f<< /xcomp/tools.fs +." Compiling MBR" nl> +f<< /xcomp/pc/mbr.fs +here org - value mbrlen +org value mbr + +." Compiling i386 kernel" nl> +f<< /xcomp/i386.fs +f<< /xcomp/pc/kernel.fs +xbindict orgifydict +here org - value kernellen +org value kernel + : createFAT ( drv clustercnt -- fat ) + \ We need to reserve (56) enough sectors for MBR + pc.bin >r dup 16 ( rootentsec ) 56 ( rsvdsec ) 1 ( secperclus ) r> FAT newFAT12 ( drv ) FAT :mountvolume ; : copyfs ( srcfs dstfs -- ) 0 Path :new ( srcfs dstpath ) swap 0 Path :new Path :copydir ; -: buildPC ( drv clustercnt ) - createFAT bootfs swap copyfs ; +$200 const SECSZ \ TODO: get from drive +create _buf SECSZ allot0 +1 value _sec +0 value _ptr +: rsvdflush ( drv -- ) + _sec _buf rot Drive :sec! 1 to+ _sec 0 to _ptr _buf SECSZ 0 fill ; +: rsvdwrite ( c drv -- ) + swap _buf _ptr + c! 1 to+ _ptr _ptr SECSZ = if rsvdflush else drop then ; + +: spitfile ( fpath drv -- ) >r + curpath :find# Path :open begin ( fc ) + begin dup getc keepc? until + dup 0>= while r@ rsvdwrite repeat ( fc c ) + drop File :close rdrop ; + +: buildPC ( drv clustercnt ) over >r \ V1=drv + ." creating FAT and copying files" nl> + createFAT bootfs swap copyfs + ." Putting MBR in place" nl> + 0 here V1 Drive :sec@ + mbr here $3e + mbrlen move + 0 here V1 Drive :sec! + ." Putting kernel in place" nl> + kernellen >r kernel begin c@+ V1 rsvdwrite next drop + S" /xcomp/bootlo.fs" V1 spitfile + S" /drv/pc/int13h.fs" V1 spitfile + S" /fs/fatlo.fs" V1 spitfile + S" /xcomp/pc/glue.fs" V1 spitfile + S" /xcomp/boothi.fs" V1 spitfile + r> rsvdflush ;