Page 2 of 2
Re: Kernel Paging and Linker Script
Posted: Tue May 15, 2012 3:00 pm
by vjain20
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.
Re: Kernel Paging and Linker Script
Posted: Tue May 15, 2012 7:20 pm
by serviper
. 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.
Re: Kernel Paging and Linker Script
Posted: Thu May 17, 2012 4:21 am
by vjain20
. gives VMA, so you can write
Code:
. = 0xC0100000
so that virtual addresses are all above 3GB. Then
Code:
.text : AT(0x100000)
Thanks for the reply. I will try with different VMA and LMA
Also you need a prepaged page directory to map linear addresses 0~4MB and 3GB~3GB+4MB to physical address 0~4MB.
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 ?
When jumping to C entry point, use an indirect jmp to force the CPU to use a virtual address.
. 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.
Thanks
Vaibhav Jain
Re: Kernel Paging and Linker Script
Posted: Thu May 17, 2012 4:43 am
by bluemoon
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.
CPU always see virtual address when paging is enabled(well, with a few exceptional case)
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
Posted: Thu May 17, 2012 8:07 am
by serviper
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 ?
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.
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.
If you write
to invoke main function written in C, CPU will use a signed offset to calculate address of main. So we write (in intel syntax)
These instructions specify register ecx from which the absolute offset from main is fetched. Thus we are now working on higher addresses instead of identity-mapped lower addresses.
Re: Kernel Paging and Linker Script
Posted: Fri May 18, 2012 5:44 pm
by vjain20
Thanks for the reply! I always thought the jmp and call instructions take absolute address.