Beginner Questions
Beginner Questions
I know some people say not to start with a boot loader and to just use something like GRUB, but decided to start with the boot loader to gain the experience. I just got my second stage loader working (thanks to the helpful people on this forum) and I'm now beginning to write the actual loader code. I don't want to make any big design mistakes at this point so i have a few questions.
Firstly, someone told me that I should get the CPU type to make sure that it will work in 32 bit PMode, so I guess a 386 or higher. How do actually do this? Is there some interrupt?
Next, I have heard that you cant use interrupts once in PMode. If this is so, how do access the floppy drive? How do you output to the monitor?
Speaking of interrupts, how can you set code to process interrupts? Like for example, the keyboard.
I've also seen that a common component for a boot loader is retrieving the memory map. What is this, and how do you use/get it?
Thank you.
Firstly, someone told me that I should get the CPU type to make sure that it will work in 32 bit PMode, so I guess a 386 or higher. How do actually do this? Is there some interrupt?
Next, I have heard that you cant use interrupts once in PMode. If this is so, how do access the floppy drive? How do you output to the monitor?
Speaking of interrupts, how can you set code to process interrupts? Like for example, the keyboard.
I've also seen that a common component for a boot loader is retrieving the memory map. What is this, and how do you use/get it?
Thank you.
Re: Beginner Questions
It's not the truth that you can't use interrupts in PMode. You can't use BIOS interrupts in PMode.thestew42 wrote:Next, I have heard that you cant use interrupts once in PMode. If this is so, how do access the floppy drive? How do you output to the monitor?
You have to set up the Interrupt Descriptor Table properly to handle interrupts. You can find tutorials to do this on the wiki, I think..thestew42 wrote:Speaking of interrupts, how can you set code to process interrupts? Like for example, the keyboard.
- Combuster
- 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: Beginner Questions
There's normally nothing wrong with beginner's questions, unless they are stupid questions. This one borders on that, because everything is available if you bothered to look for it: Expanded_Main_Page

