Skip to content

Commit 843dee5

Browse files
committed
x64 NDR: Properly address the entire cpu_state struct
All missing edge cases are now handled where possible
1 parent c6ab74e commit 843dee5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/codegen_new/codegen_backend_x86-64_ops.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,11 @@ host_x86_MOV8_ABS_IMM(codeblock_t *block, void *p, uint32_t imm_data)
509509
codegen_alloc_bytes(block, 4);
510510
codegen_addbyte3(block, 0xc6, 0x45, offset); /*MOVB offset[RBP], imm_data*/
511511
codegen_addbyte(block, imm_data);
512+
} else if (offset < (1ULL << 32)) {
513+
codegen_alloc_bytes(block, 7);
514+
codegen_addbyte2(block, 0xc6, 0x85); /*MOVB offset[RBP], imm_data*/
515+
codegen_addlong(block, offset);
516+
codegen_addbyte(block, imm_data);
512517
} else {
513518
if ((uintptr_t) p >> 32)
514519
fatal("host_x86_MOV8_ABS_IMM - out of range %p\n", p);
@@ -527,6 +532,11 @@ host_x86_MOV16_ABS_IMM(codeblock_t *block, void *p, uint16_t imm_data)
527532
codegen_alloc_bytes(block, 6);
528533
codegen_addbyte4(block, 0x66, 0xc7, 0x45, offset); /*MOV offset[RBP], imm_data*/
529534
codegen_addword(block, imm_data);
535+
} else if (offset < (1ULL << 32)) {
536+
codegen_alloc_bytes(block, 8);
537+
codegen_addbyte3(block, 0x66, 0xc7, 0x85); /*MOV offset[RBP], imm_data*/
538+
codegen_addlong(block, offset);
539+
codegen_addword(block, imm_data);
530540
} else {
531541
if ((uintptr_t) p >> 32)
532542
fatal("host_x86_MOV32_ABS_IMM - out of range %p\n", p);
@@ -545,6 +555,11 @@ host_x86_MOV32_ABS_IMM(codeblock_t *block, void *p, uint32_t imm_data)
545555
codegen_alloc_bytes(block, 7);
546556
codegen_addbyte3(block, 0xc7, 0x45, offset); /*MOV offset[RBP], imm_data*/
547557
codegen_addlong(block, imm_data);
558+
} else if (offset < (1ULL << 32)) {
559+
codegen_alloc_bytes(block, 10);
560+
codegen_addbyte2(block, 0xc7, 0x85); /*MOV offset[RBP], imm_data*/
561+
codegen_addlong(block, offset);
562+
codegen_addlong(block, imm_data);
548563
} else {
549564
if ((uintptr_t) p >> 32)
550565
fatal("host_x86_MOV32_ABS_IMM - out of range %p\n", p);
@@ -566,6 +581,10 @@ host_x86_MOV8_ABS_REG(codeblock_t *block, void *p, int src_reg)
566581
if (offset >= -128 && offset < 127) {
567582
codegen_alloc_bytes(block, 3);
568583
codegen_addbyte3(block, 0x88, 0x45 | ((src_reg & 7) << 3), offset); /*MOVB offset[RBP], src_reg*/
584+
} else if (offset < (1ULL << 32)) {
585+
codegen_alloc_bytes(block, 6);
586+
codegen_addbyte2(block, 0x88, 0x85 | ((src_reg & 7) << 3)); /*MOVB offset[RBP], src_reg*/
587+
codegen_addlong(block, offset);
569588
} else {
570589
if ((uintptr_t) p >> 32)
571590
fatal("host_x86_MOV8_ABS_REG - out of range %p\n", p);
@@ -630,6 +649,10 @@ host_x86_MOV64_ABS_REG(codeblock_t *block, void *p, int src_reg)
630649
if (offset >= -128 && offset < 127) {
631650
codegen_alloc_bytes(block, 4);
632651
codegen_addbyte4(block, 0x48, 0x89, 0x45 | ((src_reg & 7) << 3), offset); /*MOV offset[RBP], src_reg*/
652+
} else if (offset < (1ULL << 32)) {
653+
codegen_alloc_bytes(block, 7);
654+
codegen_addbyte3(block, 0x48, 0x89, 0x85 | ((src_reg & 7) << 3)); /*MOV offset[RBP], src_reg*/
655+
codegen_addlong(block, offset);
633656
} else {
634657
if ((uintptr_t) p >> 32)
635658
fatal("host_x86_MOV64_ABS_REG - out of range %p\n", p);

0 commit comments

Comments
 (0)