Page 1 of 2

Beginner Questions

Posted: Sat Jun 21, 2008 9:51 am
by thestew42
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.

Re: Beginner Questions

Posted: Sat Jun 21, 2008 10:37 am
by c0x
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?
It's not the truth that you can't use interrupts in PMode. You can't use BIOS interrupts in PMode.
thestew42 wrote:Speaking of interrupts, how can you set code to process interrupts? Like for example, the keyboard.
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..

Re: Beginner Questions

Posted: Sat Jun 21, 2008 12:07 pm
by Combuster
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
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?
The answer lies in EFLAGS. the code has been posted several times, go find it.
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?
google, read the wiki respectively.
Speaking of interrupts, how can you set code to process interrupts? Like for example, the keyboard.
Again, wiki it
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?
Again, in the wiki, and even in the FAQ!
Thank you.
Thank you for doing a bit more work in advance next time :wink:

Re: Beginner Questions

Posted: Sat Jun 21, 2008 12:40 pm
by thestew42
Sorry. My bad.

Re: Beginner Questions

Posted: Sat Jun 21, 2008 1:24 pm
by thestew42
Alright. I found some information on how to get the EFLAGS:

Code: Select all

pushfl
pop eax
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.

Re: Beginner Questions

Posted: Sat Jun 21, 2008 1:34 pm
by Combuster

Re: Beginner Questions

Posted: Sat Jun 21, 2008 1:46 pm
by suthers
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

Re: Beginner Questions

Posted: Sat Jun 21, 2008 2:17 pm
by Korona
CPUID is not available on all pre-Pentium CPUs.

Re: Beginner Questions

Posted: Sat Jun 21, 2008 2:21 pm
by inflater
Good god! CPUID on a 386?! :lol:
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.

Re: Beginner Questions

Posted: Sat Jun 21, 2008 2:23 pm
by thestew42

Re: Beginner Questions

Posted: Sat Jun 21, 2008 3:37 pm
by bewing
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

Posted: Sat Jun 21, 2008 4:06 pm
by suthers
inflater wrote:Good god! CPUID on a 386?! :lol:
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.
WOW sorry, just finished exams, wasn't thinking....
Jules

Re: Beginner Questions

Posted: Sat Jun 21, 2008 7:24 pm
by Omega
I really do appreciate the link, but I don't understand why you have to be so hostile.
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.

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.

Re: Beginner Questions

Posted: Sat Jun 21, 2008 8:33 pm
by thestew42
Ok, thanks.

Re: Beginner Questions

Posted: Sun Jun 22, 2008 2:27 am
by Brendan
Hi,
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?
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.. ;)

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