duskos

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

commit 1e80fd3d0b21f4ba76b2d09ac466c9a7ae07db5d
parent 2c2fb3e58d8598c4c7a1a24602db7514e08acdfc
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Thu, 22 Jun 2023 11:50:56 -0400

hal: separate High HAL from assembler units

As I've added in doc/hal, HAL is designed only for "live" programming in mind.
When we load an assembler, it might be for cross compiling and HAL shouldn't be
interfered with.

Diffstat:
Mfs/asm/hal.fs | 2+-
Mfs/asm/i386.fs | 63---------------------------------------------------------------
Afs/asm/i386h.fs | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mfs/comp/c/cc.fs | 1+
Mfs/doc/hal.txt | 6+++++-
Mfs/tests/asm/i386.fs | 1+
6 files changed, 72 insertions(+), 65 deletions(-)

diff --git a/fs/asm/hal.fs b/fs/asm/hal.fs @@ -1,2 +1,2 @@ \ The HAL is provided by assemblers -ARCH S" i386" s= [if] f<< /asm/i386.fs [then] +ARCH S" i386" s= [if] ?f<< /asm/i386h.fs [then] diff --git a/fs/asm/i386.fs b/fs/asm/i386.fs @@ -252,66 +252,3 @@ $e2 op loop, $e1 op loopz, $e0 op loopnz, 8b? of r@ movzx, endof 16b? of r@ 32b) movzx, endof mov, endcase ; - -\ High HAL for i386 -\ W=ax A=di PSP=si RSP=sp - -: A>) ( halop -- halop ) $40000 or ; -: A>? $40000 and bool ; -: <>) ( halop -- halop ) $80000 xor ; -: <>? $80000 and bool ; -: &) ( halop -- halop ) $10000 or ; -: &? $10000 and bool ; -: +) d) ; -: RSP) sp 0 d) ; - -: _& ( opmod -- opmod ) - dup &? if - $fffeffff and dup indirect? if dup ismem? if bank@ i) else - dup mod@ 0 = if ( indirect no disp ) $c0 or else ( indirect + disp ) - bx swap lea, bx then then then then ; - -: halop>dstsrc ( halop -- dst src ) - _& dup A>? if di else ax then ( src dst ) - over <>? not if swap then ; - -: op doer ' , does> @ ( halop w ) dip halop>dstsrc | execute ; -op @, ?movzx, op @!, xchg, op addr, lea, -: !, <>) @, ; - -: op doer ' , does> @ ( halop w ) dip halop>dstsrc ( dst src ) - bi+ 16b? | 8b? or if bx swap ?movzx, bx then | execute ; -op +, add, op -, sub, op compare, cmp, -op &, and, op |, or, op ^, xor, - -: _pre ( op -- op src ) - _& dup <>? if ax over xchg, then dup A>? if di ax mov, then dup - dup imm? if bx swap mov, bx then ; -: _post ( op -- ) - dup A>? if di ax xchg, then dup <>? if ax xchg, else drop then ; -: *, _pre mul, _post ; -: /, _pre dx dx xor, div, _post ; -: %, _pre dx dx xor, div, ax dx mov, _post ; - -: op doer ' , does> @ dip halop>dstsrc ( dst src ) - dup imm? not if cx swap mov, cl then | execute ; -op <<, shl, op >>, shr, - -: [+n], ( n halop -- ) - halop>dstsrc nip swap case ( op ) - 1 = of inc, endof - -1 = of dec, endof - i) add, endcase ; -: _ ( halop -- dst src ) - dup 16b? >r dup 8b? >r 32b) - halop>dstsrc bx swap mov, ( dst ) - bx 0 d) r> if 8b) then r> if 16b) then ; -: [@], _ mov, ; : [!], _ swap mov, ; - -\ These are used so often that it's worth redefining them in their more -\ efficient version. -: _ ?dup if swap dup 0< if neg i) sub, else i) add, then then ; -: ps+, si _ ; : rs+, sp _ ; -: dup, -4 ps+, PSP) !, ; -: nip, 4 ps+, ; -: drop, PSP) @, nip, ; diff --git a/fs/asm/i386h.fs b/fs/asm/i386h.fs @@ -0,0 +1,64 @@ +\ High HAL for i386 +\ W=ax A=di PSP=si RSP=sp +?f<< /asm/i386.fs + +: A>) ( halop -- halop ) $40000 or ; +: A>? $40000 and bool ; +: <>) ( halop -- halop ) $80000 xor ; +: <>? $80000 and bool ; +: &) ( halop -- halop ) $10000 or ; +: &? $10000 and bool ; +: +) d) ; +: RSP) sp 0 d) ; + +: _& ( opmod -- opmod ) + dup &? if + $fffeffff and dup indirect? if dup ismem? if bank@ i) else + dup mod@ 0 = if ( indirect no disp ) $c0 or else ( indirect + disp ) + bx swap lea, bx then then then then ; + +: halop>dstsrc ( halop -- dst src ) + _& dup A>? if di else ax then ( src dst ) + over <>? not if swap then ; + +: op doer ' , does> @ ( halop w ) dip halop>dstsrc | execute ; +op @, ?movzx, op @!, xchg, op addr, lea, +: !, <>) @, ; + +: op doer ' , does> @ ( halop w ) dip halop>dstsrc ( dst src ) + bi+ 16b? | 8b? or if bx swap ?movzx, bx then | execute ; +op +, add, op -, sub, op compare, cmp, +op &, and, op |, or, op ^, xor, + +: _pre ( op -- op src ) + _& dup <>? if ax over xchg, then dup A>? if di ax mov, then dup + dup imm? if bx swap mov, bx then ; +: _post ( op -- ) + dup A>? if di ax xchg, then dup <>? if ax xchg, else drop then ; +: *, _pre mul, _post ; +: /, _pre dx dx xor, div, _post ; +: %, _pre dx dx xor, div, ax dx mov, _post ; + +: op doer ' , does> @ dip halop>dstsrc ( dst src ) + dup imm? not if cx swap mov, cl then | execute ; +op <<, shl, op >>, shr, + +: [+n], ( n halop -- ) + halop>dstsrc nip swap case ( op ) + 1 = of inc, endof + -1 = of dec, endof + i) add, endcase ; +: _ ( halop -- dst src ) + dup 16b? >r dup 8b? >r 32b) + halop>dstsrc bx swap mov, ( dst ) + bx 0 d) r> if 8b) then r> if 16b) then ; +: [@], _ mov, ; : [!], _ swap mov, ; + +\ These are used so often that it's worth redefining them in their more +\ efficient version. +: _ ?dup if swap dup 0< if neg i) sub, else i) add, then then ; +: ps+, si _ ; : rs+, sp _ ; +: dup, -4 ps+, PSP) !, ; +: nip, 4 ps+, ; +: drop, PSP) @, nip, ; + diff --git a/fs/comp/c/cc.fs b/fs/comp/c/cc.fs @@ -1,4 +1,5 @@ \ C compiler +?f<< /asm/hal.fs ?f<< /comp/c/gen.fs ?f<< /comp/c/pp.fs diff --git a/fs/doc/hal.txt b/fs/doc/hal.txt @@ -17,7 +17,11 @@ of the loops. At boot, a bare Dusk system only has the Low HAL (see below) loaded. If you want to load the High HAL, do "f<< asm/hal.fs". This will load the assembler for the -native architecture. +native architecture. High HAL implementations generally live in the "asm" folder +with the name of the architecture and a "h" suffix. Example, "/asm/i386h.fs". + +The HAL is always for the "live" system. It has not been designed with cross- +compiling in mind. ## Concepts diff --git a/fs/tests/asm/i386.fs b/fs/tests/asm/i386.fs @@ -1,5 +1,6 @@ ?f<< /tests/harness.fs ?f<< /asm/i386.fs +?f<< /asm/hal.fs testbegin \ Tests for asm/i386.fs \ The first part of the tests tests particular mechanics within the assembler