diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-17 02:57:08 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | 81c5f8e750fcda6a2451fb54604130431434f88f (patch) | |
tree | 944fa06c781d57b1db90e9153080f411a1c34a55 /executor/x86_64/asm.h | |
parent | 20662a1d203ffb9e05d6694347fd258115b41d0a (diff) |
Implement more instructions, implement function parameters and arguments
Diffstat (limited to 'executor/x86_64/asm.h')
-rw-r--r-- | executor/x86_64/asm.h | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/executor/x86_64/asm.h b/executor/x86_64/asm.h index b374e44..7e5ac67 100644 --- a/executor/x86_64/asm.h +++ b/executor/x86_64/asm.h @@ -7,7 +7,7 @@ typedef struct { void *code; u8 *code_it; - usize size; + usize allocated_size; } Asm; typedef enum { @@ -47,6 +47,8 @@ void asm_ptr_init_index_disp(AsmPtr *self, Reg64 base, Reg64 index, i32 disp); CHECK_RESULT int asm_init(Asm *self); void asm_deinit(Asm *self); +usize asm_get_size(Asm *self); + CHECK_RESULT int asm_execute(Asm *self); CHECK_RESULT int asm_nop(Asm *self); @@ -68,9 +70,23 @@ CHECK_RESULT int asm_mov_rr(Asm *self, Reg64 dst, Reg64 src); CHECK_RESULT int asm_add_rr(Asm *self, Reg64 dst, Reg64 src); CHECK_RESULT int asm_sub_rr(Asm *self, Reg64 dst, Reg64 src); CHECK_RESULT int asm_imul_rr(Asm *self, Reg64 dst, Reg64 src); +/* Sign extend RAX into RDX, this is needed for some operations, such as idiv */ +CHECK_RESULT int asm_cqo(Asm *self); +/* + Divide RDX:RAX by @src. Store the quotient in RAX and the remainder in RDX. + @asm_cqo should be called before this, since RAX needs to be sign extended into RDX +*/ +CHECK_RESULT int asm_idiv_rr(Asm *self, Reg64 src); CHECK_RESULT int asm_pushr(Asm *self, Reg64 reg); CHECK_RESULT int asm_popr(Asm *self, Reg64 reg); +/* + In x86 assembly, the @relative position starts from the next instruction. + This offset shouldn't be calculated by the caller and is instead managed + by this asm library itself. +*/ +CHECK_RESULT int asm_call_rel32(Asm *self, i32 relative); +void asm_override_call_rel32(Asm *self, u32 asm_index, i32 new_relative); |