Protected Mode & Errors & Question

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
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Protected Mode & Errors & Question

Post by Octacone »

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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Protected Mode & Errors & Question

Post by Combuster »

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 ]
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Protected Mode & Errors & Question

Post by Octacone »

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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Protected Mode & Errors & Question

Post by Combuster »

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 ]
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Protected Mode & Errors & Question

Post by Octacone »

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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Protected Mode & Errors & Question

Post by Combuster »

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.

...
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 ]
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Protected Mode & Errors & Question

Post by Roman »

symbol `gdtr' undefined
That tells you exactly about the error.
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.
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
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Protected Mode & Errors & Question

Post by Octacone »

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.

...
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
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Protected Mode & Errors & Question

Post by Octacone »

Roman wrote:
symbol `gdtr' undefined
That tells you exactly about the error.
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.
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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Protected Mode & Errors & Question

Post by Combuster »

Remember my little test?
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 ]
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Protected Mode & Errors & Question

Post by Octacone »

Combuster wrote:Remember my little test?
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
User avatar
BASICFreak
Member
Member
Posts: 284
Joined: Fri Jan 16, 2009 8:34 pm
Location: Louisiana, USA

Re: Protected Mode & Errors & Question

Post by BASICFreak »

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.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: Protected Mode & Errors & Question

Post by Octacone »

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
Post Reply