/* src/vm/jit/x86_64/codegen.h - code generation macros for x86_64
- Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: codegen.h 7596 2007-03-28 21:05:53Z twisti $
-
*/
#include "vm/jit/x86_64/emit.h"
-#include "vm/jit/jit.h"
+#include "vm/jit/jit.hpp"
/* additional functions and macros to generate code ***************************/
/* patcher defines ************************************************************/
-#define PATCHER_CALL_SIZE 5 /* size in bytes of a patcher call */
+#define PATCHER_CALL_SIZE 2 /* size in bytes of a patcher call */
#define PATCHER_NOPS \
do { \
M_NOP; \
M_NOP; \
- M_NOP; \
- M_NOP; \
- M_NOP; \
} while (0)
/* macros to create code ******************************************************/
+#define M_BYTE1(a) \
+ do { \
+ *(cd->mcodeptr) = (a); \
+ cd->mcodeptr++; \
+ } while (0)
+
+
+#define M_BYTE2(a, b) \
+ do { \
+ M_BYTE1(a); \
+ M_BYTE1(b); \
+ } while (0)
+
+
#define M_MOV(a,b) emit_mov_reg_reg(cd, (a), (b))
#define M_MOV_IMM(a,b) emit_mov_imm_reg(cd, (u8) (a), (b))
#define M_LMUL_IMM(a,b,c) emit_imul_imm_reg_reg(cd, (b), (a), (c))
#define M_IINC(a) emit_incl_reg(cd, (a))
+#define M_LINC(a) emit_incq_reg(cd, (a))
#define M_IDEC(a) emit_decl_reg(cd, (a))
-#define M_ALD(a,b,disp) M_LLD(a,b,disp)
+#define M_ALD(a,b,disp) \
+ do { \
+ if (b == RIP) \
+ M_LLD(a, b, disp + -((cd->mcodeptr + 7) - cd->mcodebase)); \
+ else \
+ M_LLD(a, b, disp); \
+ } while (0)
+
#define M_ALD32(a,b,disp) M_LLD32(a,b,disp)
#define M_ALD_MEM(a,disp) emit_mov_mem_reg(cd, (disp), (a))
#define M_SSEXT(a,b) emit_movswq_reg_reg(cd, (a), (b))
#define M_ISEXT(a,b) emit_movslq_reg_reg(cd, (a), (b))
+#define M_BZEXT(a,b) emit_movzbq_reg_reg(cd, (a), (b))
#define M_CZEXT(a,b) emit_movzwq_reg_reg(cd, (a), (b))
#define M_ISLL_IMM(a,b) emit_shiftl_imm_reg(cd, SHIFT_SHL, (a), (b))
#define M_LCMP_IMM(a,b) emit_alu_imm_reg(cd, ALU_CMP, (a), (b))
#define M_LCMP_IMM_MEMBASE(a,b,c) emit_alu_imm_membase(cd, ALU_CMP, (a), (b), (c))
#define M_LCMP_MEMBASE(a,b,c) emit_alu_membase_reg(cd, ALU_CMP, (a), (b), (c))
+#define M_LCMP_MEMINDEX(a,b,c,d,e) emit_alul_memindex_reg(cd, ALU_CMP, (b), (a), (c), (d), (e))
#define M_ICMP(a,b) emit_alul_reg_reg(cd, ALU_CMP, (a), (b))
#define M_ICMP_IMM(a,b) emit_alul_imm_reg(cd, ALU_CMP, (a), (b))
#define M_ICMP_IMM32(a,b) emit_alul_imm32_reg(cd, ALU_CMP, (a), (b))
#define M_ICMP_IMM_MEMBASE(a,b,c) emit_alul_imm_membase(cd, ALU_CMP, (a), (b), (c))
#define M_ICMP_MEMBASE(a,b,c) emit_alul_membase_reg(cd, ALU_CMP, (a), (b), (c))
+#define M_ICMP_MEMINDEX(a,b,c,d,e) emit_alu_memindex_reg(cd, ALU_CMP, (b), (a), (c), (d), (e))
#define M_BEQ(disp) emit_jcc(cd, CC_E, (disp))
#define M_BNE(disp) emit_jcc(cd, CC_NE, (disp))
#define M_BUGE(disp) emit_jcc(cd, CC_AE, (disp))
#define M_BUGT(disp) emit_jcc(cd, CC_A, (disp))
+#define M_SETE(a) emit_setcc_reg(cd, CC_E, (a))
#define M_SETNE(a) emit_setcc_reg(cd, CC_NE, (a))
#define M_SETULE(a) emit_setcc_reg(cd, CC_BE, (a))
#define M_JMP(a) emit_jmp_reg(cd, (a))
#define M_JMP_IMM(a) emit_jmp_imm(cd, (a))
+#define M_JMP_IMM2(a) emit_jmp_imm2(cd, (a))
#define M_CALL(a) emit_call_reg(cd, (a))
#define M_CALL_IMM(a) emit_call_imm(cd, (a))
-#define M_RET emit_ret(cd)
+#define M_RET M_BYTE1(0xc3)
-#define M_NOP emit_nop(cd)
+#define M_NOP M_BYTE1(0x90)
+#define M_UD2 M_BYTE2(0x0f, 0x0b)
#define M_CLR(a) M_LXOR(a,a)
#define M_RDTSC emit_rdtsc(cd)
#define M_IINC_MEMBASE(a,b) emit_incl_membase(cd, (a), (b))
+#define M_LINC_MEMBASE(a,b) emit_incq_membase(cd, (a), (b))
#define M_IADD_MEMBASE(a,b,c) emit_alul_reg_membase(cd, ALU_ADD, (a), (b), (c))
#define M_IADC_MEMBASE(a,b,c) emit_alul_reg_membase(cd, ALU_ADC, (a), (b), (c))