x86: gen_gdt: add address translation if needed

When the kernel is mapped into virtual address space
that is different than the physical address space,
the dynamic GDT generation uses the virtual addresses.
However, the GDT table is required at boot before
page table is loaded where the virtual addresses are
invalid. So make sure GDT generation is using
physical addresses.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2021-02-12 12:36:49 -08:00 committed by Anas Nashif
commit d40e8ede8e

View file

@ -187,7 +187,24 @@ def main():
# x86_64 does not use descriptor for thread local storage
num_entries += 1
gdt_base = syms["_gdt"]
if "CONFIG_X86_MMU" in syms:
vm_base = syms["CONFIG_KERNEL_VM_BASE"]
vm_offset = syms["CONFIG_KERNEL_VM_OFFSET"]
sram_base = syms["CONFIG_SRAM_BASE_ADDRESS"]
if "CONFIG_SRAM_OFFSET" in syms:
sram_offset = syms["CONFIG_SRAM_OFFSET"]
else:
sram_offset = 0
# Figure out if there is any need to do virtual-to-physical
# address translation
virt_to_phys_offset = (sram_base + sram_offset) - (vm_base + vm_offset)
else:
virt_to_phys_offset = 0
gdt_base = syms["_gdt"] + virt_to_phys_offset
with open(args.output_gdt, "wb") as fp:
# The pseudo descriptor is stuffed into the NULL descriptor
@ -203,8 +220,8 @@ def main():
FLAGS_GRAN, ACCESS_RW))
if num_entries >= 5:
main_tss = syms["_main_tss"]
df_tss = syms["_df_tss"]
main_tss = syms["_main_tss"] + virt_to_phys_offset
df_tss = syms["_df_tss"] + virt_to_phys_offset
# Selector 0x18: main TSS
fp.write(create_tss_entry(main_tss, 0x67, 0))