OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 6:04 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 6:22 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
I've learned a lot since my last post. Now I understand the whole thing better. But I've got a big dilemma:

Pre-Info About My Setup and OS: I am using GRUB for a bootloader because I don't want to write my own, I am using Linux + GCC and QEMU. I have kernel.asm file and kernel.c file and linker.ld that links that whole thing + some other folders with #include files. That I what I have.

1.Can I enter protected mode from my kernel.asm? - >>>read Pre-Info text if you are asking yourself why I don't have a bootloader

2.When I copy/paste osdevWiki protected mode code into my kernel.asm and ofc I make sure there are no errors, I get an error saying: symbol `gdtr' undefined. When I disable that ->((((lgdt [gdtr])))) I get infinite reboot loop.

3.How do I fix that? Can I use protected mode with GRUB? How can I tell if my os is in protected mode. What do i need to write inside protected_mode_main function?

4.Offtopic question: lets say I have paging code ready now how many times do I need to initialize that paging like I initialize it once and that is forever or I need to initialize it every time I do anything???

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 6:54 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
I don't think you have read the first chapter of the GRUB page.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 7:06 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
Combuster wrote:
I don't think you have read the first chapter of the GRUB page.


I can't find anything useful in there that could help me with my problem.

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 7:18 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Homework: Read chapter 1, second paragraph, first sentence. Please cite the last six words in here for all of us, and explain what it means.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 7:29 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
Combuster wrote:
Homework: Read chapter 1, second paragraph, first sentence. Please cite the last six words in here for all of us, and explain what it means.


One major advantage of GRUB (or more precisely, a Multiboot-compliant bootloader) is that the kernel will be entered in a known state, which includes the A20 Line having been enabled, and Protected mode having been entered. This takes a lot of the pain out of writing a kernel, rendering GRUB a very useful tool for the amateur, or anyone who wants to spend more time on the intricacies of the kernel rather than worrying about these generic start-up procedures.

That means GRUB==alreadyInProtectedModeByDefault; It is good for amatuers.

OK What about other questions. Leave GRUB alone for now.

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 7:42 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Since you really want to go on to the next question instead of really understanding what's happening, I guess I'm obliged to help you with my opinion.

...

Quote:
I make sure there are no errors, I get an error
Image

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 7:46 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
Quote:
symbol `gdtr' undefined
That tells you exactly about the error.
Quote:
Offtopic question: lets say I have paging code ready now how many times do I need to initialize that paging like I initialize it once and that is forever or I need to initialize it every time I do anything???
I just can't understand what are you asking about. BTW, triple question marks won't make it clear.
Quote:
How do I fix that?
RTFM. Not the wiki, go grab a copy of Intel manuals, they won't bite you and don't make you read them all, just use the table of contents.

_________________
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay


Top
 Profile  
 
 Post subject: Re: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 8:04 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
Combuster wrote:
Since you really want to go on to the next question instead of really understanding what's happening, I guess I'm obliged to help you with my opinion.

...

Quote:
I make sure there are no errors, I get an error
Image



