commit 74947562bdc46b172250b147f82139a5970ff895
parent f67f057eeea25606bccba15e9caf211dcf6e4a6c
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sat, 30 Jul 2022 15:27:39 -0400
drv/pc/ata: first steps
Diffstat:
8 files changed, 82 insertions(+), 6 deletions(-)
diff --git a/dusk.asm b/dusk.asm
@@ -507,6 +507,13 @@ defword 'xor', 3, word_xor
xor [ebp], eax
ret
+defword 'bool', 4, word_bool
+ mov eax, [ebp]
+ mov dword [ebp], 0
+ test eax, eax
+ setnz byte [ebp]
+ ret
+
defword 'not', 3, word_not
mov eax, [ebp]
mov dword [ebp], 0
diff --git a/fs/drv/pc/ata.fs b/fs/drv/pc/ata.fs
@@ -0,0 +1,54 @@
+\ ATA driver
+?f<< /lib/nfmt.fs
+
+$200 const ATASECSZ
+0 value atabus \ 0=primary 1=secondary
+0 value atadrive \ 0=master 1=slave
+
+: _iobase ( -- ) atabus if $170 else $1f0 then ;
+: _ctlbase ( -- ) _iobase $206 or ; \ $3f6/$376
+: _data _iobase ;
+: _error _iobase 1+ ;
+: _features _error ;
+: _seccnt _iobase 2 + ;
+: _secno _iobase 3 + ;
+: _cyllo _iobase 4 + ;
+: _cylhi _iobase 5 + ;
+: _drvhd _iobase 6 + ;
+: _stat _iobase 7 + ;
+: _cmd _stat ;
+: _altreg _ctlbase ;
+: _devctl _ctlbase ;
+: _drvaddr _ctlbase 1+ ;
+
+$ec const IDENTIFY
+
+: atastat ( -- r ) _stat pc@ ;
+
+: ataidentify ( -- r )
+ atadrive bool 4 lshift $a0 or _drvhd pc!
+ 0 _secno pc! 0 _cyllo pc! 0 _cylhi pc!
+ IDENTIFY _cmd pc! atastat ;
+
+: atareset ( -- r ) $04 _devctl pc! 0 _devctl pc! atastat ;
+
+: _wait ( -- ) begin atastat $80 and not until ;
+
+: _locate ( sec -- )
+ dup 24 rshift $f and $e0 or atadrive bool 4 lshift or _drvhd pc!
+ 0 _features pc!
+ 1 _seccnt pc!
+ dup $ff and _secno pc!
+ dup 8 rshift _cyllo pc!
+ 16 rshift _cylhi pc! ;
+
+: ata@ ( sec dst -- )
+ swap _locate $20 ( read sectors ) _cmd pc! _wait ( dst )
+ A>r ( dst ) >A $100 >r begin _data pw@ A> w! A+ A+ next r>A ;
+
+: .ata ( -- ) atabus . ':' emit atadrive . spc> ataidentify .x1 ;
+: .ataall ( -- )
+ atadrive atabus
+ 0 to atabus 0 to atadrive .ata nl> 1 to atadrive .ata nl>
+ 1 to atabus 0 to atadrive .ata nl> 1 to atadrive .ata nl>
+ to atabus to atadrive ;
diff --git a/fs/sys/drive.fs b/fs/sys/drive.fs
@@ -23,8 +23,7 @@ DRVBUFSZ >> value drvblksz
\ Block number currently in drvbuf(
-1 value drvcurblk
-( blkno buf -- )
-alias abort (drv@)
+\ (drv@) is declared in /xcomp/bootlo
( blkno buf -- )
alias abort (drv!)
diff --git a/fs/xcomp/bootlo.fs b/fs/xcomp/bootlo.fs
@@ -99,6 +99,11 @@ alias else endof immediate
\ Return whether strings s1 and s2 are equal
: s= ( s1 s2 -- f ) over c@ 1+ []= ;
+\ These aliases belong to /sys/drive, but we need them earlier in the boot
+\ process, so we anticipate.
+$200 value drvblksz
+alias abort (drv@)
+
\ Autoloading
0 value floaded \ address of the current "loaded file" structure
: floaded, ( id -- ) floaded here to floaded , ( id ) , ;
diff --git a/fs/xcomp/i386.fs b/fs/xcomp/i386.fs
@@ -313,6 +313,13 @@ xcode xor
[ebp] ax xor,
ret,
+xcode bool
+ ax [ebp] mov,
+ [ebp] 0 i) mov,
+ ax ax test,
+ [ebp] setnz,
+ ret,
+
xcode not
ax [ebp] mov,
[ebp] 0 i) mov,
diff --git a/fs/xcomp/pc/glue1.fs b/fs/xcomp/pc/glue1.fs
@@ -1,2 +1 @@
-BIOSSECSZ const drvblksz
-alias biossec@ (drv@)
+' biossec@ to (drv@)
diff --git a/fs/xcomp/pc/init.fs b/fs/xcomp/pc/init.fs
@@ -9,6 +9,11 @@ f<< /drv/pc/vga.fs
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.
+\ ' ata@ to (drv@)
+
f<< /drv/pc/idt.fs
f<< /drv/pc/pci.fs
diff --git a/posix/glue1.fs b/posix/glue1.fs
@@ -1,4 +1,4 @@
\ Glue code between the storage driver and the FS handler
fatfs( to ramdrv(
-RAMDRVSECSZ const drvblksz
-alias ramdrv@ (drv@)
+RAMDRVSECSZ to drvblksz
+' ramdrv@ to (drv@)