Beginner Questions

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.
thestew42
Member
Member
Posts: 38
Joined: Thu Jun 19, 2008 6:20 pm
Location: San Diego, CA

Beginner Questions

Post 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.
c0x
Member
Member
Posts: 26
Joined: Sun Apr 20, 2008 2:16 am

Re: Beginner Questions

Post 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..
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: Beginner Questions

Post 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:
"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 ]
thestew42
Member
Member
Posts: 38
Joined: Thu Jun 19, 2008 6:20 pm
Location: San Diego, CA

Re: Beginner Questions

Post by thestew42 »

Sorry. My bad.
thestew42
Member
Member
Posts: 38
Joined: Thu Jun 19, 2008 6:20 pm
Location: San Diego, CA

Re: Beginner Questions

Post 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.
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: Beginner Questions

Post by Combuster »

"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
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: Beginner Questions

Post 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
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Beginner Questions

Post by Korona »

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].
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Re: Beginner Questions

Post 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.
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Beginner Questions

Post 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.
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: Beginner Questions

Post 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
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: Beginner Questions

Post 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.
Free energy is indeed evil for it absorbs the light.
thestew42
Member
Member
Posts: 38
Joined: Thu Jun 19, 2008 6:20 pm
Location: San Diego, CA

Re: Beginner Questions

Post by thestew42 »

Ok, thanks.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Beginner Questions

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