refactor(ir): 将IR节点重构为值引用并添加字符串字面量支持
- 将scc_ir_node_ref_t重命名为scc_ir_value_ref_t,并更新所有相关API - 修改IR定义中的节点标签枚举为值标签枚举(scc_ir_node_tag_t -> scc_ir_value_tag_t) - 更新AST到IR转换器中所有节点引用的类型声明 - 添加对内置类型(VOID, CHAR, INT等)的完整映射实现 - 实现字符串字面量的常量数组创建功能 - 更新项目名称从"Simple Modual C Compiler"为"Simple C Compiler" - 在Doxyfile中排除external目录的文档生成 - 移除未使用的strpool字段并重命名decl到IR的映射表 BREAKING CHANGE: IR节点引用类型已更改,所有使用scc_ir_node_ref_t的地方需 替换为scc_ir_value_ref_t。
This commit is contained in:
@@ -52,6 +52,8 @@
|
||||
#define SCC_AMD64_COND_LE 14 // less or equal (signed)
|
||||
#define SCC_AMD64_COND_G 15 // greater (signed)
|
||||
|
||||
#define SCC_MCODE_FUNC [[maybe_unused]] static inline
|
||||
|
||||
// ==================== REX 前缀辅助 ====================
|
||||
/**
|
||||
* @brief 生成 REX 前缀(若不为 0x40 则写入)
|
||||
@@ -62,8 +64,8 @@
|
||||
* @param x REX.X 位
|
||||
* @param b REX.B 位
|
||||
*/
|
||||
static inline void scc_mcode_amd64_rex(scc_mcode_t *mcode, u8 w, u8 r, u8 x,
|
||||
u8 b) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_rex(scc_mcode_t *mcode, u8 w, u8 r, u8 x,
|
||||
u8 b) {
|
||||
u8 rex = 0x40 | (w << 3) | (r << 2) | (x << 1) | b;
|
||||
if (rex != 0x40)
|
||||
scc_mcode_add_u8(mcode, rex);
|
||||
@@ -82,9 +84,9 @@ static inline void scc_mcode_amd64_rex(scc_mcode_t *mcode, u8 w, u8 r, u8 x,
|
||||
* @param p_src_low 输出 src 的低 3 位
|
||||
* @return 是否需要写入 REX 前缀(0 表示不需要)
|
||||
*/
|
||||
static inline int scc_mcode_amd64_prepare_rex(int dst_reg, int src_reg,
|
||||
int use_w, u8 *p_rex,
|
||||
u8 *p_dst_low, u8 *p_src_low) {
|
||||
SCC_MCODE_FUNC int scc_mcode_amd64_prepare_rex(int dst_reg, int src_reg,
|
||||
int use_w, u8 *p_rex,
|
||||
u8 *p_dst_low, u8 *p_src_low) {
|
||||
u8 rex = 0x40;
|
||||
if (use_w)
|
||||
rex |= 0x08;
|
||||
@@ -105,8 +107,8 @@ static inline int scc_mcode_amd64_prepare_rex(int dst_reg, int src_reg,
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param width 宽度(1=8位,2=16位,4=32位,8=64位)
|
||||
*/
|
||||
static inline void scc_mcode_amd64_emit_width_prefix(scc_mcode_t *mcode,
|
||||
int width) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_emit_width_prefix(scc_mcode_t *mcode,
|
||||
int width) {
|
||||
if (width == 2) {
|
||||
scc_mcode_add_u8(mcode, 0x66);
|
||||
}
|
||||
@@ -121,7 +123,7 @@ static inline void scc_mcode_amd64_emit_width_prefix(scc_mcode_t *mcode,
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param reg 寄存器编号
|
||||
*/
|
||||
static inline void scc_mcode_amd64_push_r64(scc_mcode_t *mcode, int reg) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_push_r64(scc_mcode_t *mcode, int reg) {
|
||||
if (reg < 8) {
|
||||
scc_mcode_add_u8(mcode, 0x50 + reg);
|
||||
} else {
|
||||
@@ -136,7 +138,7 @@ static inline void scc_mcode_amd64_push_r64(scc_mcode_t *mcode, int reg) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param reg 寄存器编号
|
||||
*/
|
||||
static inline void scc_mcode_amd64_pop_r64(scc_mcode_t *mcode, int reg) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_pop_r64(scc_mcode_t *mcode, int reg) {
|
||||
if (reg < 8) {
|
||||
scc_mcode_add_u8(mcode, 0x58 + reg);
|
||||
} else {
|
||||
@@ -151,7 +153,7 @@ static inline void scc_mcode_amd64_pop_r64(scc_mcode_t *mcode, int reg) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_push_imm32(scc_mcode_t *mcode, u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_push_imm32(scc_mcode_t *mcode, u32 imm) {
|
||||
scc_mcode_add_u8(mcode, 0x68);
|
||||
scc_mcode_add_u32(mcode, imm);
|
||||
}
|
||||
@@ -167,8 +169,8 @@ static inline void scc_mcode_amd64_push_imm32(scc_mcode_t *mcode, u32 imm) {
|
||||
* @param reg 目标寄存器
|
||||
* @param imm 64 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r64_imm64(scc_mcode_t *mcode, int reg,
|
||||
u64 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r64_imm64(scc_mcode_t *mcode, int reg,
|
||||
u64 imm) {
|
||||
u8 rex = 0x48; // REX.W
|
||||
if (reg >= 8) {
|
||||
rex |= 0x01; // REX.B
|
||||
@@ -186,8 +188,8 @@ static inline void scc_mcode_amd64_mov_r64_imm64(scc_mcode_t *mcode, int reg,
|
||||
* @param reg 目标寄存器
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r64_imm32(scc_mcode_t *mcode, int reg,
|
||||
u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r64_imm32(scc_mcode_t *mcode, int reg,
|
||||
u32 imm) {
|
||||
u8 rex = 0x40; // REX.W=0
|
||||
if (reg >= 8) {
|
||||
rex |= 0x01; // REX.B
|
||||
@@ -205,8 +207,8 @@ static inline void scc_mcode_amd64_mov_r64_imm32(scc_mcode_t *mcode, int reg,
|
||||
* @param dst 目标寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48; // REX.W
|
||||
if (src >= 8)
|
||||
rex |= 0x04; // REX.R
|
||||
@@ -225,8 +227,8 @@ static inline void scc_mcode_amd64_mov_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
* @param base 基址寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_m64_r64(scc_mcode_t *mcode, int base,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_m64_r64(scc_mcode_t *mcode, int base,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -251,8 +253,8 @@ static inline void scc_mcode_amd64_mov_m64_r64(scc_mcode_t *mcode, int base,
|
||||
* @param dst 目标寄存器
|
||||
* @param base 基址寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r64_m64(scc_mcode_t *mcode, int dst,
|
||||
int base) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r64_m64(scc_mcode_t *mcode, int dst,
|
||||
int base) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -278,9 +280,9 @@ static inline void scc_mcode_amd64_mov_r64_m64(scc_mcode_t *mcode, int dst,
|
||||
* @param disp 32 位偏移
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_m64_disp32_r64(scc_mcode_t *mcode,
|
||||
int base, u32 disp,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_m64_disp32_r64(scc_mcode_t *mcode,
|
||||
int base, u32 disp,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -307,9 +309,9 @@ static inline void scc_mcode_amd64_mov_m64_disp32_r64(scc_mcode_t *mcode,
|
||||
* @param base 基址寄存器
|
||||
* @param disp 32 位偏移
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r64_m64_disp32(scc_mcode_t *mcode,
|
||||
int dst, int base,
|
||||
u32 disp) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r64_m64_disp32(scc_mcode_t *mcode,
|
||||
int dst, int base,
|
||||
u32 disp) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -328,6 +330,32 @@ static inline void scc_mcode_amd64_mov_r64_m64_disp32(scc_mcode_t *mcode,
|
||||
scc_mcode_add_u32(mcode, disp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 加载 RIP 相对地址到 64 位寄存器 (lea r64, [rip+disp32])
|
||||
*
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param dst 目标寄存器 (0-15)
|
||||
* @param disp 32 位相对偏移量 (有符号)
|
||||
*/
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_lea_r64_rip_rel32(scc_mcode_t *mcode,
|
||||
int dst, u32 disp) {
|
||||
// REX.W = 1, 无额外扩展位(RIP 不是通用寄存器,不涉及 REX.B/R/X)
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8) {
|
||||
rex |= 0x04; // REX.R 位,因为 dst 放在 reg 字段
|
||||
dst -= 8;
|
||||
}
|
||||
scc_mcode_add_u8(mcode, rex);
|
||||
scc_mcode_add_u8(mcode, 0x8D); // LEA opcode
|
||||
|
||||
// ModRM: mod=00 (无位移), reg=dst, r/m=101 (RIP 相对寻址)
|
||||
u8 modrm = 0x05 | ((dst & 7) << 3);
|
||||
scc_mcode_add_u8(mcode, modrm);
|
||||
|
||||
// disp32 (有符号)
|
||||
scc_mcode_add_u32(mcode, (u32)disp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 加载有效地址到 64 位寄存器 (lea r64, [base+disp32])
|
||||
*
|
||||
@@ -336,9 +364,9 @@ static inline void scc_mcode_amd64_mov_r64_m64_disp32(scc_mcode_t *mcode,
|
||||
* @param base 基址寄存器
|
||||
* @param disp 32 位偏移
|
||||
*/
|
||||
static inline void scc_mcode_amd64_lea_r64_m64_disp32(scc_mcode_t *mcode,
|
||||
int dst, int base,
|
||||
u32 disp) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_lea_r64_m64_disp32(scc_mcode_t *mcode,
|
||||
int dst, int base,
|
||||
u32 disp) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -366,8 +394,8 @@ static inline void scc_mcode_amd64_lea_r64_m64_disp32(scc_mcode_t *mcode,
|
||||
* @param dst 目标寄存器(低 32 位)
|
||||
* @param src 源寄存器(低 32 位)
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r32_r32(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r32_r32(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x40; // REX.W=0
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -386,8 +414,8 @@ static inline void scc_mcode_amd64_mov_r32_r32(scc_mcode_t *mcode, int dst,
|
||||
* @param reg 目标寄存器
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r32_imm32(scc_mcode_t *mcode, int reg,
|
||||
u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r32_imm32(scc_mcode_t *mcode, int reg,
|
||||
u32 imm) {
|
||||
scc_mcode_amd64_mov_r64_imm32(mcode, reg, imm); // 与 64 位 imm32 版本相同
|
||||
}
|
||||
|
||||
@@ -398,8 +426,8 @@ static inline void scc_mcode_amd64_mov_r32_imm32(scc_mcode_t *mcode, int reg,
|
||||
* @param base 基址寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_m32_r32(scc_mcode_t *mcode, int base,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_m32_r32(scc_mcode_t *mcode, int base,
|
||||
int src) {
|
||||
u8 rex = 0x40; // REX.W=0
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -424,8 +452,8 @@ static inline void scc_mcode_amd64_mov_m32_r32(scc_mcode_t *mcode, int base,
|
||||
* @param dst 目标寄存器
|
||||
* @param base 基址寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r32_m32(scc_mcode_t *mcode, int dst,
|
||||
int base) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r32_m32(scc_mcode_t *mcode, int dst,
|
||||
int base) {
|
||||
u8 rex = 0x40; // REX.W=0
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -452,8 +480,8 @@ static inline void scc_mcode_amd64_mov_r32_m32(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器(低 16 位)
|
||||
* @param src 源寄存器(低 16 位)
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r16_r16(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r16_r16(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
scc_mcode_amd64_emit_width_prefix(mcode, 2);
|
||||
u8 rex = 0x40; // REX.W=0
|
||||
if (src >= 8)
|
||||
@@ -473,8 +501,8 @@ static inline void scc_mcode_amd64_mov_r16_r16(scc_mcode_t *mcode, int dst,
|
||||
* @param reg 目标寄存器
|
||||
* @param imm 16 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r16_imm16(scc_mcode_t *mcode, int reg,
|
||||
u16 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r16_imm16(scc_mcode_t *mcode, int reg,
|
||||
u16 imm) {
|
||||
scc_mcode_amd64_emit_width_prefix(mcode, 2);
|
||||
u8 rex = 0x40; // REX.W=0
|
||||
if (reg >= 8) {
|
||||
@@ -493,8 +521,8 @@ static inline void scc_mcode_amd64_mov_r16_imm16(scc_mcode_t *mcode, int reg,
|
||||
* @param base 基址寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_m16_r16(scc_mcode_t *mcode, int base,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_m16_r16(scc_mcode_t *mcode, int base,
|
||||
int src) {
|
||||
scc_mcode_amd64_emit_width_prefix(mcode, 2);
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
@@ -520,8 +548,8 @@ static inline void scc_mcode_amd64_mov_m16_r16(scc_mcode_t *mcode, int base,
|
||||
* @param dst 目标寄存器
|
||||
* @param base 基址寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r16_m16(scc_mcode_t *mcode, int dst,
|
||||
int base) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r16_m16(scc_mcode_t *mcode, int dst,
|
||||
int base) {
|
||||
scc_mcode_amd64_emit_width_prefix(mcode, 2);
|
||||
u8 rex = 0x40;
|
||||
if (dst >= 8)
|
||||
@@ -550,7 +578,7 @@ static inline void scc_mcode_amd64_mov_r16_m16(scc_mcode_t *mcode, int dst,
|
||||
* @param reg 寄存器编号
|
||||
* @return 是否需要 REX 前缀
|
||||
*/
|
||||
static inline int scc_mcode_amd64_is_byte_reg_needs_rex(int reg) {
|
||||
SCC_MCODE_FUNC int scc_mcode_amd64_is_byte_reg_needs_rex(int reg) {
|
||||
return (reg >= 4 && reg <= 7) || reg >= 8;
|
||||
}
|
||||
|
||||
@@ -561,8 +589,8 @@ static inline int scc_mcode_amd64_is_byte_reg_needs_rex(int reg) {
|
||||
* @param dst 目标寄存器(低 8 位)
|
||||
* @param src 源寄存器(低 8 位)
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r8_r8(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r8_r8(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(dst) ||
|
||||
scc_mcode_amd64_is_byte_reg_needs_rex(src);
|
||||
@@ -585,8 +613,8 @@ static inline void scc_mcode_amd64_mov_r8_r8(scc_mcode_t *mcode, int dst,
|
||||
* @param reg 目标寄存器
|
||||
* @param imm 8 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r8_imm8(scc_mcode_t *mcode, int reg,
|
||||
u8 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r8_imm8(scc_mcode_t *mcode, int reg,
|
||||
u8 imm) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(reg);
|
||||
if (reg >= 8) {
|
||||
@@ -607,8 +635,8 @@ static inline void scc_mcode_amd64_mov_r8_imm8(scc_mcode_t *mcode, int reg,
|
||||
* @param base 基址寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_m8_r8(scc_mcode_t *mcode, int base,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_m8_r8(scc_mcode_t *mcode, int base,
|
||||
int src) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(src) ||
|
||||
scc_mcode_amd64_is_byte_reg_needs_rex(base);
|
||||
@@ -637,8 +665,8 @@ static inline void scc_mcode_amd64_mov_m8_r8(scc_mcode_t *mcode, int base,
|
||||
* @param dst 目标寄存器
|
||||
* @param base 基址寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r8_m8(scc_mcode_t *mcode, int dst,
|
||||
int base) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r8_m8(scc_mcode_t *mcode, int dst,
|
||||
int base) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(dst) ||
|
||||
scc_mcode_amd64_is_byte_reg_needs_rex(base);
|
||||
@@ -669,8 +697,8 @@ static inline void scc_mcode_amd64_mov_r8_m8(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 64 位目标寄存器
|
||||
* @param src 8 位源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_movsx_r64_r8(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_movsx_r64_r8(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48; // REX.W
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -690,8 +718,8 @@ static inline void scc_mcode_amd64_movsx_r64_r8(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 64 位目标寄存器
|
||||
* @param src 16 位源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_movsx_r64_r16(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_movsx_r64_r16(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -711,8 +739,8 @@ static inline void scc_mcode_amd64_movsx_r64_r16(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 64 位目标寄存器
|
||||
* @param src 32 位源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_movsx_r64_r32(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_movsx_r64_r32(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -731,8 +759,8 @@ static inline void scc_mcode_amd64_movsx_r64_r32(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 64 位目标寄存器
|
||||
* @param src 8 位源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_movzx_r64_r8(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_movzx_r64_r8(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -752,8 +780,8 @@ static inline void scc_mcode_amd64_movzx_r64_r8(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 64 位目标寄存器
|
||||
* @param src 16 位源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_movzx_r64_r16(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_movzx_r64_r16(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -777,8 +805,8 @@ static inline void scc_mcode_amd64_movzx_r64_r16(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_add_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_add_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -797,8 +825,8 @@ static inline void scc_mcode_amd64_add_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_add_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_add_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -816,8 +844,8 @@ static inline void scc_mcode_amd64_add_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_sub_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_sub_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -836,8 +864,8 @@ static inline void scc_mcode_amd64_sub_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_sub_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_sub_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -854,7 +882,7 @@ static inline void scc_mcode_amd64_sub_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_sub_rsp_imm32(scc_mcode_t *mcode, u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_sub_rsp_imm32(scc_mcode_t *mcode, u32 imm) {
|
||||
scc_mcode_amd64_sub_r64_imm32(mcode, SCC_AMD64_RSP, imm);
|
||||
}
|
||||
|
||||
@@ -864,7 +892,7 @@ static inline void scc_mcode_amd64_sub_rsp_imm32(scc_mcode_t *mcode, u32 imm) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_add_rsp_imm32(scc_mcode_t *mcode, u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_add_rsp_imm32(scc_mcode_t *mcode, u32 imm) {
|
||||
scc_mcode_amd64_add_r64_imm32(mcode, SCC_AMD64_RSP, imm);
|
||||
}
|
||||
|
||||
@@ -875,8 +903,8 @@ static inline void scc_mcode_amd64_add_rsp_imm32(scc_mcode_t *mcode, u32 imm) {
|
||||
* @param dst 左操作数寄存器
|
||||
* @param src 右操作数寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_cmp_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_cmp_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -895,8 +923,8 @@ static inline void scc_mcode_amd64_cmp_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_cmp_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_cmp_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -914,8 +942,8 @@ static inline void scc_mcode_amd64_cmp_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标/左操作数寄存器
|
||||
* @param src 右操作数寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_imul_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_imul_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x04; // dst in reg field
|
||||
@@ -936,9 +964,9 @@ static inline void scc_mcode_amd64_imul_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
* @param src 源寄存器或内存(此处为寄存器版本)
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_imul_r64_r64_imm32(scc_mcode_t *mcode,
|
||||
int dst, int src,
|
||||
u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_imul_r64_r64_imm32(scc_mcode_t *mcode,
|
||||
int dst, int src,
|
||||
u32 imm) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -960,8 +988,9 @@ static inline void scc_mcode_amd64_imul_r64_r64_imm32(scc_mcode_t *mcode,
|
||||
* @param src 源寄存器或内存(此处为寄存器版本)
|
||||
* @param imm 8 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_imul_r64_r64_imm8(scc_mcode_t *mcode,
|
||||
int dst, int src, u8 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_imul_r64_r64_imm8(scc_mcode_t *mcode,
|
||||
int dst, int src,
|
||||
u8 imm) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -983,8 +1012,8 @@ static inline void scc_mcode_amd64_imul_r64_r64_imm8(scc_mcode_t *mcode,
|
||||
* @param dst 目标寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_add_r32_r32(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_add_r32_r32(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x40; // REX.W=0
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -1003,8 +1032,8 @@ static inline void scc_mcode_amd64_add_r32_r32(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_add_r32_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_add_r32_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
u8 rex = 0x40;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1022,8 +1051,8 @@ static inline void scc_mcode_amd64_add_r32_imm32(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_sub_r32_r32(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_sub_r32_r32(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -1042,8 +1071,8 @@ static inline void scc_mcode_amd64_sub_r32_r32(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 左操作数寄存器
|
||||
* @param src 右操作数寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_cmp_r32_r32(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_cmp_r32_r32(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -1064,8 +1093,8 @@ static inline void scc_mcode_amd64_cmp_r32_r32(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_add_r16_r16(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_add_r16_r16(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
scc_mcode_amd64_emit_width_prefix(mcode, 2);
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
@@ -1085,8 +1114,8 @@ static inline void scc_mcode_amd64_add_r16_r16(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param imm 16 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_add_r16_imm16(scc_mcode_t *mcode, int dst,
|
||||
u16 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_add_r16_imm16(scc_mcode_t *mcode, int dst,
|
||||
u16 imm) {
|
||||
scc_mcode_amd64_emit_width_prefix(mcode, 2);
|
||||
u8 rex = 0x40;
|
||||
if (dst >= 8)
|
||||
@@ -1105,8 +1134,8 @@ static inline void scc_mcode_amd64_add_r16_imm16(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_sub_r16_r16(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_sub_r16_r16(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
scc_mcode_amd64_emit_width_prefix(mcode, 2);
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
@@ -1126,8 +1155,8 @@ static inline void scc_mcode_amd64_sub_r16_r16(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 左操作数寄存器
|
||||
* @param src 右操作数寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_cmp_r16_r16(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_cmp_r16_r16(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
scc_mcode_amd64_emit_width_prefix(mcode, 2);
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
@@ -1149,8 +1178,8 @@ static inline void scc_mcode_amd64_cmp_r16_r16(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_add_r8_r8(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_add_r8_r8(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(dst) ||
|
||||
scc_mcode_amd64_is_byte_reg_needs_rex(src);
|
||||
@@ -1173,8 +1202,8 @@ static inline void scc_mcode_amd64_add_r8_r8(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param imm 8 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_add_r8_imm8(scc_mcode_t *mcode, int dst,
|
||||
u8 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_add_r8_imm8(scc_mcode_t *mcode, int dst,
|
||||
u8 imm) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(dst);
|
||||
if (dst >= 8) {
|
||||
@@ -1197,8 +1226,8 @@ static inline void scc_mcode_amd64_add_r8_imm8(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_sub_r8_r8(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_sub_r8_r8(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(dst) ||
|
||||
scc_mcode_amd64_is_byte_reg_needs_rex(src);
|
||||
@@ -1221,8 +1250,8 @@ static inline void scc_mcode_amd64_sub_r8_r8(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 左操作数寄存器
|
||||
* @param src 右操作数寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_cmp_r8_r8(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_cmp_r8_r8(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(dst) ||
|
||||
scc_mcode_amd64_is_byte_reg_needs_rex(src);
|
||||
@@ -1248,7 +1277,7 @@ static inline void scc_mcode_amd64_cmp_r8_r8(scc_mcode_t *mcode, int dst,
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mul_r64(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mul_r64(scc_mcode_t *mcode, int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1264,7 +1293,7 @@ static inline void scc_mcode_amd64_mul_r64(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mul_r32(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mul_r32(scc_mcode_t *mcode, int src) {
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1280,7 +1309,7 @@ static inline void scc_mcode_amd64_mul_r32(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mul_r16(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mul_r16(scc_mcode_t *mcode, int src) {
|
||||
scc_mcode_amd64_emit_width_prefix(mcode, 2);
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
@@ -1297,7 +1326,7 @@ static inline void scc_mcode_amd64_mul_r16(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mul_r8(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mul_r8(scc_mcode_t *mcode, int src) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(src);
|
||||
if (src >= 8)
|
||||
@@ -1318,7 +1347,7 @@ static inline void scc_mcode_amd64_mul_r8(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_imul_r64_1op(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_imul_r64_1op(scc_mcode_t *mcode, int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1334,7 +1363,7 @@ static inline void scc_mcode_amd64_imul_r64_1op(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_imul_r32_1op(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_imul_r32_1op(scc_mcode_t *mcode, int src) {
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1350,7 +1379,7 @@ static inline void scc_mcode_amd64_imul_r32_1op(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_imul_r16_1op(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_imul_r16_1op(scc_mcode_t *mcode, int src) {
|
||||
scc_mcode_amd64_emit_width_prefix(mcode, 2);
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
@@ -1367,7 +1396,7 @@ static inline void scc_mcode_amd64_imul_r16_1op(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_imul_r8_1op(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_imul_r8_1op(scc_mcode_t *mcode, int src) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(src);
|
||||
if (src >= 8)
|
||||
@@ -1388,7 +1417,7 @@ static inline void scc_mcode_amd64_imul_r8_1op(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_div_r64(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_div_r64(scc_mcode_t *mcode, int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1404,7 +1433,7 @@ static inline void scc_mcode_amd64_div_r64(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_div_r32(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_div_r32(scc_mcode_t *mcode, int src) {
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1420,7 +1449,7 @@ static inline void scc_mcode_amd64_div_r32(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_div_r16(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_div_r16(scc_mcode_t *mcode, int src) {
|
||||
scc_mcode_amd64_emit_width_prefix(mcode, 2);
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
@@ -1437,7 +1466,7 @@ static inline void scc_mcode_amd64_div_r16(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_div_r8(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_div_r8(scc_mcode_t *mcode, int src) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(src);
|
||||
if (src >= 8)
|
||||
@@ -1458,7 +1487,7 @@ static inline void scc_mcode_amd64_div_r8(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_idiv_r64(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_idiv_r64(scc_mcode_t *mcode, int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1474,7 +1503,7 @@ static inline void scc_mcode_amd64_idiv_r64(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_idiv_r32(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_idiv_r32(scc_mcode_t *mcode, int src) {
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1490,7 +1519,7 @@ static inline void scc_mcode_amd64_idiv_r32(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_idiv_r16(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_idiv_r16(scc_mcode_t *mcode, int src) {
|
||||
scc_mcode_amd64_emit_width_prefix(mcode, 2);
|
||||
u8 rex = 0x40;
|
||||
if (src >= 8)
|
||||
@@ -1507,7 +1536,7 @@ static inline void scc_mcode_amd64_idiv_r16(scc_mcode_t *mcode, int src) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_idiv_r8(scc_mcode_t *mcode, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_idiv_r8(scc_mcode_t *mcode, int src) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(src);
|
||||
if (src >= 8)
|
||||
@@ -1531,8 +1560,8 @@ static inline void scc_mcode_amd64_idiv_r8(scc_mcode_t *mcode, int src) {
|
||||
* @param dst 目标寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_and_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_and_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -1551,8 +1580,8 @@ static inline void scc_mcode_amd64_and_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_and_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_and_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1570,8 +1599,8 @@ static inline void scc_mcode_amd64_and_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_or_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_or_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -1590,8 +1619,8 @@ static inline void scc_mcode_amd64_or_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_or_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_or_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1609,8 +1638,8 @@ static inline void scc_mcode_amd64_or_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_xor_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_xor_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -1629,8 +1658,8 @@ static inline void scc_mcode_amd64_xor_r64_r64(scc_mcode_t *mcode, int dst,
|
||||
* @param dst 目标寄存器
|
||||
* @param imm 32 位立即数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_xor_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_xor_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
u32 imm) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1651,7 +1680,7 @@ static inline void scc_mcode_amd64_xor_r64_imm32(scc_mcode_t *mcode, int dst,
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param dst 目标寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_shl_r64_1(scc_mcode_t *mcode, int dst) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_shl_r64_1(scc_mcode_t *mcode, int dst) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1668,8 +1697,8 @@ static inline void scc_mcode_amd64_shl_r64_1(scc_mcode_t *mcode, int dst) {
|
||||
* @param dst 目标寄存器
|
||||
* @param imm 移位次数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_shl_r64_imm8(scc_mcode_t *mcode, int dst,
|
||||
u8 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_shl_r64_imm8(scc_mcode_t *mcode, int dst,
|
||||
u8 imm) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1686,7 +1715,7 @@ static inline void scc_mcode_amd64_shl_r64_imm8(scc_mcode_t *mcode, int dst,
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param dst 目标寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_shr_r64_1(scc_mcode_t *mcode, int dst) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_shr_r64_1(scc_mcode_t *mcode, int dst) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1703,8 +1732,8 @@ static inline void scc_mcode_amd64_shr_r64_1(scc_mcode_t *mcode, int dst) {
|
||||
* @param dst 目标寄存器
|
||||
* @param imm 移位次数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_shr_r64_imm8(scc_mcode_t *mcode, int dst,
|
||||
u8 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_shr_r64_imm8(scc_mcode_t *mcode, int dst,
|
||||
u8 imm) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1721,7 +1750,7 @@ static inline void scc_mcode_amd64_shr_r64_imm8(scc_mcode_t *mcode, int dst,
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param dst 目标寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_sar_r64_1(scc_mcode_t *mcode, int dst) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_sar_r64_1(scc_mcode_t *mcode, int dst) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1738,8 +1767,8 @@ static inline void scc_mcode_amd64_sar_r64_1(scc_mcode_t *mcode, int dst) {
|
||||
* @param dst 目标寄存器
|
||||
* @param imm 移位次数
|
||||
*/
|
||||
static inline void scc_mcode_amd64_sar_r64_imm8(scc_mcode_t *mcode, int dst,
|
||||
u8 imm) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_sar_r64_imm8(scc_mcode_t *mcode, int dst,
|
||||
u8 imm) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1759,8 +1788,8 @@ static inline void scc_mcode_amd64_sar_r64_imm8(scc_mcode_t *mcode, int dst,
|
||||
* @param cond 条件码(0-15)
|
||||
* @param reg 目标 8 位寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_setcc_r8(scc_mcode_t *mcode, int cond,
|
||||
int reg) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_setcc_r8(scc_mcode_t *mcode, int cond,
|
||||
int reg) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(reg);
|
||||
if (reg >= 8) {
|
||||
@@ -1783,8 +1812,8 @@ static inline void scc_mcode_amd64_setcc_r8(scc_mcode_t *mcode, int cond,
|
||||
* @param cond 条件码
|
||||
* @param base 基址寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_setcc_m8(scc_mcode_t *mcode, int cond,
|
||||
int base) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_setcc_m8(scc_mcode_t *mcode, int cond,
|
||||
int base) {
|
||||
u8 rex = 0x40;
|
||||
int need_rex = scc_mcode_amd64_is_byte_reg_needs_rex(base);
|
||||
if (base >= 8) {
|
||||
@@ -1814,7 +1843,7 @@ static inline void scc_mcode_amd64_setcc_m8(scc_mcode_t *mcode, int cond,
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param rel32 32 位相对偏移
|
||||
*/
|
||||
static inline void scc_mcode_amd64_jmp_rel32(scc_mcode_t *mcode, u32 rel32) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_jmp_rel32(scc_mcode_t *mcode, u32 rel32) {
|
||||
scc_mcode_add_u8(mcode, 0xE9);
|
||||
scc_mcode_add_u32(mcode, rel32);
|
||||
}
|
||||
@@ -1826,8 +1855,8 @@ static inline void scc_mcode_amd64_jmp_rel32(scc_mcode_t *mcode, u32 rel32) {
|
||||
* @param cond 条件码
|
||||
* @param rel32 32 位相对偏移
|
||||
*/
|
||||
static inline void scc_mcode_amd64_jcc_rel32(scc_mcode_t *mcode, int cond,
|
||||
u32 rel32) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_jcc_rel32(scc_mcode_t *mcode, int cond,
|
||||
u32 rel32) {
|
||||
scc_mcode_add_u8(mcode, 0x0F);
|
||||
scc_mcode_add_u8(mcode, 0x80 + cond);
|
||||
scc_mcode_add_u32(mcode, rel32);
|
||||
@@ -1839,7 +1868,7 @@ static inline void scc_mcode_amd64_jcc_rel32(scc_mcode_t *mcode, int cond,
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param rel32 32 位相对偏移
|
||||
*/
|
||||
static inline void scc_mcode_amd64_call_rel32(scc_mcode_t *mcode, u32 rel32) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_call_rel32(scc_mcode_t *mcode, u32 rel32) {
|
||||
scc_mcode_add_u8(mcode, 0xE8);
|
||||
scc_mcode_add_u32(mcode, rel32);
|
||||
}
|
||||
@@ -1850,7 +1879,7 @@ static inline void scc_mcode_amd64_call_rel32(scc_mcode_t *mcode, u32 rel32) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param reg 目标寄存器(存储跳转地址)
|
||||
*/
|
||||
static inline void scc_mcode_amd64_jmp_r64(scc_mcode_t *mcode, int reg) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_jmp_r64(scc_mcode_t *mcode, int reg) {
|
||||
u8 rex = 0x40;
|
||||
if (reg >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1866,7 +1895,7 @@ static inline void scc_mcode_amd64_jmp_r64(scc_mcode_t *mcode, int reg) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param base 基址寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_jmp_m64(scc_mcode_t *mcode, int base) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_jmp_m64(scc_mcode_t *mcode, int base) {
|
||||
u8 rex = 0x48;
|
||||
if (base >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1888,7 +1917,7 @@ static inline void scc_mcode_amd64_jmp_m64(scc_mcode_t *mcode, int base) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param reg 目标寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_call_r64(scc_mcode_t *mcode, int reg) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_call_r64(scc_mcode_t *mcode, int reg) {
|
||||
u8 rex = 0x40;
|
||||
if (reg >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1904,7 +1933,7 @@ static inline void scc_mcode_amd64_call_r64(scc_mcode_t *mcode, int reg) {
|
||||
* @param mcode 机器码缓冲区
|
||||
* @param base 基址寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_call_m64(scc_mcode_t *mcode, int base) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_call_m64(scc_mcode_t *mcode, int base) {
|
||||
u8 rex = 0x48;
|
||||
if (base >= 8)
|
||||
rex |= 0x01;
|
||||
@@ -1925,7 +1954,7 @@ static inline void scc_mcode_amd64_call_m64(scc_mcode_t *mcode, int base) {
|
||||
*
|
||||
* @param mcode 机器码缓冲区
|
||||
*/
|
||||
static inline void scc_mcode_amd64_ret(scc_mcode_t *mcode) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_ret(scc_mcode_t *mcode) {
|
||||
scc_mcode_add_u8(mcode, 0xC3);
|
||||
}
|
||||
|
||||
@@ -1936,7 +1965,7 @@ static inline void scc_mcode_amd64_ret(scc_mcode_t *mcode) {
|
||||
*
|
||||
* @param mcode 机器码缓冲区
|
||||
*/
|
||||
static inline void scc_mcode_amd64_syscall(scc_mcode_t *mcode) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_syscall(scc_mcode_t *mcode) {
|
||||
scc_mcode_add_u8(mcode, 0x0F);
|
||||
scc_mcode_add_u8(mcode, 0x05);
|
||||
}
|
||||
@@ -1946,10 +1975,10 @@ static inline void scc_mcode_amd64_syscall(scc_mcode_t *mcode) {
|
||||
// 辅助函数:根据 base, index, scale, disp 生成 ModRM 和 SIB 字节并写入
|
||||
// 返回需要写入 disp 的字节数(0,1,4),调用者需写入 disp
|
||||
|
||||
static inline int scc_mcode_amd64_emit_sib_address(scc_mcode_t *mcode, int base,
|
||||
int index, int scale,
|
||||
u32 disp, int has_disp,
|
||||
int disp8) {
|
||||
SCC_MCODE_FUNC int scc_mcode_amd64_emit_sib_address(scc_mcode_t *mcode,
|
||||
int base, int index,
|
||||
int scale, u32 disp,
|
||||
int has_disp, int disp8) {
|
||||
// scale 编码: 0=1, 1=2, 2=4, 3=8
|
||||
u8 scale_code = 0;
|
||||
switch (scale) {
|
||||
@@ -2013,7 +2042,7 @@ static inline int scc_mcode_amd64_emit_sib_address(scc_mcode_t *mcode, int base,
|
||||
// * @param disp 位移量
|
||||
// * @param disp_size 位移大小(0=无位移,1=8位,4=32位)
|
||||
// */
|
||||
// static inline void scc_mcode_amd64_mov_r64_m64_sib(scc_mcode_t *mcode, int
|
||||
// SCC_MCODE_FUNC void scc_mcode_amd64_mov_r64_m64_sib(scc_mcode_t *mcode, int
|
||||
// dst,
|
||||
// int base, int index, int
|
||||
// scale, u32 disp, int
|
||||
@@ -2049,9 +2078,9 @@ static inline int scc_mcode_amd64_emit_sib_address(scc_mcode_t *mcode, int base,
|
||||
* @param scale 比例因子(1,2,4,8)
|
||||
* @param disp 位移量
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_r64_m64_sib(scc_mcode_t *mcode, int dst,
|
||||
int base, int index,
|
||||
int scale, u32 disp) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_r64_m64_sib(scc_mcode_t *mcode, int dst,
|
||||
int base, int index,
|
||||
int scale, u32 disp) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -2133,9 +2162,10 @@ static inline void scc_mcode_amd64_mov_r64_m64_sib(scc_mcode_t *mcode, int dst,
|
||||
* @param disp 位移量
|
||||
* @param src 源寄存器
|
||||
*/
|
||||
static inline void scc_mcode_amd64_mov_m64_sib_r64(scc_mcode_t *mcode, int base,
|
||||
int index, int scale,
|
||||
u32 disp, int src) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_mov_m64_sib_r64(scc_mcode_t *mcode,
|
||||
int base, int index,
|
||||
int scale, u32 disp,
|
||||
int src) {
|
||||
u8 rex = 0x48;
|
||||
if (src >= 8)
|
||||
rex |= 0x04;
|
||||
@@ -2214,9 +2244,9 @@ static inline void scc_mcode_amd64_mov_m64_sib_r64(scc_mcode_t *mcode, int base,
|
||||
* @param scale 比例因子
|
||||
* @param disp 位移量
|
||||
*/
|
||||
static inline void scc_mcode_amd64_lea_r64_m64_sib(scc_mcode_t *mcode, int dst,
|
||||
int base, int index,
|
||||
int scale, u32 disp) {
|
||||
SCC_MCODE_FUNC void scc_mcode_amd64_lea_r64_m64_sib(scc_mcode_t *mcode, int dst,
|
||||
int base, int index,
|
||||
int scale, u32 disp) {
|
||||
u8 rex = 0x48;
|
||||
if (dst >= 8)
|
||||
rex |= 0x04;
|
||||
|
||||
Reference in New Issue
Block a user