duskos

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

commit 7bddfd4116ab4d4d15fc237b0ab24d72368d1b4d
parent f8d6d50226d7f379939f9b4a0e34dc7886414efd
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Tue, 27 Jun 2023 14:34:15 -0400

lib/endian: add alignment guarantees and drop the High HAL

see doc/lib/endian.

Diffstat:
Mfs/doc/lib/endian.txt | 7++++++-
Mfs/fs/fat.fs | 9++++-----
Mfs/lib/endian.fs | 48+++++++++++++++---------------------------------
3 files changed, 25 insertions(+), 39 deletions(-)

diff --git a/fs/doc/lib/endian.txt b/fs/doc/lib/endian.txt @@ -23,4 +23,9 @@ be! n a -- Big-endian store Each of these words have a 16-bit variant, so they can be called with a "16b" modulator. They don't have a "8b" one because it makes no sense. -These words are implemented in HAL, so they're fast. +Additionally, these words can ignore alignment discipline because they are +guaranteed to read and write byte by byte. + +The tradeoff is that these words are much slower than their native counterpart. +This unit can't use the High HAL because it's a dependencies to assemblers, +which themselves are dependencies to the High HAL. diff --git a/fs/fs/fat.fs b/fs/fs/fat.fs @@ -22,6 +22,7 @@ ?f<< /fs/fatlo.fs ?f<< /lib/fmt.fs ?f<< /lib/str.fs +?f<< /lib/endian.fs extends FSInfo struct[ FATInfo DirEntry NAMESZ 2 + const BUFSZ \ 1 for the '.' and 1 for len @@ -166,22 +167,20 @@ create _FATTemplate ( BootSig ) $29 c, ( VolID ) 0 , ( VolLabel ) ," NONAME " ( FilSysType ) ," FAT12 " -: lew! ( n a -- ) \ w! that can write on odd addresses w/ alignment discipline - over 8 rshift over 1+ c! c! ; : newFAT12 ( drv -- ) fatopts clustercnt 341 / 1+ >r \ V1=fatseccnt ( drv ) dup Drive secsz >r ( drv ) \ V2=secsz here# V2 0 fill _FATTemplate here $3e move ( drv ) - V2 here $0b + lew! + V2 here $0b + 16b le! fatopts secpertrk here $18 + w! fatopts numheads here $1a + w! fatopts drvnum here $24 + c! fatopts secperclus here $0d + c! fatopts rsvdsec here $0e + w! - fatopts rootentsec DirEntry SZ * here $11 + lew! + fatopts rootentsec DirEntry SZ * here $11 + 16b le! fatopts clustercnt fatopts secperclus * fatopts rootentsec + - fatopts rsvdsec + V1 + dup here $13 + lew! + fatopts rsvdsec + V1 + dup here $13 + 16b le! ." TotSec " . nl> V1 here $16 + w! $aa55 here $1fe + w! diff --git a/fs/lib/endian.fs b/fs/lib/endian.fs @@ -1,36 +1,18 @@ \ Endian-ness convenience words -?f<< /asm/hal.fs +\ We cannot use the High HAL because assemblers depend on this unit. -$1234 here ! here c@ $34 = const LITTLE_ENDIAN? +: le@ >r 8b to@+ V1 8b to@+ V1 8 lshift or + 8b to@+ V1 16 lshift or 8b to@+ V1 24 lshift or rdrop ; +:16b >r 8b to@+ V1 8b to@+ V1 8 lshift or rdrop ; +: le! >r dup 8b to!+ V1 8 rshift dup 8b to!+ V1 8 rshift + dup 8b to!+ V1 8 rshift 8b to!+ V1 rdrop ; +:16b >r dup 8b to!+ V1 8 rshift 8b to!+ V1 rdrop ; +: le, here le! 4 allot ; :16b here 16b le! 2 allot ; -alias @ le@ :16b 16b @ ; -alias ! le! :16b 16b ! ; -alias , le, :16b 16b , ; -LITTLE_ENDIAN? not [if] abort" TODO" [then] - -alias @ be@ :16b 16b @ ; -alias ! be! :16b 16b ! ; -alias , be, :16b 16b , ; -LITTLE_ENDIAN? [if] - code be@ ( a -- n ) - W>A, A) 8b) @, 8 i) <<, - A) 1 +) 8b) |, 8 i) <<, - A) 2 +) 8b) |, 8 i) <<, - A) 3 +) 8b) |, exit, - - code16b - W>A, A) 8b) @, 8 i) <<, - A) 1 +) 8b) |, exit, - - code be! ( n a -- ) - W>A, drop, A) 3 +) 8b) !, 8 i) >>, - A) 2 +) 8b) !, 8 i) >>, - A) 1 +) 8b) !, 8 i) >>, - A) 8b) !, drop, exit, - - code16b - W>A, drop, A) 1 +) 8b) !, 8 i) >>, - A) 8b) !, drop, exit, - - : be, here be! 4 allot ; :16b here 16b be! 2 allot ; -[then] +: be@ >r 8b to@+ V1 24 lshift 8b to@+ V1 16 lshift or + 8b to@+ V1 8 lshift or 8b to@+ V1 or rdrop ; +:16b >r 8b to@+ V1 8 lshift 8b to@+ V1 or rdrop ; +: be! >r dup 24 rshift 8b to!+ V1 dup 16 rshift 8b to!+ V1 + dup 8 rshift 8b to!+ V1 8b to!+ V1 rdrop ; +:16b >r dup 8 rshift 8b to!+ V1 8b to!+ V1 rdrop ; +: be, here be! 4 allot ; :16b here 16b be! 2 allot ;