duskos

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

commit 480b36119bf0270c844dde205202932e439ef388
parent 7bddfd4116ab4d4d15fc237b0ab24d72368d1b4d
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Tue, 27 Jun 2023 14:48:53 -0400

asm/i386: use lib/endian

This way, we can cross-compile i386 from a big endian machine (theoretically
for now...)

Diffstat:
Mfs/asm/i386.fs | 12++++++------
Mfs/xcomp/i386/kernel.fs | 25+++++++++++++------------
Mfs/xcomp/i386/pc/kernel.fs | 2+-
Mfs/xcomp/i386/pc/mbr.fs | 10+++++-----
4 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/fs/asm/i386.fs b/fs/asm/i386.fs @@ -1,3 +1,4 @@ +?f<< /lib/endian.fs ?f<< /asm/label.fs \ "opcode+mod" structure (very close to i386 structure) @@ -21,7 +22,6 @@ : <<3 << << << ; : <<8 8 lshift ; : >>8 8 rshift ; -: w, 16b , ; : regid@ 7 and ; : mod@ 6 rshift 3 and ; : modrm@ $c7 and ; @@ -94,8 +94,8 @@ alias _remsz 8b) : 16b) $20000 or ; : 32b) $fffdffff and $100 or ; -: addr, realmode if w, else , then ; -: data, realmode _16b or if w, else , then ; +: addr, realmode if 16b le, else le, then ; +: data, realmode _16b or if 16b le, else le, then ; : ?disp, ( opmod -- ) dup mod@ case ( opmod ) 0 = of dup ismem? if bank@ addr, else drop then endof 1 = of bank@ c, endof @@ -216,7 +216,7 @@ create _tbl $8c , $120 , $121 , $124 , \ as EB FE. : jrel8? ( rel -- f ) $7f + isbyte? ; : jrel8, 2 - c, ; -: jrel32, ( rel32-or-16 ) realmode if 3 - w, else 5 - , then ; +: jrel32, ( rel32-or-16 ) realmode if 3 - 16b le, else 5 - le, then ; \ Conditional jumps : op ( opcode -- ) doer , does> ( rel a -- ) @@ -236,8 +236,8 @@ $e2 op loop, $e1 op loopz, $e0 op loopnz, dup jrel8? if $eb op, jrel8, else $e9 op, jrel32, then then asm$ ; : call, _argcnt if $ff10 or opmod, else $e8 op, jrel32, then asm$ ; -: jmpfar, ( seg16 absaddr ) $ea op, addr, w, asm$ ; -: callfar, ( seg16 absaddr ) $9a op, addr, w, asm$ ; +: jmpfar, ( seg16 absaddr ) $ea op, addr, 16b le, asm$ ; +: callfar, ( seg16 absaddr ) $9a op, addr, 16b le, asm$ ; : _jmpop@ ( a -- a+n is8? ) c@+ dup $0f = if \ 16 bit jcc diff --git a/fs/xcomp/i386/kernel.fs b/fs/xcomp/i386/kernel.fs @@ -23,7 +23,8 @@ : xconst ( n -- ) xcode xdup, ax swap i) mov, ret, ; 0 value lblintnoop : idtgen ( entrycount -- ) for - lblintnoop $ffff and w, $08 w, 0 c, $8e c, lblintnoop 16 rshift w, next ; + lblintnoop $ffff and 16b le, $08 16b le, 0 c, $8e c, + lblintnoop 16 rshift 16b le, next ; \ Constants and labels 0 to realmode @@ -52,7 +53,7 @@ pc to lblintnoop iret, \ Interrupt Descriptor Table alignhere pc to L2 $100 idtgen pc to lblidt -$100 8 * 1- w, L2 , +$100 8 * 1- 16b le, L2 le, L1 forward! lblidt m) lidt, sti, forward16 jmp, to L1 @@ -62,23 +63,23 @@ L2 xconst IDT 5 xconst BRSZ HERESTART xconst herestart -pc HEREMAX , xconst HEREMAX -pc to lblhere HERESTART , +pc HEREMAX le, xconst HEREMAX +pc to lblhere HERESTART le, lblhere xconst HERE -8 allot0 pc to lblsysdict 0 , +8 allot0 pc to lblsysdict 0 le, lblsysdict xconst sysdict -pc to lblmod 0 , +pc to lblmod 0 le, lblmod xconst MOD -pc to lbl[rcnt] 0 , +pc to lbl[rcnt] 0 le, lbl[rcnt] xconst [rcnt] -pc to lblnextword 0 , +pc to lblnextword 0 le, lblnextword xconst NEXTWORD pc to lblcurword $20 allot0 lblcurword xconst curword -pc to lblnextmeta 0 , +pc to lblnextmeta 0 le, lblnextmeta xconst nextmeta -pc to lblcompiling 0 , +pc to lblcompiling 0 le, xcode compiling xdup, ax lblcompiling m) mov, ret, @@ -116,7 +117,7 @@ $5 xconst NZ) $2 xconst <) $3 xconst >=) $6 xconst <=) $7 xconst >) $c xconst s<) $d xconst s>=) $e xconst s<=) $f xconst s>) -pc to lblhbank 0 , +pc to lblhbank 0 le, lblhbank xconst HBANK xcode m) ( a -- operand ) lblhbank m) ax mov, @@ -431,7 +432,7 @@ xcode cidx ( c a u -- ?idx f ) \ Interpret loop -alignhere pc to lblbootptr 0 , +alignhere pc to lblbootptr 0 le, xcode boot< dx lblbootptr m) mov, xdup, ax dx 0 d) 8b) movzx, diff --git a/fs/xcomp/i386/pc/kernel.fs b/fs/xcomp/i386/pc/kernel.fs @@ -7,7 +7,7 @@ pc to L1 \ back to protected mode! lblidt m) lidt, sti, xdrop, ( final xdrop ) ret, -pc to L2 $3ff w, 0 , \ real mode IVT +pc to L2 $3ff 16b le, 0 le, \ real mode IVT pc to L3 1 to realmode \ we're in realmode ax ax xor, es ax mov, ds ax mov, ss ax mov, L2 m) lidt, sti, diff --git a/fs/xcomp/i386/pc/mbr.fs b/fs/xcomp/i386/pc/mbr.fs @@ -15,15 +15,15 @@ forward8 jmp, to lblstart 3 allot0 \ now aligned on 32-bit \ Inspired by GNU grub at grub-core/kern/i386/realmode.S pc 8 allot0 \ first entry is always null \ Code segment. base=0, limit=ffffff*4kb, present, 32bit, execute/read, DPL=0 -$ffff w, 0 w, 0 c, $9a c, $cf c, 0 c, +$ffff 16b le, 0 16b le, 0 c, $9a c, $cf c, 0 c, \ Data segment. base=0, limit=ffffff*4kb, present, 32bit, read/write, DPL=0 -$ffff w, 0 w, 0 c, $92 c, $cf c, 0 c, +$ffff 16b le, 0 16b le, 0 c, $92 c, $cf c, 0 c, \ Code segment. base=0, limit=ffff*1b, present, 32bit, execute/read, DPL=0 -$ffff w, 0 w, 0 c, $9a c, 0 c, 0 c, +$ffff 16b le, 0 16b le, 0 c, $9a c, 0 c, 0 c, \ Data segment. base=0, limit=ffff*1b, present, 32bit, read/write, DPL=0 -$ffff w, 0 w, 0 c, $92 c, 0 c, 0 c, +$ffff 16b le, 0 16b le, 0 c, $92 c, 0 c, 0 c, pc to lblgdt -$27 w, ( pc ) , +$27 16b le, ( pc ) le, pc to lblspit \ al=char \ the BIOS is supposed to preserve unused registers, but we never know...