~vdupras/duskos

a2e9e3f148bb24a0bd6d9d2a0de78b0a5da54cb5 — Virgil Dupras a month ago c4b329a
i386: HAL tests pass!
2 files changed, 63 insertions(+), 4 deletions(-)

M fs/asm/i386.fs
M fs/doc/hal.txt
M fs/asm/i386.fs => fs/asm/i386.fs +62 -3
@@ 7,9 7,12 @@
\ b8     0=8b 1=32/16b
\ b14:9  zeroes
\ b15    immediate? ( value in bank )
\ b16    opcode is 2 bytes (has $0f extension byte)
\ b16    dual meaning:
\   asm: opcode is 2 bytes (has $0f extension byte)
\   hal: "&)" flag
\ b17    16b?
\ b19:18 reserved
\ b18    HAL "A>)" flag
\ b19    HAL "<>)" flag
\ b23:20 Number bank index
\ b31:24 SIB
\ When we refer to "opmod" below, it's this structure


@@ 81,7 84,7 @@ $100 _ ax $101 _ cx $102 _ dx $103 _ bx $104 _ sp $105 _ bp $106 _ si $107 _ di
: i) newbankedop $8000 or ;
: m) newbankedop memmodrm $100 or or ;
: d)
  notreal# args# _d)
  notreal# _d)
  dup ismem? if ( bp+0 ) $40 + then
  dup sib? if ( sp+n ) $24000000 or then ;



@@ 249,3 252,59 @@ $e2 op loop,     $e1 op loopz,   $e0 op loopnz,
    of 8b? movzx, endof
    of 16b? 32b) movzx, endof
    mov, endcase ;

\ High HAL for i386
\ W=ax A=di PSP=si RSP=sp

: A>) ( halop -- halop ) $40000 or ;
: <>) ( halop -- halop ) $80000 xor ;
: &) ( halop -- halop ) $10000 or ;
: +) d) ;
: RSP) sp 0 d) ;

: _& ( opmod -- opmod )
  dup indirect? if dup ismem? if bank@ i) else
    dup mod@ 0 = if ( indirect no disp ) $c0 or else ( indirect + disp )
      abort" TODO: &) lea," then then then ;

: halop>dstsrc ( halop -- dst src )
  dup 16 rshift >r $fff2ffff and ( src ) \ V1=flags
  r@ 1 and ( & ) if _& then ( src )
  r@ 4 and ( A> ) if di else ax then ( src dst )
  r> 8 and not if swap then ;

: op doer ' , does> @ ( halop w ) dip halop>dstsrc | execute ;
op @, ?movzx,      op @!, xchg,        op addr, lea,
: !, <>) @, ;

\ TODO: in 32-bit mode, arithmetics can be done directly, no need for bx
: op doer ' , does> @ ( halop w ) dip halop>dstsrc ( dst src )
  bx swap ?movzx, bx | execute ;
op +, add,         op -, sub,          op compare, cmp,

: *,
  halop>dstsrc over AX? not if over ax mov, then ( dst src )
  mul, ( dst ) dup AX? if drop else ax xchg, then ;

: op doer ' , does> @ dip halop>dstsrc ( dst src )
  dup imm? not if cx swap mov, cl then | execute ;
op <<, shl,        op >>, shr,

: _ ( 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, ;

$2 const C)
$3 const NC)
$4 const Z)
$5 const NZ)
$2 const <)
$3 const >=)
$6 const <=)
$7 const >)
$c const s<)
$d const s>=)
$e const s<=)
$f const s>)

M fs/doc/hal.txt => fs/doc/hal.txt +1 -1
@@ 48,7 48,7 @@ of each half is described in the sections below.

The HAL has 4 virtual registers: W, A, PSP, RSP. Each architecture implementing
the HAL will need to map those virtual registers to actual registers. For
example, on i386, W=eax A=esi PSP=edi and RSP=esp.
example, on i386, W=eax A=edi PSP=esi and RSP=esp.

### W and A registers