I'm trying to write a small 64-bit OS, booting it via UEFI.
This means that when my code takes full control (after ExitBootServices), the processor is already in 64-bit long mode, with paging enabled.
What I want to do is substitute all UEFI generated structures (paging structures, GDT, IDT) with my own.
After successfully loading a new value in CR3 (paging structures) and in GDTR (with lgdt), to use my new GDT, I need to update the CS register. On the OSDev wiki there are tutorials to load a new GDT from 32-bit to 64-bit mode, but none on how to do it when already in 64 bit long mode.
I suppose I should use a far jump, but this code does not work (AT&T syntax):
Code: Select all
mov %rax, %cr3 # load paging structures (it works)
lgdt 6(%rcx) # load gdt (it works)
mov $100, %rsp # update stack pointer (it works)
# now what I tried unsuccessfully:
pushw $8 # new code segment selector
pushq fun # function to execute next
retfq # far return (pops address and code segment)
Thanks in advance for your help.