commit d27c3be65ff94d7382ee81f21e05142a3e89e4ad
parent 0a6dbc7a465cf432521d1702fe9b039bb64d7bae
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Wed, 20 Jul 2022 21:10:27 -0400
Bare metal on PC: first tiny step
Diffstat:
6 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
@@ -1,4 +1,5 @@
/dusk
/fatfs
/boot.fs
+/pc.bin
*.o
diff --git a/Makefile b/Makefile
@@ -20,6 +20,13 @@ fatfs: $(ALLSRCS)
mformat -M 512 -d 1 -i $@ ::
mcopy -sQ -i $@ fs/* ::
+pc.bin: dusk
+ ./dusk < buildpc.fs 2> $@
+
+.PHONY: pcrun
+pcrun: pc.bin
+ qemu-system-i386 -drive file=pc.bin,if=floppy,format=raw
+
.PHONY: run
run: dusk
stty -icanon -echo; ./dusk ; stty icanon echo
diff --git a/buildpc.fs b/buildpc.fs
@@ -0,0 +1,4 @@
+: spit ( a u -- ) >r begin c@+ stderr next ;
+f<< /xcomp/pc/mbr.fs
+
+ORG $200 spit bye
diff --git a/dusk.asm b/dusk.asm
@@ -230,6 +230,15 @@ defword '(emit)', 6, word__emit
defword 'emit', 4, word_emit
sysalias emit
+defword 'stderr', 6, word_stderr
+ mov eax, SYSCALL_WRITE
+ mov ebx, 2 ; stderr
+ mov ecx, ebp ; buffer: top of PS, little endian
+ mov edx, 1 ; len
+ int 0x80
+ pspop eax
+ ret
+
defword 'key', 3, word_key
pspush 0
mov eax, SYSCALL_READ
diff --git a/fs/asm/i386.fs b/fs/asm/i386.fs
@@ -24,6 +24,7 @@ SZ32 value opsz
0 value imm \ value of current immediate, if set
0 value disp \ displacement value
0 value sib \ value of the SIB byte
+0 value ORG \ base address for jmp, and call, rel32 computing
\ Utilities
: asm$ SZ32 to opsz 1 to opdirec 3 to opmod -1 to opreg -1 to oprm 0 to imm? ;
@@ -149,7 +150,7 @@ $840f op jz, $850f op jnz,
\ the "opreg" for the modrm version.
: op ( opcode -- ) doer , does> @ ( rel32? opcode -- )
opreg 0< if ( rel32 opcode )
- c, here - 4 - , asm$
+ c, here - ORG + 4 - , asm$
else \ ( opcode )
8 rshift opreg! $ff opmodrm,
then ;
@@ -208,3 +209,5 @@ $58 op pop, $50 op _push,
else $c7 c, 0 opreg! msd, imm, asm$ then
else $88 opmodrm, then ;
+\ INT is special
+: int, ( n -- ) $cd c, c, ;
diff --git a/fs/xcomp/pc/mbr.fs b/fs/xcomp/pc/mbr.fs
@@ -0,0 +1,10 @@
+\ x86 bootloader
+?f<< /asm/i386.fs
+
+here to ORG here $200 0 fill
+$26 jmp, \ bypass BPB
+$21 allot
+ax $0e58 i) mov,
+$10 int,
+here jmp,
+$55 ORG $1fe + c!+ $aa swap c!