From 81c5f8e750fcda6a2451fb54604130431434f88f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 17 Aug 2019 02:57:08 +0200 Subject: Implement more instructions, implement function parameters and arguments --- executor/x86_64/asm.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'executor/x86_64/asm.h') 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); -- cgit v1.2.3