How do we use UEFI SetVirtualAddressMap
How do we use UEFI SetVirtualAddressMap
Why do OS loaders use SetVirtualAddressMap, and how to map virtual memory inside UEFI bootloader to load a higher half kernel.
-
- Member
- Posts: 5562
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How do we use UEFI SetVirtualAddressMap
Do they? Linux seems to assume the loader won't use it, but I have no idea what Windows does.devc1 wrote:Why do OS loaders use SetVirtualAddressMap,
Anyway, the intention is to make it easier for the OS to call runtime services by allowing the OS to choose their virtual addresses instead of requiring identity mapping.
devc1 wrote:and how to map virtual memory inside UEFI bootloader to load a higher half kernel.
- Use boot services to load your kernel and build your page tables
- Call ExitBootServices()
- Switch to your newly-built page tables
- Jump to your kernel
Re: How do we use UEFI SetVirtualAddressMap
That's what I was going to do anyway. I will copy the code to map the page tables in the bootloader, there is no need for a new page table since the kernel only uses the upperhalf (>128 TB).
SetVirtualaddrMap makes runtime drivers switch from physical to virtual addressing using ConvertPointer for variables, I did it after ExitBootServices but I don't think that I will really need change the mappings, so if a user mode program needs to check the time, it will syscall and simply Ill switch to the kernel's page table and runtime services will work well as I think.
SetVirtualaddrMap makes runtime drivers switch from physical to virtual addressing using ConvertPointer for variables, I did it after ExitBootServices but I don't think that I will really need change the mappings, so if a user mode program needs to check the time, it will syscall and simply Ill switch to the kernel's page table and runtime services will work well as I think.
Re: How do we use UEFI SetVirtualAddressMap
Now I'm stuck to link my assembly file to the kernel (to get the value of cr3). I'm using EDK2
-
- Member
- Posts: 5562
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How do we use UEFI SetVirtualAddressMap
Be careful with that. Two user mode programs running on two CPUs might syscall at the same time, but most runtime services can only run on one CPU at a time (and not at the same time as any other runtime services).devc1 wrote:if a user mode program needs to check the time, it will syscall and simply Ill switch to the kernel's page table and runtime services will work well as I think.
Kernel or bootloader? You shouldn't be using EDK2 for your kernel. (If you're using EDK2 with GCC, you can use GCC's inline assembly. I don't know how to link external assembly with EDK2.)devc1 wrote:Now I'm stuck to link my assembly file to the kernel (to get the value of cr3). I'm using EDK2
Re: How do we use UEFI SetVirtualAddressMap
It's just the bootloader, and btw thank you for the tip, I didn't think of that.
Re: How do we use UEFI SetVirtualAddressMap
I found out that UEFI sets it page tables as read only so I'm gonna need to make a new page table.