Exemple #1
0
static void asm_x64_write_word32(asm_x64_t* as, int w32) {
    byte* c = asm_x64_get_cur_to_write_bytes(as, 4);
    c[0] = IMM32_L0(w32);
    c[1] = IMM32_L1(w32);
    c[2] = IMM32_L2(w32);
    c[3] = IMM32_L3(w32);
}
Exemple #2
0
STATIC void asm_x64_write_word32(asm_x64_t *as, int w32) {
    byte* c = asm_x64_get_cur_to_write_bytes(as, 4);
    if (c != NULL) {
        c[0] = IMM32_L0(w32);
        c[1] = IMM32_L1(w32);
        c[2] = IMM32_L2(w32);
        c[3] = IMM32_L3(w32);
    }
}
Exemple #3
0
static void asm_x64_write_word64(asm_x64_t* as, int64_t w64) {
    byte* c = asm_x64_get_cur_to_write_bytes(as, 8);
    c[0] = IMM32_L0(w64);
    c[1] = IMM32_L1(w64);
    c[2] = IMM32_L2(w64);
    c[3] = IMM32_L3(w64);
    c[4] = IMM64_L4(w64);
    c[5] = IMM64_L5(w64);
    c[6] = IMM64_L6(w64);
    c[7] = IMM64_L7(w64);
}
Exemple #4
0
static void asm_x64_write_r64_disp(asm_x64_t* as, int r64, int disp_r64, int disp_offset) {
    assert(disp_r64 != REG_RSP);

    if (disp_offset == 0 && disp_r64 != REG_RBP) {
        asm_x64_write_byte_1(as, MODRM_R64(r64) | MODRM_RM_DISP0 | MODRM_RM_R64(disp_r64));
    } else if (SIGNED_FIT8(disp_offset)) {
        asm_x64_write_byte_2(as, MODRM_R64(r64) | MODRM_RM_DISP8 | MODRM_RM_R64(disp_r64), IMM32_L0(disp_offset));
    } else {
        asm_x64_write_byte_1(as, MODRM_R64(r64) | MODRM_RM_DISP32 | MODRM_RM_R64(disp_r64));
        asm_x64_write_word32(as, disp_offset);
    }
}
Exemple #5
0
STATIC void asm_x64_write_r64_disp(asm_x64_t *as, int r64, int disp_r64, int disp_offset) {
    assert(disp_r64 != ASM_X64_REG_RSP);

    if (disp_r64 == ASM_X64_REG_R12) {
        // special case for r12; not fully implemented
        assert(SIGNED_FIT8(disp_offset));
        asm_x64_write_byte_3(as, MODRM_R64(r64) | MODRM_RM_DISP8 | MODRM_RM_R64(disp_r64), 0x24, IMM32_L0(disp_offset));
        return;
    }

    if (disp_offset == 0 && disp_r64 != ASM_X64_REG_RBP && disp_r64 != ASM_X64_REG_R13) {
        asm_x64_write_byte_1(as, MODRM_R64(r64) | MODRM_RM_DISP0 | MODRM_RM_R64(disp_r64));
    } else if (SIGNED_FIT8(disp_offset)) {
        asm_x64_write_byte_2(as, MODRM_R64(r64) | MODRM_RM_DISP8 | MODRM_RM_R64(disp_r64), IMM32_L0(disp_offset));
    } else {
        asm_x64_write_byte_1(as, MODRM_R64(r64) | MODRM_RM_DISP32 | MODRM_RM_R64(disp_r64));
        asm_x64_write_word32(as, disp_offset);
    }
}
Exemple #6
0
STATIC void asm_x86_write_r32_disp(asm_x86_t *as, int r32, int disp_r32, int disp_offset) {
    assert(disp_r32 != ASM_X86_REG_ESP);

    if (disp_offset == 0 && disp_r32 != ASM_X86_REG_EBP) {
        asm_x86_write_byte_1(as, MODRM_R32(r32) | MODRM_RM_DISP0 | MODRM_RM_R32(disp_r32));
    } else if (SIGNED_FIT8(disp_offset)) {
        asm_x86_write_byte_2(as, MODRM_R32(r32) | MODRM_RM_DISP8 | MODRM_RM_R32(disp_r32), IMM32_L0(disp_offset));
    } else {
        asm_x86_write_byte_1(as, MODRM_R32(r32) | MODRM_RM_DISP32 | MODRM_RM_R32(disp_r32));
        asm_x86_write_word32(as, disp_offset);
    }
}