duskos

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

commit d2b685d2db690afd81d949807bc790fa24b8d002
parent dd2a0a2157f9973b5704aa41cf7a767b1611bc3b
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Thu,  1 Sep 2022 07:17:32 -0400

Dusk is theoretically self-hosting!

mtools is not needed any more.

To be really self-hosting, I only need to actually self-host from one platform,
which will be PC under QEMU. But for this, I need to make the ATA drive support
more than one drive at once.

Diffstat:
MMakefile | 28++++++++--------------------
MREADME.md | 2--
Dbuildmbr.fs | 6------
Mbuildpc.fs | 20++++----------------
Dbuildpc2.fs | 4----
Abuildpctest.fs | 5+++++
Mfs/sys/file.fs | 3+++
Mfs/xcomp/pc/build.fs | 13++++++++++---
8 files changed, 30 insertions(+), 51 deletions(-)

diff --git a/Makefile b/Makefile @@ -12,33 +12,21 @@ posix/boot.fs: $(BOOTFS_SRC) dusk: posix/vm.c posix/boot.fs fs/init.fs $(CC) posix/vm.c -Wall -o $@ -mbr.bin: dusk buildmbr.fs $(ALLSRCS) - ./dusk < buildmbr.fs 2> $@ - -pc.bin: dusk buildpc.fs $(ALLSRCS) - ./dusk < buildpc.fs 2> $@ - -pc.img: mbr.bin pc.bin - dd if=/dev/zero of=$@ bs=1M count=1 - # We need to reserve (-R) enough sectors for MBR + pc.bin - mformat -M 512 -d 1 -R 56 -i $@ :: - dd if=mbr.bin of=$@ bs=1 seek=62 conv=notrunc - dd if=pc.bin of=$@ bs=1 seek=512 conv=notrunc - mcopy -sQ -i $@ fs/* :: - -pc2.img: dusk $(ALLSRCS) +pc.img: dusk $(ALLSRCS) dd if=/dev/zero of=$@ bs=1M count=1 - ./dusk < buildpc2.fs + ./dusk < buildpc.fs .PHONY: pcrun pcrun: pc.img - cat fs/xcomp/pc/init.fs fs/xcomp/init.fs | mcopy -D overwrite -i pc.img - ::init.fs qemu-system-i386 -drive file=pc.img,format=raw +pctest.img: dusk $(ALLSRCS) + dd if=/dev/zero of=$@ bs=1M count=1 + ./dusk < buildpctest.fs + .PHONY: testpc -testpc: pc.img - cat fs/xcomp/pc/init.fs fs/xcomp/pc/inittest.fs | mcopy -D overwrite -i pc.img - ::init.fs - qemu-system-i386 -nographic -drive file=pc.img,format=raw | tee /dev/stderr | grep "All tests passed" +testpc: pctest.img + qemu-system-i386 -nographic -drive file=pctest.img,format=raw | tee /dev/stderr | grep "All tests passed" .PHONY: run run: dusk diff --git a/README.md b/README.md @@ -217,7 +217,6 @@ its target platforms, so that's why it exists. To build this VM, you need: * GNU Make * A C compiler -* [mtools][6] Running `make` will yield a `./dusk` binary which if opened, provides an interactive prompt. @@ -256,7 +255,6 @@ BIOS" mode. [3]: https://sr.ht/~vdupras/duskos [4]: https://sr.ht/~vdupras/duskos/lists [5]: https://lists.sr.ht/~vdupras/duskos-discuss/%3C87czew8rir.fsf%40valley.vpn%3E -[6]: https://www.gnu.org/software/mtools/ [7]: https://lists.sr.ht/~vdupras/duskos-discuss/%3C1a6b5f15-a54a-4f28-8b7c-a9da2009a4c5%40www.fastmail.com%3E [8]: https://git.sr.ht/~vdupras/duskos/tree/master/item/fs/tests/cc/test.c [9]: https://git.sr.ht/~vdupras/duskos/tree/master/item/fs/doc/cc.txt diff --git a/buildmbr.fs b/buildmbr.fs @@ -1,6 +0,0 @@ -: spit ( a u -- ) >r begin c@+ stderr next ; -1 to fecho -f<< /xcomp/pc/mbr.fs -org here org - spit -bye - diff --git a/buildpc.fs b/buildpc.fs @@ -1,17 +1,5 @@ -?f<< /xcomp/tools.fs -: spit ( a u -- ) >r begin c@+ stderr next ; -: spitfile<< - word curpath :find# Path :open begin ( fc ) - begin dup getc keepc? until - dup 0>= while stderr repeat ( fc c ) drop File :close ; -1 to fecho -f<< /xcomp/i386.fs -f<< /xcomp/pc/kernel.fs -xbindict orgifydict -org here org - spit -spitfile<< /xcomp/bootlo.fs -spitfile<< /drv/pc/int13h.fs -spitfile<< /fs/fatlo.fs -spitfile<< /xcomp/pc/glue.fs -spitfile<< /xcomp/boothi.fs +f<< /xcomp/pc/build.fs + +S" pc.img" mountImage ( drv ) 1938 buildPC +S" /xcomp/pc/init.fs" S" /xcomp/init.fs" rot combineInit bye diff --git a/buildpc2.fs b/buildpc2.fs @@ -1,4 +0,0 @@ -f<< /xcomp/pc/build.fs - -S" pc2.img" mountImage ( drv ) 1938 buildPC -bye diff --git a/buildpctest.fs b/buildpctest.fs @@ -0,0 +1,5 @@ +f<< /xcomp/pc/build.fs + +S" pctest.img" mountImage ( drv ) 1938 buildPC +S" /xcomp/pc/init.fs" S" /xcomp/pc/inittest.fs" rot combineInit +bye diff --git a/fs/sys/file.fs b/fs/sys/file.fs @@ -80,6 +80,9 @@ struct[ Path r> File :close r> File :close ; : :copyfile ( dst self -- ) \ arguments are paths :open >r :open r> _copyfile ; + : :appendfile ( src self -- ) + :open dup File size over File :seek swap :open _copyfile ; + \ dst is the *parent* of where the source element will be 0 value _dstfs diff --git a/fs/xcomp/pc/build.fs b/fs/xcomp/pc/build.fs @@ -36,9 +36,16 @@ create _buf SECSZ allot0 dup 0>= while r@ rsvdwrite repeat ( fc c ) drop File :close rdrop ; -: buildPC ( drv clustercnt ) over >r \ V1=drv +: combineInit ( fname1 fname2 fat -- ) >r swap >r >r \ V1=fat V2=f1 V3=f2 + S" /init.fs" V1 0 Path :new Path :find# + V2 bootfs 0 Path :new Path :find# Path :copyfile + V3 bootfs 0 Path :new Path :find# + S" /init.fs" V1 0 Path :new Path :find# Path :appendfile + rdrop rdrop rdrop ; + +: buildPC ( drv clustercnt -- fat ) over >r \ V1=drv ." creating FAT and copying files" nl> - createFAT bootfs swap copyfs + createFAT dup >r bootfs swap copyfs \ V2=fat ." Putting MBR in place" nl> 0 here V1 Drive :sec@ mbr here $3e + mbrlen move @@ -50,4 +57,4 @@ create _buf SECSZ allot0 S" /fs/fatlo.fs" V1 spitfile S" /xcomp/pc/glue.fs" V1 spitfile S" /xcomp/boothi.fs" V1 spitfile - r> rsvdflush ; + V1 rsvdflush r> rdrop ;