Skip to content

Commit ec4d70a

Browse files
committed
relative jumps
1 parent 349bba3 commit ec4d70a

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

  • src/arch/x86_64/platform/pvh

src/arch/x86_64/platform/pvh/entry.s

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,35 @@
55

66
.code32
77

8+
.macro gotpcrel reg, sym
9+
call 2f
10+
2:
11+
pop eax
12+
3:
13+
.att_syntax prefix
14+
addl $_GLOBAL_OFFSET_TABLE_ + (3b - 2b), %eax
15+
.intel_syntax noprefix
16+
mov \reg, dword ptr [eax + \sym@GOT]
17+
.endm
18+
819
.section .text
920
.align 4
1021
.global _start
1122
_start:
1223
mov edi, ebx
1324
cli # avoid any interrupt
1425

26+
call 2f
27+
2:
28+
pop eax
29+
3:
30+
.att_syntax prefix
31+
addl $_GLOBAL_OFFSET_TABLE_ + (3b - 2b), %eax
32+
.intel_syntax noprefix
33+
mov esp, dword ptr [eax + {stack}@GOT]
34+
35+
1536
# Initialize stack pointer
16-
mov esp, OFFSET {stack}
1737
add esp, {stack_top_offset}
1838

1939
# Move the 32-bit physical address of the Multiboot information structure into `RDI` as first argument to `rust_start`.
@@ -53,7 +73,7 @@ cpu_init:
5373
jz Linvalid # They aren't, there is no long mode.
5474

5575
# Set CR3
56-
mov eax, OFFSET {level_4_table}
76+
gotpcrel eax, {level_4_table}
5777
mov cr3, eax
5878

5979
# we need to enable PAE modus
@@ -83,11 +103,18 @@ cpu_init:
83103
or eax, (1 << 31) # enable paging
84104
mov cr0, eax
85105

86-
lgdt [{gdt_ptr}] # Load the 64-bit global descriptor table.
106+
gotpcrel eax, {gdt_ptr}
107+
108+
lgdt [eax] # Load the 64-bit global descriptor table.
109+
110+
push {kernel_code_selector}
111+
gotpcrel eax, start64
112+
push eax
113+
retf
87114
# https://github.com/llvm/llvm-project/issues/46048
88115
.att_syntax prefix
89116
# Set the code segment and enter 64-bit long mode.
90-
ljmp ${kernel_code_selector}, $start64
117+
# ljmp ${kernel_code_selector}, $start64
91118
.intel_syntax noprefix
92119

93120
# there is no long mode
@@ -106,7 +133,7 @@ start64:
106133
mov gs, eax
107134
cld
108135
# set default stack pointer
109-
movabs rsp, OFFSET {stack}
136+
mov rsp, [rip + {stack}@GOTPCREL]
110137
add rsp, {stack_top_offset}
111138

112139
# jump to the boot processors's C code

0 commit comments

Comments
 (0)