commit dc69524d0f60680b6477ee932f7590048b3d2ce4
parent be8fb6a5caa4dd33b034b1bfdfee4ffd857e6c24
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Fri, 7 Oct 2022 14:11:52 -0400
asm/i386: add support for rel8 jumps
Diffstat:
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/fs/asm/i386.fs b/fs/asm/i386.fs
@@ -174,27 +174,28 @@ $9c op pushf, $9d op popf, $cf op iret,
\ of the size of its relative offset. To that end, we auto adjust that relative
\ address to the size of the op. Therefore, "0 jmp," is an infinite loop encoded
\ as EB FE.
-: jrop, ( rel32-or-16 opcode )
- dup op, $ff > if 1- then realmode if 3 - w, else 5 - , then asm$ ;
+: jrel8? ( rel -- f ) $7f + $100 < ;
+: jrel8, 2 - c, ;
+: jrel32, ( rel32-or-16 ) realmode if 3 - w, else 5 - , then ;
-\ Conditional jumps TODO: add jr8 support
-: op ( opcode -- ) doer , does> ( rel32-or-16 a -- ) @ jrop, ;
-$0f84 op jz, $0f85 op jnz, $0f82 op jc, $0f83 op jnc,
-$0f88 op js, $0f89 op jns, $0f8c op jl, $0f8d op jnl,
-$0f87 op ja, $0f86 op jna,
+\ Conditional jumps
+: op ( opcode -- ) doer , does> ( rel a -- )
+ @ over jrel8? if $70 or op, jrel8, else $f80 or op, 1- jrel32, then ;
+$4 op jz, $5 op jnz, $2 op jc, $3 op jnc,
+$8 op js, $9 op jns, $c op jl, $d op jnl,
+$7 op ja, $6 op jna,
\ JMP and CALL
\ These are special. They can either be called with a modrm tgt, or with *no
\ argument at all*. In the latter case, an absolute addr to call is waiting on
\ PS. in the opcode structure, lower byte is the "direct" opcode and 2nd one is
\ the "opreg" for the modrm version.
-: op ( opcode -- ) doer , does> @ ( rel32-or-16? opcode -- )
- opreg 0< oprm 0< and if ( rel32 opcode )
- $ff and jrop,
- else \ ( opcode )
- 8 rshift opreg! $ff opmodrm,
- then ;
-$04e9 op jmp, $02e8 op call,
+: _rel? opreg 0< oprm 0< and ;
+: _rm, opreg! $ff opmodrm, ;
+: jmp, _rel? if
+ dup jrel8? if $eb op, jrel8, else $e9 op, jrel32, then
+ else 4 _rm, then ;
+: call, _rel? if $e8 op, jrel32, else 2 _rm, then ;
: jmpfar, ( seg16 absaddr ) $ea op, addr, w, ;
: callfar, ( seg16 absaddr ) $9a op, addr, w, ;