duskos

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

commit df2a6f97cd432cbd79a6936abfd3c45691bf6c64
parent a680f1ecf8953f05f92d55ff0b508fb79dd03c5b
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Thu, 21 Jul 2022 20:37:16 -0400

asm/i386: add the ability to MOV from/to segment registers

Diffstat:
Mfs/asm/i386.fs | 16+++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/fs/asm/i386.fs b/fs/asm/i386.fs @@ -7,9 +7,12 @@ 4 const SP 5 const BP 6 const SI 7 const DI 0 const AL 1 const CL 2 const DL 3 const BL 4 const AH 5 const CH 6 const DH 7 const BH +0 const ES 1 const CS 2 const SS 3 const DS +4 const FS 5 const GS 4 const SIB \ mod 0/1/2 + r/m 4 == SIB 0 value op8b \ is current op in 8bit mode? +0 value opsreg \ is current op an Sreg? 1 value opdirec \ 1: reg=tgt r/m=src 0: reg=src r/m=tgt 3 value opmod \ by default, we're in "direct reg" mode -1 value opreg \ -1 = unset @@ -21,7 +24,8 @@ 0 value realmode \ Utilities -: asm$ 0 to op8b 1 to opdirec 3 to opmod -1 to opreg -1 to oprm 0 to imm? ; +: asm$ 0 to op8b 0 to opsreg 1 to opdirec 3 to opmod -1 to opreg -1 to oprm + 0 to imm? ; : _err asm$ abort" argument error" ; : _assert not if _err then ; : w, here w! 2 allot ; @@ -37,7 +41,8 @@ : opreg! ( reg -- ) opreg 0>= if oprm 0< _assert \ can't have a 2nd argument! - opreg to oprm then + opreg to oprm + 0 to opdirec then to opreg ; : .asm ." 8b? " op8b . ." d" opdirec . ." mod " opmod . ." reg " opreg . @@ -106,6 +111,9 @@ AX _ ax BX _ bx CX _ cx DX _ dx SP _ sp BP _ bp SI _ si DI _ di : _ doer ( reg -- ) c, does> c@ ( reg ) r! 1 to op8b ; AL _ al BL _ bl CL _ cl DL _ dl AH _ ah BH _ bh CH _ ch DH _ dh +: _ doer ( reg -- ) c, does> c@ ( reg ) opreg! 1 to opsreg ; +ES _ es SS _ ss DS _ ds FS _ fs GS _ gs + : i) ( imm -- ) 1 to imm? to imm ; : 16breg>[oprm] ( reg ) case @@ -222,7 +230,9 @@ $58 op pop, $50 op _push, imm? if opmod 3 = if \ mov reg, imm shortcut $b0 op8b not 3 lshift or ( b0 or b8 ) opreg or c, imm, asm$ else $c7 c, 0 opreg! msd, imm, asm$ then - else $88 opmodrm, then ; + else + opsreg if $8c opdirec << or c, msd, asm$ else + $88 opmodrm, then then ; \ INT is special : int, ( n -- ) $cd c, c, ;