The answer lies in EFLAGS. the code has been posted several times, go find it.Firstly, someone told me that I should get the CPU type to make sure that it will work in 32 bit PMode, so I guess a 386 or higher. How do actually do this? Is there some interrupt?
google, read the wiki respectively.Next, I have heard that you cant use interrupts once in PMode. If this is so, how do access the floppy drive? How do you output to the monitor?
Again, wiki itSpeaking of interrupts, how can you set code to process interrupts? Like for example, the keyboard.
Again, in the wiki, and even in the FAQ!I've also seen that a common component for a boot loader is retrieving the memory map. What is this, and how do you use/get it?
Thank you for doing a bit more work in advance next timeThank you.
Re: Beginner Questions
Sorry. My bad.
Re: Beginner Questions
Alright. I found some information on how to get the EFLAGS:
but I didn't find anything on how to tell if the processor is a 386+. I saw that the RF and VM flags were only available on the 386+, but how can you tell if they are available or not? I really have looked for this.
Code: Select all
pushfl
pop eaxRe: Beginner Questions
Couldn't you do using CPUID though?
Just set ax to 1, call CPUID then check bits 0 to 11 to check what it outputs into eax, bits 0 to 11 give id info, which will allow you to see if its 386+, so if it is capable of Protected mode.
Jules
edit: sorry combuster, I didn't see your post.
second edit: sorry, you have to make ax = Bh for the CPUID
Just set ax to 1, call CPUID then check bits 0 to 11 to check what it outputs into eax, bits 0 to 11 give id info, which will allow you to see if its 386+, so if it is capable of Protected mode.
Jules
edit: sorry combuster, I didn't see your post.
second edit: sorry, you have to make ax = Bh for the CPUID
Re: Beginner Questions
CPUID is not available on all pre-Pentium CPUs.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
Re: Beginner Questions
Good god! CPUID on a 386?! 
I've heard about very rare 80486 with cpuid,but 386? No way man.
Tomorrow i can post asm codes for detecting from 80286 to Pentium.
I've heard about very rare 80486 with cpuid,but 386? No way man.
Tomorrow i can post asm codes for detecting from 80286 to Pentium.
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English
)
Derrick operating system: http://derrick.xf.cz (Slovak and English
Re: Beginner Questions
Thanks for the link, but... no
http://www.google.com/search?hl=en&clie ... tnG=Search
http://www.google.com/search?hl=en&clie ... tnG=Search
http://www.google.com/search?hl=en&clie ... tnG=Search
http://www.google.com/search?hl=en&clie ... tnG=Search
http://www.google.com/search?hl=en&clie ... tnG=Search
http://www.google.com/search?hl=en&clie ... tnG=Search
http://www.google.com/search?hl=en&clie ... tnG=Search
http://www.google.com/search?hl=en&clie ... tnG=Search
http://www.google.com/search?hl=en&clie ... tnG=Search
I really do appreciate the link, but I don't understand why you have to be so hostile
Re: Beginner Questions
Yeah, well ... starting an OS requires doing lots of reading and searching, and unfortunately way too many people before you have shown up who refuse to use the wiki, the forum search feature, or google. So we are all pre-aggravated about it. You have several weeks of reading to do in the wiki is what it comes down to. Please read, keep track of everything that doesn't make sense, and when you have done your two weeks of reading, post your questions. I promise that we will be happy to answer questions of that type.
Re: Beginner Questions
WOW sorry, just finished exams, wasn't thinking....inflater wrote:Good god! CPUID on a 386?!
I've heard about very rare 80486 with cpuid,but 386? No way man.
Tomorrow i can post asm codes for detecting from 80286 to Pentium.
Jules
Re: Beginner Questions
Don't let it bother you. Think that he spent the time to type in google and then come here and post the link, thank him for that, and ignore the rest and he seems a pretty descent guy. He knows a crap load about OS dev, so play nice and he might actually help when he isn't too busy.I really do appreciate the link, but I don't understand why you have to be so hostile.
Now for your questions:
Do I need CPU type? Not really unless you think millions of users will use your OS, otherwise assume everyone has a 386 or better at this point. It's nice to do I guess, so that's up to you really.
How do I access floppy from Pmode? Jump to V86 or Rmode do your floppy crap then come back to Pmode. Remember, the pc industry is trying to kill the floppy drive so don't rely too much on floppy crap, try to shoot for flash drive or hdd later in dev.
Process ints? Set up IDT in assembler, link to it, and create a handler that is called, process and play.
That's it. Good Luck. Do research. Come here only when there is no other source, because you will get flamed or worse IGNORED, unfortunately.
Free energy is indeed evil for it absorbs the light.
Re: Beginner Questions
Ok, thanks.
Re: Beginner Questions
Hi,

However, I really wouldn't bother supporting 80386 CPUs as they're insanely hard to find (for testing, etc) and half of them used expanded memory (a strange arrangement that uses bank switching) instead of extended memory (i.e. normal RAM above 0x00100000).
Basically, newer CPUs added more features that improve performance, etc; and if you support a very wide variety of CPUs then you need to do a lot of "if FEATURE_SUPPORTED then FOO else BAR" work to support/use these new features (and get decent performance on modern CPUs). With this in mind, "80386 or later" is a lot of work, "80486 or later" is a little less work, "Pentium or later" is even easier, etc.
Cheers,
Brendan
IMHO the easiest way is to hook the invalid opcode exception handler and then try to execute an "80386 or later" instruction. If you get an invalid opcode exception then the CPU is too old, and if you don't then it's not..thestew42 wrote:Firstly, someone told me that I should get the CPU type to make sure that it will work in 32 bit PMode, so I guess a 386 or higher. How do actually do this?
However, I really wouldn't bother supporting 80386 CPUs as they're insanely hard to find (for testing, etc) and half of them used expanded memory (a strange arrangement that uses bank switching) instead of extended memory (i.e. normal RAM above 0x00100000).
Basically, newer CPUs added more features that improve performance, etc; and if you support a very wide variety of CPUs then you need to do a lot of "if FEATURE_SUPPORTED then FOO else BAR" work to support/use these new features (and get decent performance on modern CPUs). With this in mind, "80386 or later" is a lot of work, "80486 or later" is a little less work, "Pentium or later" is even easier, etc.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


