duskos

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

commit 1dab3f145bd77d89c757ba4fbbb6b5db02b663f5
parent 4233cb64177d65225be7103509a11905b43befde
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sun,  6 Nov 2022 14:06:35 -0500

drv/pc/ata: code consolidation

Diffstat:
Mfs/drv/pc/ata.fs | 49+++++++++++++++++++++++--------------------------
Mfs/xcomp/i386/pc/init.fs | 2+-
2 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/fs/drv/pc/ata.fs b/fs/drv/pc/ata.fs @@ -6,12 +6,9 @@ extends Drive struct[ ATADrive sfield bus sfield unit $200 const SECSZ - \ TODO: get rid of those global variables - 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 + : _iobase ( drv -- port ) bus if $170 else $1f0 then ; + : _ctlbase ( drv -- port ) _iobase $206 or ; \ $3f6/$376 : _data _iobase ; : _error _iobase 1+ ; : _features _error ; @@ -28,25 +25,25 @@ extends Drive struct[ ATADrive $ec const IDENTIFY - : stat ( -- r ) _stat pc@ ; + : stat ( drv -- r ) _stat pc@ ; : :identify ( drv -- r ) >r - r@ bus to atabus r@ unit bool 4 lshift $a0 or _drvhd pc! - 0 _secno pc! 0 _cyllo pc! 0 _cylhi pc! - IDENTIFY _cmd pc! stat rdrop ; + r@ unit bool 4 lshift $a0 or r@ _drvhd pc! + 0 r@ _secno pc! 0 r@ _cyllo pc! 0 r@ _cylhi pc! + IDENTIFY r@ _cmd pc! r> stat ; - : :reset ( -- r ) $04 _devctl pc! 0 _devctl pc! stat ; + : :reset ( drv -- r ) >r $04 r@ _devctl pc! 0 r@ _devctl pc! r> stat ; - : _wait ( -- ) begin stat $80 and not until ; + : _wait ( drv -- ) begin dup stat $80 and not until drop ; - : _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! ; + : _locate ( sec drv -- ) >r + dup 24 rshift $f and $e0 or r@ unit bool 4 lshift or + r@ _drvhd pc! + 0 r@ _features pc! + 1 r@ _seccnt pc! + dup $ff and r@ _secno pc! + dup 8 rshift r@ _cyllo pc! + 16 rshift r> _cylhi pc! ; code _ ( dst port -- ) dx bp 0 d) mov, di bp 4 d) mov, bp CELLSZ << i) add, @@ -56,9 +53,9 @@ extends Drive struct[ ATADrive di inc, di inc, cx dec, ( pc ) abs>rel jnz, ret, - : ata@ ( sec dst drv -- ) dup bus to atabus unit to atadrive - swap _locate $20 ( read sectors ) _cmd pc! - _wait ( dst ) _data _ ; + : ata@ ( sec dst drv -- ) >r + swap r@ _locate $20 ( read sectors ) r@ _cmd pc! + r@ _wait ( dst ) r> _data _ ; code _ ( src port -- ) dx bp 0 d) mov, di bp 4 d) mov, bp CELLSZ << i) add, @@ -68,10 +65,10 @@ extends Drive struct[ ATADrive di inc, di inc, cx dec, ( pc ) abs>rel jnz, ret, - : ata! ( sec src drv -- ) dup bus to atabus unit to atadrive - swap _locate $30 ( write sectors ) _cmd pc! - _wait ( src ) _data _ - $e7 ( flush cache ) _cmd pc! _wait ; + : ata! ( sec src drv -- ) >r + swap r@ _locate $30 ( write sectors ) r@ _cmd pc! + r@ _wait ( src ) r@ _data _ + $e7 ( flush cache ) r@ _cmd pc! r> _wait ; : :. ( drv -- ) >r r@ bus . ':' emit r@ unit . spc> r> :identify .x1 ; diff --git a/fs/xcomp/i386/pc/init.fs b/fs/xcomp/i386/pc/init.fs @@ -22,7 +22,7 @@ f<< /sys/grid.fs f<< /drv/pc/pci.fs \ IDE boot drive f<< /drv/pc/ata.fs -ATADrive :reset drop ATA0:0 bootfs to Filesystem drv +ATA0:0 ATADrive :reset drop ATA0:0 bootfs to Filesystem drv \ AHCI boot drive \ f<< /drv/pc/ahci.fs