Thanks a lot for the explanation! I did not think about how grub would behave.I am wondering how linux does it. AFAIK
it is linked to 0xC0000000 and loaded at1MB.
Kernel Paging and Linker Script
Re: Kernel Paging and Linker Script
- Thanks
Vaibhav jain
Vaibhav jain
Re: Kernel Paging and Linker Script
. gives VMA, so you can write
so that virtual addresses are all above 3GB. Then
gives LMA at 1MB.
Also you need a prepaged page directory to map linear addresses 0~4MB and 3GB~3GB+4MB to physical address 0~4MB.
When jumping to C entry point, use an indirect jmp to force the CPU to use a virtual address.
Code: Select all
. = 0xC0100000
Code: Select all
.text : AT(0x100000)
Also you need a prepaged page directory to map linear addresses 0~4MB and 3GB~3GB+4MB to physical address 0~4MB.
When jumping to C entry point, use an indirect jmp to force the CPU to use a virtual address.
Re: Kernel Paging and Linker Script
Thanks for the reply. I will try with different VMA and LMA. gives VMA, so you can write
Code:
. = 0xC0100000
so that virtual addresses are all above 3GB. Then
Code:
.text : AT(0x100000)
This means that I will have to write all the code for setting up GDT and page tables in assembly and all the addresses would beAlso you need a prepaged page directory to map linear addresses 0~4MB and 3GB~3GB+4MB to physical address 0~4MB.
subtracted by 0xC0000000 before paging is enabled. Am I right ?
. Could you please explain this jumping using indirect jmp to force theWhen jumping to C entry point, use an indirect jmp to force the CPU to use a virtual address.
CPU to use a virtual address. I didn't understand what you mean by indirect jump.
Thanks
Vaibhav Jain
- Thanks
Vaibhav jain
Vaibhav jain
Re: Kernel Paging and Linker Script
CPU always see virtual address when paging is enabled(well, with a few exceptional case)vjain20 wrote:. Could you please explain this jumping using indirect jmp to force the
CPU to use a virtual address. I didn't understand what you mean by indirect jump.
By doing that jump you jump from low address, which coincidentally identity mapped, to a higher address which virtual address differ with physical address.
For example
Code: Select all
PHYADDR=00100XXX VADDR=00100XXX EIP=00100XXX jmp ecx (ecx = C0100XXX)
...
PHYADDR=00100XXX VADDR=C0100XXX EIP=C0100XXX execution continue here.
Re: Kernel Paging and Linker Script
No need to subtract all the addresses by 3GB. Actually we will enable paging immediately after the bootloader hands over control to the kernel, but before we enter the first C function we will keep using identity-mapped lower virtual addresses. Of course the initial page directory must be defined somewhere in the data section of the kernel image.This means that I will have to write all the code for setting up GDT and page tables in assembly and all the addresses would be
subtracted by 0xC0000000 before paging is enabled. Am I right ?
If you writeCould you please explain this jumping using indirect jmp to force the CPU to use a virtual address. I didn't understand what you mean by indirect jump.
Code: Select all
call main
Code: Select all
mov ecx, main
jmp ecx
Re: Kernel Paging and Linker Script
Thanks for the reply! I always thought the jmp and call instructions take absolute address.
- Thanks
Vaibhav jain
Vaibhav jain