mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-02 00:08:43 +00:00
hv: fixup addresses in the assembly code for relocation
In cpu_primary.S - Assign %rsp in cpu_primary_start_64(), so we can call _relocate() before any references to the symbols that need to be patched - Move lidtq instruction and the IDT fixup code after _relocate() call - In code64 part, replace 'mov' with 'lea' for correct addressing - No relocation is needed in code32 part In trampoline.S: - add trampoline_spinlock_ptr pointer, so we may be able to fixup trampoline code in HV Signed-off-by: Zheng Gen <gen.zheng@intel.com> Signed-off-by: Zide Chen <zide.chen@intel.com> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
This commit is contained in:
parent
ca728fb3c5
commit
bc8b3a40f8
@ -119,15 +119,57 @@ cpu_primary_start_32:
|
||||
.global cpu_primary_start_64
|
||||
cpu_primary_start_64:
|
||||
/* save the MULTBOOT magic number & MBI */
|
||||
movl %edi, (boot_regs)
|
||||
movl %esi, (boot_regs+4)
|
||||
lea boot_regs(%rip), %rax
|
||||
movl %edi, (%rax)
|
||||
movl %esi, 4(%rax)
|
||||
|
||||
primary_start_long_mode:
|
||||
|
||||
/* Fix up the IDT desciptors */
|
||||
movl $HOST_IDT, %edx
|
||||
movl $HOST_IDT_ENTRIES, %ecx
|
||||
.LFixUpIDT_Entries:
|
||||
/* Initialize temporary stack pointer */
|
||||
lea _ld_bss_end(%rip), %rsp
|
||||
add $CPU_PAGE_SIZE,%rsp
|
||||
/* 16 = CPU_STACK_ALIGN */
|
||||
and $(~(16 - 1)),%rsp
|
||||
|
||||
/*
|
||||
* Fix up the .rela sections
|
||||
* Notes: this includes the fixup to IDT tables and temporary
|
||||
* page tables
|
||||
*/
|
||||
/*call _relocate*/
|
||||
|
||||
/* Load temportary GDT pointer value */
|
||||
lea cpu_primary32_gdt_ptr(%rip), %rbx
|
||||
lgdt (%ebx)
|
||||
|
||||
/* Set the correct long jump address */
|
||||
lea jmpbuf(%rip), %rax
|
||||
lea after(%rip), %rbx
|
||||
mov %rbx, (%rax)
|
||||
rex.w ljmp *(%rax)
|
||||
.data
|
||||
jmpbuf: .quad 0
|
||||
.word HOST_GDT_RING0_CODE_SEL
|
||||
.text
|
||||
after:
|
||||
// load all selector registers with appropriate values
|
||||
xor %edx, %edx
|
||||
lldt %dx
|
||||
movl $HOST_GDT_RING0_DATA_SEL,%eax
|
||||
mov %eax,%ss // Was 32bit POC Stack
|
||||
mov %eax,%ds // Was 32bit POC Data
|
||||
mov %eax,%es // Was 32bit POC Data
|
||||
mov %edx,%fs // Was 32bit POC Data
|
||||
mov %edx,%gs // Was 32bit POC CLS
|
||||
|
||||
/*
|
||||
* Fix up the IDT desciptors
|
||||
* The relocation delta in IDT tables has been fixed in _relocate()
|
||||
*/
|
||||
leal HOST_IDT(%rip), %edx
|
||||
movl $HOST_IDT_ENTRIES, %ecx
|
||||
|
||||
.fixup_idt_entries:
|
||||
xorl %eax, %eax
|
||||
xchgl %eax, 12(%edx) /* Set rsvd bits to 0; eax now has
|
||||
high 32 of entry point */
|
||||
@ -138,42 +180,11 @@ primary_start_long_mode:
|
||||
shr $16, %eax
|
||||
movw %ax, 6(%edx) /* Set bits 16-31 of entry point */
|
||||
addl $X64_IDT_DESC_SIZE,%edx
|
||||
loop .LFixUpIDT_Entries
|
||||
loop .fixup_idt_entries
|
||||
|
||||
/* Load IDT */
|
||||
mov $HOST_IDTR, %rcx
|
||||
lidtq (%rcx)
|
||||
|
||||
/* Load temportary GDT pointer value */
|
||||
mov $cpu_primary32_gdt_ptr, %ebx
|
||||
lgdt (%ebx)
|
||||
|
||||
/* Replace CS with the correct value should we need it */
|
||||
mov $HOST_GDT_RING0_CODE_SEL, %bx
|
||||
mov %bx, jcs
|
||||
movabsq $jmpbuf, %rax
|
||||
rex.w ljmp *(%rax)
|
||||
.data
|
||||
jmpbuf: .quad after
|
||||
jcs: .word 0
|
||||
.text
|
||||
after:
|
||||
|
||||
/* Initialize temporary stack pointer */
|
||||
movq $_ld_bss_end, %rsp
|
||||
add $CPU_PAGE_SIZE,%rsp
|
||||
/* 16 = CPU_STACK_ALIGN */
|
||||
and $(~(16 - 1)),%rsp
|
||||
|
||||
// load all selector registers with appropriate values
|
||||
xor %edx, %edx
|
||||
lldt %dx
|
||||
movl $HOST_GDT_RING0_DATA_SEL,%eax
|
||||
mov %eax,%ss // Was 32bit POC Stack
|
||||
mov %eax,%ds // Was 32bit POC Data
|
||||
mov %eax,%es // Was 32bit POC Data
|
||||
mov %edx,%fs // Was 32bit POC Data
|
||||
mov %edx,%gs // Was 32bit POC CLS
|
||||
lea HOST_IDTR(%rip), %rbx
|
||||
lidtq (%rbx)
|
||||
|
||||
/* continue with chipset level initialization */
|
||||
call bsp_boot_init
|
||||
|
@ -148,7 +148,7 @@ trampoline_start64:
|
||||
mov %eax, %gs
|
||||
|
||||
/* Obtain CPU spin-lock to serialize trampoline for different APs */
|
||||
mov $trampoline_spinlock, %rdi
|
||||
movq trampoline_spinlock_ptr(%rip), %rdi
|
||||
spinlock_obtain(%rdi)
|
||||
|
||||
/* Initialize temporary stack pointer
|
||||
@ -173,6 +173,10 @@ trampoline_start64:
|
||||
main_entry:
|
||||
.quad cpu_secondary_init /* default entry is AP start entry */
|
||||
|
||||
.global trampoline_spinlock_ptr
|
||||
trampoline_spinlock_ptr:
|
||||
.quad trampoline_spinlock
|
||||
|
||||
/* GDT table */
|
||||
.align 4
|
||||
trampoline_gdt:
|
||||
|
Loading…
Reference in New Issue
Block a user