commit 41843e3beb031e7da86f400a2d961f18eee2c1cf
parent e078faf0039f9fdcb54093bab93ea797e1160fb0
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Mon, 8 Aug 2022 19:04:04 -0400
pc: straigten out memory layout
Also, make the ATA driver activate itself if the identify command works.
Otherwise, stay on INT13h.
Diffstat:
6 files changed, 29 insertions(+), 29 deletions(-)
diff --git a/fs/doc/x86.txt b/fs/doc/x86.txt
@@ -32,3 +32,20 @@ Here is a schema of a 8 bytes stack frame in C
^ ^
|-----------------|
Stack frame
+
+## Memory layout
+
+RS and PS live at the end of x86 conventional memory, that is $80000.
+
+The bootloader is loaded at $7c00, and it then loads the kernel along with its
+boot code, which are about $6000 bytes long. We load them at address $500, which
+is the beginning of conventional memory. Then, we jump to the kernel which makes
+"here" start at $8000. From there, the boot code begins interpreting itself.
+
+We have to make sure that initial filesystem buffers are all under $10000 so
+that INT13h can access it without problem (we don't play with segments in the
+int13h routine, so we're limited to 64K).
+
+During higher level initialization, we're expected to deal with the A20 gate,
+stop needing int13h, and then make "here" jump to its final playground, that is
+$100000 and above.
diff --git a/fs/drv/pc/idt.fs b/fs/drv/pc/idt.fs
@@ -1,11 +0,0 @@
-\ Interrupt Descriptor Table
-
-?f<< /asm/i386.fs
-
-create IDT $800 allot0
-
-create IDTR $7ff w, IDT ,
-
-\ Only call this when you don't need the BIOS any more
-code idt$ IDTR m) lidt, ret,
-
diff --git a/fs/xcomp/i386.fs b/fs/xcomp/i386.fs
@@ -28,11 +28,12 @@
lblnextmeta lblret lblcurrent lblemit lblparsec lblparseh lblparseud
lblerrmsg lblrtype lblhere lblmovewrite lblwrite lblcwrite
lblcompiling lblareg lblidt
-$a000 const HERESTART \ TODO: find a better place
-$80000 const HEREMAX
-$8000 to binstart \ This code lives at $8000.
-$6000 const RSTOP
-$7c00 const PSTOP
+$8000 const HERESTART \ TODO: find a better place
+$500 to binstart
+$2000 const STACKSZ
+$80000 const RSTOP
+RSTOP STACKSZ - const PSTOP
+PSTOP STACKSZ - const HEREMAX
\ Let's go!
align4 here to org
@@ -133,7 +134,7 @@ xcode heremax
ret,
xcode here
- wcall, (val) pc to lblhere $500 ,
+ wcall, (val) pc to lblhere HERESTART ,
xcode current
wcall, (val) pc to lblcurrent 0 ,
diff --git a/fs/xcomp/pc/init.fs b/fs/xcomp/pc/init.fs
@@ -1,6 +1,5 @@
\ Initialization for PC
: ARCH S" i386" ;
-herestart to here
0 S" sys" fchild S" file.fs" fchild fload
\ We now have f<<
f<< /drv/pc/acpi.fs
@@ -10,13 +9,7 @@ f<< /sys/grid.fs
' (emit) to emit
f<< /drv/pc/ata.fs
-\ TODO: fix timing issues in ATA driver. Uncommenting this line below works
-\ under QEMU, but not on real hardware.
-\ Update: hum no, it seems that my notebook doesn't list anything at all on its
-\ IDE buses. Maybe I'll have to go straight to AHCI...
-\ ATADrive to fatdrv
-
-f<< /drv/pc/idt.fs
+ataidentify $c0 and $40 = [if] atareset drop ATADrive to fatdrv [then]
f<< /drv/pc/pci.fs
f<< /drv/pc/ps28042.fs
diff --git a/fs/xcomp/pc/mbr.fs b/fs/xcomp/pc/mbr.fs
@@ -33,7 +33,7 @@ pc to lblpayload 0 to realmode
ax $10 i) mov, ds ax mov, ss ax mov, es ax mov, gs ax mov, fs ax mov,
sti,
\ Jump to payload
- $08 $8000 jmpfar,
+ $08 $500 jmpfar,
1 to realmode
lblstart forward!
cld, ax ax xor, es ax mov, ds ax mov,
@@ -42,9 +42,9 @@ lblgdt m) lgdt,
\ BS_DrvNum is often not set properly, so let's set it.
$7c24 m) dl mov,
\ read BPB_RsvdSecCnt-1 sectors, starting from sector 2 from boot floppy in
-\ memory at address $8000. DL is set by BIOS.
+\ memory at address $500 DL is set by BIOS.
ah 2 i) mov, al $7c0e ( BPB_RsvdSecCnt ) m) mov, al dec,
-bx $8000 i) mov, cx $0002 i) mov, dh 0 i) mov, $13 int,
+bx $500 i) mov, cx $0002 i) mov, dh 0 i) mov, $13 int,
lblerror abs>rel jc,
ax $0003 i) mov, $10 int, \ video mode 80x25
cli, ax cr0 mov, ax 1 i) or, cr0 ax mov,
diff --git a/fs/xcomp/tools.fs b/fs/xcomp/tools.fs
@@ -21,5 +21,5 @@ newxdict xbindict
@ begin ( a )
5 - dup @ ( 'prev prev )
?dup while ( 'prev prev )
- dup xoffset + ( 'prev oldprev newprev ) rot ! ( prev ) repeat 2drop ;
+ dup xoffset + ( 'prev oldprev newprev ) rot ! ( prev ) repeat drop ;