Page 1 of 1

is CR3 physical,linear or virtual ?

Posted: Sun Apr 23, 2017 4:36 pm
by SeeSoftware
I'm trying to use paging and i hit a road block.
im trying to load the page directory into CR3 but it tripple faults even tho i am 99% sure that the directory and the tables are correct

Here is my problem:

after loading the second stage i do following things:

Identity page 0x0 - 0x400000 (because it fills a whole table)
Map 0x100000 to 0xC0000000 (im doing higher half kernel)
set cr3 to the page directory
enable paging

load kernel into 0xc0100000 and put stack at 0xc00FFFFF

execute kernel:

kernel creates page tables and page directories (Identity page 0x0 - 0x100000 and map 0x100000 to 0xC0000000)
kernel sets cr3 to new page directory address
Tripple fault

now lets say the directory is stored at 0xc0200000 (physical address 0x300000)
do i have to set cr3 to 0xc0200000 or 0x300000 ?(i have gdt mapped from 0x0 to 0xFFFFFFFF so linear = physical)

and i didnt have problems in the second stage bootloader because its Identity maped and virtual would equal to physical

Sry for bad english it is not my first language.

Re: is CR3 physical,linear or virtual ?

Posted: Sun Apr 23, 2017 5:09 pm
by sleephacker
cr3 is supposed to be the physical address of your page directory. You should look at the logs of your emulator (or better yet, let your kernel print the exceptions to screen and loop forever) to see which exception (and error code) caused a tripple fault and look it up here, that might help to get an idea of the possible causes. Register contents can usually also be found in logs, which could be useful to check if your code actually wrote the right address to cr3.

Re: is CR3 physical,linear or virtual ?

Posted: Sun Apr 23, 2017 6:28 pm
by azblue
SeeSoftware wrote: now lets say the directory is stored at 0xc0200000 (physical address 0x300000)
do i have to set cr3 to 0xc0200000 or 0x300000 ?
0x300000

SeeSoftware wrote: linear = physical
I don't want to sound like I'm nit-picking, but you have to be very precise in your vocabulary (otherwise you just end up confusing yourself!)
Setting up flat mode means offsets = linear address; your GDT alone tells us nothing about physical addresses.
SeeSoftware wrote: (i have gdt mapped from 0x0 to 0xFFFFFFFF...
Generally we'd say we set up flat mode; I generally see "mapping" to refer to pages rather than segments.
SeeSoftware wrote: Sry for bad english it is not my first language.
I think you did pretty good; I had no trouble understanding you :)