commit 8cab7ec3b72497e144a588f78d0fa4c58d6f30c2
parent e929f00de69abdf0816002ed6ee49836a872e33c
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Wed, 22 Feb 2023 21:58:18 -0500
xcomp/i386/pc/build: break build process into smaller pieces
This allows ad-hoc usage of individual parts of that build process. One example
use I need is, on my work laptop, spit the kernel+bootcode to the "alternate"
location (cylinder 1, activated in the MBR). It was very difficult to do before.
Diffstat:
2 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/buildpc.fs b/buildpc.fs
@@ -1,5 +1,8 @@
f<< /xcomp/i386/pc/build.fs
-S" pc.img" mountImage ( drv ) 2796 buildPC
-S" /xcomp/i386/pc/init.fs" S" /xcomp/init.fs" rot combineInit
+S" pc.img" mountImage ( drv ) value mydrv
+mydrv 2796 setupFAT value myfat
+mydrv setupMBR
+mydrv DriveFile :new $200 over File :seek spitBoot
+S" /xcomp/i386/pc/init.fs" S" /xcomp/init.fs" myfat combineInit
bye
diff --git a/fs/xcomp/i386/pc/build.fs b/fs/xcomp/i386/pc/build.fs
@@ -32,19 +32,14 @@ org value kernel
: copyfs ( srcfs dstfs -- ) 0 Path :new swap 0 Path :new Path :copydir ;
-$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 ;
+: setupFAT ( drv clustercnt -- fat )
+ ." creating FAT and copying files\n"
+ createFAT bootfs over copyfs ;
-: spitfile ( fpath drv -- ) >r
+: spitfile ( fpath dst -- ) >r
curpath :find# Path :open begin ( fc )
begin dup IO :getc keepc? until
- dup 0>= while r@ rsvdwrite repeat ( fc c )
+ dup 0>= while r@ IO :putc repeat ( fc c )
drop File :close rdrop ;
: combineInit ( fname1 fname2 fat -- ) >r swap >r >r \ V1=fat V2=f1 V3=f2
@@ -54,18 +49,18 @@ create _buf SECSZ allot0
S" /init.fs" V1 0 Path :new Path :find# Path :appendfile
2rdrop rdrop ;
-: buildPC ( drv clustercnt -- fat ) over >r \ V1=drv
- ." creating FAT and copying files" nl>
- createFAT dup >r bootfs swap copyfs \ V2=fat
- ." Putting MBR in place" nl>
- 0 here V1 Drive :sec@
+: setupMBR ( drv -- )
+ ." Putting MBR in place\n"
+ >r 0 here r@ Drive :sec@
mbr here $3e + mbrlen move
- 0 here V1 Drive :sec!
- ." Putting kernel in place" nl>
- kernel kernellen for c@+ V1 rsvdwrite next drop
+ 0 here r> Drive :sec! ;
+
+: spitBoot ( iohdl -- ) >r \ V1=iohdl
+ ." Putting kernel in place\n"
+ kernel kernellen V1 IO :write
S" /xcomp/bootlo.fs" V1 spitfile
S" /drv/pc/int13h.fs" V1 spitfile
S" /fs/fatlo.fs" V1 spitfile
S" /xcomp/i386/pc/glue.fs" V1 spitfile
S" /xcomp/boothi.fs" V1 spitfile
- V1 rsvdflush r> rdrop ;
+ r> IO :flush ;