x86_64 new recompiler: properly handle cases where pccache is not within 2 GB of the beginning of the RAM array.

This commit is contained in:
OBattler
2025-05-10 06:22:56 +02:00
parent 8755768515
commit 1dd460e9a4

View File

@@ -780,8 +780,19 @@ host_x86_MOV32_REG_ABS(codeblock_t *block, int dst_reg, void *p)
codegen_alloc_bytes(block, 8);
codegen_addbyte4(block, 0x41, 0x8b, 0x84 | ((dst_reg & 7) << 3), 0x24); /*MOV dst_reg, ram_offset[R12]*/
codegen_addlong(block, ram_offset);
} else if ((ram_offset < -2147483648LL) || (ram_offset > 2147483647LL) || !(block->flags & CODEBLOCK_NO_IMMEDIATES)) {
// fatal("host_x86_MOV32_REG_ABS - out of range\n");
// void *q = p;
//uint32_t *r = NULL;
// *r = 5; /* Crash deliberately. */
codegen_alloc_bytes(block, 18);
codegen_addbyte2(block, 0x41, 0x54); /*PUSH r12*/
codegen_addbyte2(block, 0x49, 0xbc); /*MOV r12,(uintptr_t) p*/
codegen_addquad(block, (uintptr_t) p);
codegen_addbyte4(block, 0x41, 0x8b, 0x04 | ((dst_reg & 7) << 3), 0x24); /*MOV dst_reg, [R12]*/
codegen_addbyte2(block, 0x41, 0x5c); /*POP r12*/
} else {
fatal("host_x86_MOV32_REG_ABS - out of range\n");
fatal("host_x86_MOV32_REG_ABS - RAM offset = %016" PRIX64 " (p - ram = %016" PRIX64 ")\n", ram_offset, (uintptr_t) p - (uintptr_t) ram);
codegen_alloc_bytes(block, 6);
codegen_addbyte(block, 0x8b); /*MOV [p], src_reg*/
codegen_addbyte(block, 0x05 | ((dst_reg & 7) << 3));