From 4b7b3e31c69ed38671aedbbee82425b39e8adcc8 Mon Sep 17 00:00:00 2001 From: acscpt <18481385+acscpt@users.noreply.github.com> Date: Wed, 15 Apr 2026 00:22:12 +0200 Subject: [PATCH 1/2] Move Linux/Windows mmap constants to the 0x70000000 band. --- asm/asm_platform.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/asm/asm_platform.h b/asm/asm_platform.h index 9a4ed9ee..520c28e1 100644 --- a/asm/asm_platform.h +++ b/asm/asm_platform.h @@ -39,12 +39,17 @@ #define K_ASM_TABLE_ADDR 0x0 /* Unused om ARM64. */ #endif #else -/* Linux and Windows. */ -#define K_BBC_MEM_RAW_ADDR 0x0f008000 -#define K_JIT_ADDR 0x06000000 -#define K_INTURBO_ADDR 0x07000000 -#define K_ASM_TABLE_ADDR 0x50000000 -#define K_JIT_TRAMPOLINES_ADDR 0x80000000 +/* Linux and Windows. System mappings (brk heap, ASLR mmap pool) can + * extend a long way above the non-PIE binary at 0x400000. Mirror the + * macOS x64 layout: place our mappings in the 0x70000000 band where + * they sit well above any plausible brk growth, well below the + * 0x7f... high-mmap pool, and within the +-2GB disp32 jump range. + */ +#define K_BBC_MEM_RAW_ADDR 0x70008000 +#define K_JIT_ADDR 0x75000000 +#define K_INTURBO_ADDR 0x76000000 +#define K_ASM_TABLE_ADDR 0x77000000 +#define K_JIT_TRAMPOLINES_ADDR 0x77800000 #endif #endif /* BEEBJIT_ASM_PLATFORM_H */ From b6494493ebc78278edf251e1c5bd70f044dc94f5 Mon Sep 17 00:00:00 2001 From: acscpt <18481385+acscpt@users.noreply.github.com> Date: Sun, 26 Apr 2026 22:21:37 +0200 Subject: [PATCH 2/2] Update test-jit.c expectations for new BBC memory base. Moving K_BBC_MEM_RAW_ADDR from 0x0f008000 to 0x70008000 (in the companion commit 4b7b3e3) changes the disp32 values that the JIT bakes into emitted code that references BBC memory. Four of the test_expect_binary cases in test-jit.c hard-code those byte sequences and need updating; each affected disp32 shifts by exactly +0x61000000, the K_BBC_MEM_RAW_ADDR delta. Comments and expected bytes adjusted accordingly. The remaining nine binary expectations reference rbp+small-disp patterns that are unaffected. --- test-jit.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test-jit.c b/test-jit.c index f8797edf..d5edf953 100644 --- a/test-jit.c +++ b/test-jit.c @@ -1080,12 +1080,12 @@ jit_test_compile_binary(void) { util_buffer_destroy(p_buf); p_binary = jit_test_get_binary(s_p_metadata, 0x3200); #if defined(__x86_64__) - /* mov r9b, BYTE PTR [r13+0x12017ffa] + /* mov r9b, BYTE PTR [r13+0x73017ffa] * shr r14b, 1 * adc al, 0x1 * adc al, BYTE PTR [rbp-0x3e] */ - p_expect = "\x45\x8a\x8d\xfa\x7f\x01\x12" + p_expect = "\x45\x8a\x8d\xfa\x7f\x01\x73" "\x41\xd0\xee" "\x14\x01" "\x12\x45\xc2"; @@ -1131,13 +1131,13 @@ jit_test_compile_binary(void) { #if defined(__x86_64__) /* movzx edx, BYTE PTR [rbp-0x10] * mov dh, BYTE PTR [rbp-0x0f] - * xor al, BYTE PTR [rdx+rcx*1+0x10008000] - * mov BYTE PTR [rdx+rcx*1+0x11008000], al + * xor al, BYTE PTR [rdx+rcx*1+0x71008000] + * mov BYTE PTR [rdx+rcx*1+0x72008000], al */ p_expect = "\x0f\xb6\x55\xf0" "\x8a\x75\xf1" - "\x32\x84\x0a\x00\x80\x00\x10" - "\x88\x84\x0a\x00\x80\x00\x11"; + "\x32\x84\x0a\x00\x80\x00\x71" + "\x88\x84\x0a\x00\x80\x00\x72"; expect_len = 21; #elif defined(__aarch64__) /* TODO: the second add y / addr check can also be eliminated. */ @@ -1244,11 +1244,11 @@ jit_test_compile_binary(void) { #if defined(__x86_64__) /* movzx edx,BYTE PTR [rbp+0x3481] * mov dh,BYTE PTR [rbp+0x3482] - * movzx eax,BYTE PTR [rdx+rbx*1+0x10008000] + * movzx eax,BYTE PTR [rdx+rbx*1+0x71008000] */ p_expect = "\x0f\xb6\x95\x81\x34\x00\x00" "\x8a\xb5\x82\x34\x00\x00" - "\x0f\xb6\x84\x1a\x00\x80\x00\x10"; + "\x0f\xb6\x84\x1a\x00\x80\x00\x71"; expect_len = 21; #elif defined(__aarch64__) /* mov x21, #0x3501 @@ -1336,7 +1336,7 @@ jit_test_compile_binary(void) { util_buffer_destroy(p_buf); p_binary = jit_test_get_binary(s_p_metadata, 0x3700); #if defined(__x86_64__) - /* mov r9b, BYTE PTR [r13+0x12017ffa] + /* mov r9b, BYTE PTR [r13+0x73017ffa] * sub al, BYTE PTR [rbp-0x40] * sbb al, BYTE PTR [rbp-0x3f] * cmc @@ -1345,7 +1345,7 @@ jit_test_compile_binary(void) { /* Uses the longer-form countdown check, so fix up p_binary. */ p_binary -= 6; p_binary += 11; - p_expect = "\x45\x8a\x8d\xfa\x7f\x01\x12" + p_expect = "\x45\x8a\x8d\xfa\x7f\x01\x73" "\x2a\x45\xc0" "\x1a\x45\xc1" "\xf5"