duskos

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

commit 4f34b25848b88e984439686565192e97a2df27f6
parent 98d5bc808b5d06458d18877a613559cc0fac84fc
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sun,  3 Jul 2022 15:57:12 -0400

asm: add the ability to call/jmp to a modrm

Diffstat:
Mfs/asm.fs | 12++++++++++--
Mfs/cc/vm.fs | 2+-
Mfs/tests/asm.fs | 18++++++++++++++----
3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/fs/asm.fs b/fs/asm.fs @@ -82,9 +82,17 @@ : op ( opcode -- ) doer c, does> ( a -- ) c@ inh, ; $c3 op ret, -\ Relative jumps +\ Conditional jumps : op ( opcode -- ) doer , does> ( rel32 a -- ) @ op, , ; -$00e9 op jmp, $0f84 op jz, $0f85 op jnz, +$0f84 op jz, $0f85 op jnz, + +\ 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. +: op ( opcode -- ) doer c, c, does> ( rel32? a -- ) + prefix, tgt 0< if 1+ c@ op, here - 4 - , else c@ $ff ( reg op ) modrm1, then ; +$e9 4 op jmp, $e8 2 op call, \ Single operand : op ( reg opcode -- ) doer , c, does> ( a -- ) diff --git a/fs/cc/vm.fs b/fs/cc/vm.fs @@ -208,7 +208,7 @@ operands value 'curop \ TODO: call function with no return value. : vmcall>op1, ( -- ) VM_*CONSTANT optype = _assert - oparg execute, VM_NONE optype! + oparg call, VM_NONE optype! selop1 noop# VM_REGISTER optype! regallot dup oparg! r! [ebp] mov, ebp 4 i32 add, 0 to callsz ; diff --git a/fs/tests/asm.fs b/fs/tests/asm.fs @@ -2,20 +2,30 @@ ?f<< asm.fs testbegin \ Tests for asm.fs -code foo +code foo1 eax 42 i32 mov, ebp 4 i32 sub, [ebp] eax mov, ret, -foo 42 #eq +foo1 42 #eq here 1234 , ( a ) -code foo +code foo2 ebx [i32] mov, ebp 4 i32 sub, [ebp] ebx mov, ret, -foo 1234 #eq +foo2 1234 #eq + +\ test call in its different forms +code foo3 + ' foo1 call, + eax ' foo1 i32 mov, + eax call, + ret, + +foo3 42 #eq 42 #eq + testend