OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:18 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: How do we use UEFI SetVirtualAddressMap
PostPosted: Fri Mar 17, 2023 1:58 pm 
Offline
Member
Member

Joined: Fri Feb 11, 2022 4:55 am
Posts: 435
Location: behind the keyboard
Why do OS loaders use SetVirtualAddressMap, and how to map virtual memory inside UEFI bootloader to load a higher half kernel.


Top
 Profile  
 
 Post subject: Re: How do we use UEFI SetVirtualAddressMap
PostPosted: Fri Mar 17, 2023 3:08 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
devc1 wrote:
Why do OS loaders use SetVirtualAddressMap,

Do they? Linux seems to assume the loader won't use it, but I have no idea what Windows does.

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.

  1. Use boot services to load your kernel and build your page tables
  2. Call ExitBootServices()
  3. Switch to your newly-built page tables
  4. Jump to your kernel


Top
 Profile  
 
 Post subject: Re: How do we use UEFI SetVirtualAddressMap
PostPosted: Fri Mar 17, 2023 3:20 pm 
Offline
Member
Member

Joined: Fri Feb 11, 2022 4:55 am
Posts: 435
Location: behind the keyboard
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.


Top
 Profile  
 
 Post subject: Re: How do we use UEFI SetVirtualAddressMap
PostPosted: Fri Mar 17, 2023 3:21 pm 
Offline
Member
Member

Joined: Fri Feb 11, 2022 4:55 am
Posts: 435
Location: behind the keyboard
Now I'm stuck to link my assembly file to the kernel (to get the value of cr3). I'm using EDK2


Top
 Profile  
 
 Post subject: Re: How do we use UEFI SetVirtualAddressMap
PostPosted: Fri Mar 17, 2023 3:32 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.

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:
Now I'm stuck to link my assembly file to the kernel (to get the value of cr3). I'm using EDK2

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.)


Top
 Profile  
 
 Post subject: Re: How do we use UEFI SetVirtualAddressMap
PostPosted: Fri Mar 17, 2023 3:35 pm 
Offline
Member
Member

Joined: Fri Feb 11, 2022 4:55 am
Posts: 435
Location: behind the keyboard
It's just the bootloader, and btw thank you for the tip, I didn't think of that.


Top
 Profile  
 
 Post subject: Re: How do we use UEFI SetVirtualAddressMap
PostPosted: Sun Mar 19, 2023 6:13 am 
Offline
Member
Member

Joined: Fri Feb 11, 2022 4:55 am
Posts: 435
Location: behind the keyboard
I found out that UEFI sets it page tables as read only so I'm gonna need to make a new page table.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 52 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group