Page 1 of 1

Can I access all available memory without setting up GDT?

Posted: Fri Jul 22, 2022 10:29 am
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?

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

Posted: Fri Jul 22, 2022 10:57 am
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.

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

Posted: Fri Jul 22, 2022 11:10 am
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?

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

Posted: Fri Jul 22, 2022 12:07 pm
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?