...make sure there are no syntax errors... that is what I meant

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 8:08 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
Roman wrote:
Quote:
symbol `gdtr' undefined
That tells you exactly about the error.
Quote:
Offtopic question: lets say I have paging code ready now how many times do I need to initialize that paging like I initialize it once and that is forever or I need to initialize it every time I do anything???
I just can't understand what are you asking about. BTW, triple question marks won't make it clear.
Quote:
How do I fix that?
RTFM. Not the wiki, go grab a copy of Intel manuals, they won't bite you and don't make you read them all, just use the table of contents.


1.I am a Superman and my brain is overclocked
2.I open code text editor
3.I start writing paging in .c code
4.I press ctrl+s, my code is saved
5.Now how do I call that paging from my kernel.c do I need to call it only once or I need to call it after every function?

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 8:26 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Remember my little test?
Quote:
Please cite the last six words
I suppose it's no use to try and help someone who both objectively and practically proved himself unable to read.


Seriously, I expect more of a programmer mindset here. OS Development is not a hobby to randomly stack things together and fire 101 unrelated expert-looking questions when you don't know the basics and fail because of that. For instance, posting that GRUB enables protected mode, then insisting on your own code that also enables protected mode just fails the basic intelligence tests. If that has to be the norm, I'm sorry but I won't be able to help with such deficiencies.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 10:08 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
Combuster wrote:
Remember my little test?
Quote:
Please cite the last six words
I suppose it's no use to try and help someone who both objectively and practically proved himself unable to read.


Seriously, I expect more of a programmer mindset here. OS Development is not a hobby to randomly stack things together and fire 101 unrelated expert-looking questions when you don't know the basics and fail because of that. For instance, posting that GRUB enables protected mode, then insisting on your own code that also enables protected mode just fails the basic intelligence tests. If that has to be the norm, I'm sorry but I won't be able to help with such deficiencies.


I did not ask you guys to give me bunch of metaphors, I asked you 5 or 6 questions that I need answer for.

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 11:06 am 
Offline
Member
Member
User avatar

Joined: Fri Jan 16, 2009 8:34 pm
Posts: 284
Location: Louisiana, USA
thehardcoreOS wrote:
1.Can I enter protected mode from my kernel.asm? - >>>read Pre-Info text if you are asking yourself why I don't have a bootloader

2.When I copy/paste osdevWiki protected mode code into my kernel.asm and ofc I make sure there are no errors, I get an error saying: symbol `gdtr' undefined. When I disable that ->((((lgdt [gdtr])))) I get infinite reboot loop.

3.How do I fix that? Can I use protected mode with GRUB? How can I tell if my os is in protected mode. What do i need to write inside protected_mode_main function?

4.Offtopic question: lets say I have paging code ready now how many times do I need to initialize that paging like I initialize it once and that is forever or I need to initialize it every time I do anything???


Simply put:
1. No, not with Grub
2. define gdtr... (it is a data structure)
3. See 2. Yes. Are you over 1MB, is your code SEGMENT:OFFSET? Nothing, you are in PMode.
4. Once, per page directory - (where you are once and only once)

ALSO: DO NOT COPY AND PAST CODE FROM WIKI!!! <- It is usually wrong in some way (especially if you implement it and nothing else it relies on)



You have been given great advice by some of the best OSDevers on this site, and have spit it back in their faces. Learn what you are doing and how it is done. RTFM!

_________________
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
Sortie wrote:
  • Don't play the role of an operating systems developer, be one.
  • Be truly afraid of undefined [behavior].
  • Your operating system should be itself, not fight what it is.


Top
 Profile  
 
 Post subject: Re: Protected Mode & Errors & Question
PostPosted: Fri Aug 28, 2015 11:25 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
BASICFreak wrote:
thehardcoreOS wrote:
1.Can I enter protected mode from my kernel.asm? - >>>read Pre-Info text if you are asking yourself why I don't have a bootloader

2.When I copy/paste osdevWiki protected mode code into my kernel.asm and ofc I make sure there are no errors, I get an error saying: symbol `gdtr' undefined. When I disable that ->((((lgdt [gdtr])))) I get infinite reboot loop.

3.How do I fix that? Can I use protected mode with GRUB? How can I tell if my os is in protected mode. What do i need to write inside protected_mode_main function?

4.Offtopic question: lets say I have paging code ready now how many times do I need to initialize that paging like I initialize it once and that is forever or I need to initialize it every time I do anything???


Simply put:
1. No, not with Grub
2. define gdtr... (it is a data structure)
3. See 2. Yes. Are you over 1MB, is your code SEGMENT:OFFSET? Nothing, you are in PMode.
4. Once, per page directory - (where you are once and only once)

ALSO: DO NOT COPY AND PAST CODE FROM WIKI!!! <- It is usually wrong in some way (especially if you implement it and nothing else it relies on)



You have been given great advice by some of the best OSDevers on this site, and have spit it back in their faces. Learn what you are doing and how it is done. RTFM!


Thank you for giving me real answers. =D>

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot], Google [Bot], Majestic-12 [Bot] and 1161 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