From 3964c936cbc12bb481de26da7bf360e188add773 Mon Sep 17 00:00:00 2001 From: Daniel Victor Date: Fri, 7 Nov 2025 18:51:13 -0300 Subject: [PATCH] [FREELDR] Add the relocator caller on realmode code (#8439) CORE-19882 --- boot/freeldr/freeldr/arch/realmode/amd64.S | 16 ++++++++++------ boot/freeldr/freeldr/arch/realmode/i386.S | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/boot/freeldr/freeldr/arch/realmode/amd64.S b/boot/freeldr/freeldr/arch/realmode/amd64.S index b1e88af37d6..1e8f172be97 100644 --- a/boot/freeldr/freeldr/arch/realmode/amd64.S +++ b/boot/freeldr/freeldr/arch/realmode/amd64.S @@ -29,15 +29,18 @@ Startup: mov byte ptr ds:[BSS_BootPartition], dh /* Setup a real mode stack */ - mov sp, word ptr ds:[stack16] + mov sp, STACK16ADDR + + /* Enable A20 address line */ + call EnableA20 + + /* Relocate FreeLdr if necessary */ + call RelocateFreeLdr /* Output first status */ mov si, offset Msg_Starting call writestr - /* Enable A20 address line */ - call EnableA20 - /* Check the CPU */ call CheckFor64BitSupport test al, al @@ -361,12 +364,13 @@ CallbackTable: .word PnpBiosGetDeviceNode .word PnpBiosGetDockStationInformation - /* 16-bit stack pointer */ + /* 16-bit stack pointer (the code must change it to the current stack pointer later) */ stack16: - .word STACK16ADDR + .word 0 #include "int386.inc" +#include "relocator.inc" #include "helpers.inc" #include "pxe.inc" #include "pnp.inc" diff --git a/boot/freeldr/freeldr/arch/realmode/i386.S b/boot/freeldr/freeldr/arch/realmode/i386.S index 2accf63ce52..41c9ad65f4b 100644 --- a/boot/freeldr/freeldr/arch/realmode/i386.S +++ b/boot/freeldr/freeldr/arch/realmode/i386.S @@ -25,11 +25,18 @@ RealModeEntryPoint: mov ss, ax /* Setup the stack */ - mov sp, word ptr ds:[stack16] + mov sp, STACK16ADDR /* Enable A20 address line */ call EnableA20 + /* Relocate FreeLdr if necessary */ + call RelocateFreeLdr + + /* Output first status */ + mov si, offset Msg_Starting + call writestr + /* Save real mode entry point in shared memory */ mov dword ptr ds:[BSS_RealModeEntry], offset switch_to_real16 @@ -54,6 +61,8 @@ RealModeEntryPoint: jmp exit_to_protected +Msg_Starting: + .ascii "Starting FreeLoader...", CR, LF, NUL /* This is the entry point from protected mode */ switch_to_real16: @@ -143,9 +152,9 @@ CallbackTable: .word PnpBiosGetDockStationInformation - /* 16-bit stack pointer */ + /* 16-bit stack pointer (the code must change it to the current stack pointer later) */ stack16: - .word STACK16ADDR + .word 0 .align 4 /* force 4-byte alignment */ @@ -191,6 +200,7 @@ rmode_idtptr: .long 0 /* Base Address */ #include "int386.inc" +#include "relocator.inc" #if defined(SARCH_PC98) #include "helpers_pc98.inc" #else