Can I access all available memory without setting up GDT?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
nightcrawler
Posts: 17
Joined: Thu Aug 08, 2019 8:21 am

Can I access all available memory without setting up GDT?

Post by nightcrawler »

Following 32 bit osdev samples, I managed to get interrupts (IRQ) and PIC working and as a result keyboard input is working fine.

I seem to also be able to access all 4 GB of memory, i.e this code prints `c` as expected without GDT:

Code: Select all

 char* addr = (char *)0xffffffff;
 *addr = 'c';
 print(*addr); // prints `c`
If I don't care about setting up memory access privileges and just want my kernel to access all memory freely (everything runs at ring 0) then do I really need to setup GDT?
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: Can I access all available memory without setting up GDT

Post by kzinti »

If you are in protected mode on x86 (and it sounds like you are), you are using the GDT unless you physically removed it from your CPU die. Just because you didn't set it up doesn't mean it isn't there. Presumably your bootloader loaded a GDT which you shouldn't rely on.
nullplan
Member
Member
Posts: 1766
Joined: Wed Aug 30, 2017 8:24 am

Re: Can I access all available memory without setting up GDT

Post by nullplan »

You kinda cannot set up interrupts unless you know the GDT layout, since you need to select your CS selector when creating the IDT. You cannot assume that your current CS value can be loaded because the bootloader can overwrite the GDT after loading it. Given that a GDT is typically just 3 magic numbers in a row, is there a specific reason you want to forego it?
Carpe diem!
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: Can I access all available memory without setting up GDT

Post by Octocontrabass »

You can access all memory without a GDT if you load appropriate descriptors into your segment registers before you discard the GDT.

You can't handle interrupts without a GDT since interrupt handling involves loading the CS descriptor from the GDT. Which GDT are you using for handling interrupts?
Post Reply