Using GDT to Set Up Paging

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
shad

Using GDT to Set Up Paging

Post by shad »

Right now i have the base 40100000 in the gdt so i can link my kernel at 0xC0000000, the problem is when i try to map and enable paging, and all that good stuff, it says running in bogus memory. Are there any tutorials that continue from Tim's on using the GDT to set up paging?
pskyboy

Re:Using GDT to Set Up Paging

Post by pskyboy »

Hey,

Your not the only one having trouble eith this. I guess you have been reading the Memory mapping thread. I still haven't figured out how to get it to work yet. What i have realised though is u have to jump in to a basic PMode and then set up the GDT with a base of 0x40100000 before jumping to your kernel. This is because you need the 32Bit LGDT command to point to the GDT properly when the base is 0x40100000.

Peter
shad

Re:Using GDT to Set Up Paging

Post by shad »

Yup. Although in Tim's tutorial it says the address is 0x41000000, but that doesnt work out on paper or in the real thing. Its 0x40100000. Anyway.. Im past the asm part. Im in C (thank god.) But i cant seem to initialize paging correctly so i can switch my GDT back to base 0. I wish Tim's tut went a little farther into explaining that...
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Using GDT to Set Up Paging

Post by distantvoices »

what do you want to do?

have the descriptors in the gdt be zero based.

second: look to the thread about memmanagement of pskyboy.

third: what do you want to do with the gdt in relation to setting up paging?
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
shad

Re:Using GDT to Set Up Paging

Post by shad »

The GDT base addrs being a virt to phys conversion so i can link at 0xC0000000. But that already works. Now im trying to map it rightfully.
pskyboy

Re:Using GDT to Set Up Paging

Post by pskyboy »

When you say you have got it to work. What exactky have you got to work, Loading a kernel at 1Mb but jumping to it ny jumping to 3Gb? If you have got this to work can i have a look at your source?

Cheers
Peter
pskyboy

Re:Using GDT to Set Up Paging

Post by pskyboy »

Hey Shad

I finally got it working. Its not that difficult actually but its a little subtlty that got me. Where are you having trouble with yours and ill see if i can find the problem. or upload the code if you can and ill have a look. The basic layout for doing it is.

Put the base into the GDT so 0x40100000 base if you are mapping to 3Gb.

Then enable the GDT as normal using the physicl address of the GDT tables in the GDT pointer.

Then and this is what was causing my all the trouble, when you do the jump to set the CS you need to do a far jump and you do this by

jmp DWORD code_sel:addr

Then you should be able to carry on as per normal as you are no in protected mode. So after you have set the DS and anythign else you do after PMODE just do a jmp to your kernel. If at 3GB do this

jmp CODE_SEL:0xC0000000

and that shoudl work
shad

Re:Using GDT to Set Up Paging

Post by shad »

Yup, thats the part i had working.. lol. What i didnt have working was after i was in the kernel (pmode) and trying to virtually map it to 0xC0000000 so that i could set the gdt base back to 0. Have you mapped yours yet? Are you going to map yours?
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Using GDT to Set Up Paging

Post by distantvoices »

Gosh, why don't you install two gdt descriptors more which are zero-based or build a new gdt which is for use in paged environment which contains zerobased descriptors. you can switch gdt by using lgdt [gdtrptr] in pmode. After this, jump to new_code_sel:$c0000000.

I don't think if it is wise to patch a descriptor the cpu has currently in use. But it can be done with the same function you use to install a descriptor. Do you have this function at hand?

stay safe.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
Post Reply