diff mbox series

[v2,4/5] x86: Compensate relocation in case of EFI

Message ID 20240814083428.3012-5-frediano.ziglio@cloud.com (mailing list archive)
State New
Headers show
Series Support EFI multiboot loading using PE binary | expand

Commit Message

Frediano Ziglio Aug. 14, 2024, 8:34 a.m. UTC
If code is loaded by EFI the loader will relocate the image
under 4GB. This causes offsets in x86 code generated by
sym_offs(SYMBOL) to be relocated too (basically they won't be
offsets from image base). In order to get wanted address
when using sym_offs an sym_esi compensate the difference
in %esi.

Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
---
 xen/arch/x86/boot/head.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
---
Changes since v1:
- Completely different way to cope with the issue, much more easier.

Comments

Jan Beulich Aug. 20, 2024, 1:04 p.m. UTC | #1
On 14.08.2024 10:34, Frediano Ziglio wrote:
> If code is loaded by EFI the loader will relocate the image
> under 4GB. This causes offsets in x86 code generated by
> sym_offs(SYMBOL) to be relocated too (basically they won't be
> offsets from image base).

In turn meaning that ...

> --- a/xen/arch/x86/boot/head.S
> +++ b/xen/arch/x86/boot/head.S
> @@ -380,7 +380,8 @@ x86_32_switch:
>          lgdt    gdt_boot_descr(%rip)
>  
>          /* Store Xen image load base address in place accessible for 32-bit code. */
> -        lea     __image_base__(%rip),%esi
> +        lea     __image_base__(%rip), %esi
> +        sub     $sym_offs(__image_base__), %esi

... the comment needs updating too then, as %esi won't necessarily hold
the load base address any longer (if I understand correctly what's going
on here).

Jan
diff mbox series

Patch

diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S
index 666e341bc5..86805389f9 100644
--- a/xen/arch/x86/boot/head.S
+++ b/xen/arch/x86/boot/head.S
@@ -380,7 +380,8 @@  x86_32_switch:
         lgdt    gdt_boot_descr(%rip)
 
         /* Store Xen image load base address in place accessible for 32-bit code. */
-        lea     __image_base__(%rip),%esi
+        lea     __image_base__(%rip), %esi
+        sub     $sym_offs(__image_base__), %esi
 
         /* Reload code selector. */
         pushq   $BOOT_CS32