OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:46 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Can I access all available memory without setting up GDT?
PostPosted: Fri Jul 22, 2022 10:29 am 
Offline

Joined: Thu Aug 08, 2019 8:21 am
Posts: 17
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:
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?


Top
 Profile  
 
 Post subject: Re: Can I access all available memory without setting up GDT
PostPosted: Fri Jul 22, 2022 10:57 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
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.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: Can I access all available memory without setting up GDT
PostPosted: Fri Jul 22, 2022 11:10 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
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!


Top
 Profile  
 
 Post subject: Re: Can I access all available memory without setting up GDT
PostPosted: Fri Jul 22, 2022 12:07 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group