Notes from a n00b

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
rhollencamp
Posts: 3
Joined: Tue Sep 23, 2008 9:38 pm

Notes from a n00b

Post by rhollencamp »

I've always been interested in OS development and decided to play around with it a little. I'm taking an OS Dev course from Penn State, but it's more of a theoretical class which makes me sad :(

Anyway, I'm a fairly strong programmer and am very knowledgable about linux/posix. Here are some of the things I ran into while going through the barebones tutorial:

* using -Werror to compile kernel.c causes two errors (gcc4.3.2) because you don't use the two parameters passed to kmain. What exactly are the two parameters supposed to do? removing them from kernel.c (void _kmain()) and removing the two push's from loader.s works fine...

* loader.s calls _kmain; ld threw me an unresolved external, renaming kmain to _kmin in kernel.c works fine

* when I ran bochs, it didn't immediately boot up grub; it came up with a menu. One thing that I had to do was specify a keymap; if you don't it won't let you type. I used the keymap /usr/share/bochs/keymaps/x11-pc-us.map

I considered adding notes to the wiki mentioning these things, but decided to consult the forum first since I am a little new to this area of development :P

Robert Hollencamp
[email protected]
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Notes from a n00b

Post by Troy Martin »

rhollencamp wrote:What exactly are the two parameters supposed to do?
The multiboot information and magic number do things for GRUB, check the multiboot documents.
rhollencamp wrote:loader.s calls _kmain; ld threw me an unresolved external, renaming kmain to _kmin in kernel.c works fine
Seriously? That's odd, I see no issues in the wiki tutorial code.
rhollencamp wrote:when I ran bochs, it didn't immediately boot up grub; it came up with a menu. One thing that I had to do was specify a keymap; if you don't it won't let you type. I used the keymap /usr/share/bochs/keymaps/x11-pc-us.map
That's a Bochs issue (obviously) and I don't know why that happens. I don't use Bochs.

By the way, are you using GNU assembler or NASM?
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Notes from a n00b

Post by Solar »

rhollencamp wrote:* using -Werror to compile kernel.c causes two errors (gcc4.3.2) because you don't use the two parameters passed to kmain. What exactly are the two parameters supposed to do? removing them from kernel.c (void _kmain()) and removing the two push's from loader.s works fine...
Obviously.

The C code in kernel.c reads "/* Write your kernel here. */". Originally, that was the only line in there. It is assumed that the code you'd add here does check the Multiboot magic number (sanity check), and uses the Multiboot Data pointer to access the data contained therein (e.g. available memory, boot device, modules loaded etc.). This is beyond the scope of a "bare bones" tutorial, thus it was not included.
Every good solution is obvious once you've found it.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Notes from a n00b

Post by AJ »

rhollencamp wrote:but it's more of a theoretical class which makes me sad :(
More people should start of by reading up on theory first - make sure you absorb all that information and it will be useful later :)
* using -Werror to compile kernel.c causes two errors (gcc4.3.2) because you don't use the two parameters passed to kmain. What exactly are the two parameters supposed to do? removing them from kernel.c (void _kmain()) and removing the two push's from loader.s works fine...
Simply remove the variable names from the kmain function prototype: function(int, int) instead of function(int name1, int name2). You can add the variable names back in again once you need them. The reason for this warning is that GCC thinks you have created a function with unnecessary params. This would normally be a warning FYI. Whatever you do, do not remove the -Werror flag - never allow your kernel to be tested if it compiled with warnings.
* loader.s calls _kmain; ld threw me an unresolved external, renaming kmain to _kmin in kernel.c works fine
As Troy Martin says, this is odd. The only reason I can think is that you named _kmain _kmin in the loader.s file - an assembler should not mangle / prefix names!
* when I ran bochs, it didn't immediately boot up grub; it came up with a menu. One thing that I had to do was specify a keymap; if you don't it won't let you type. I used the keymap /usr/share/bochs/keymaps/x11-pc-us.map
Can you post your bochsrc file here (in code tags)? Also, could you say how you start Bochs (icon from file association or from the command line - if so, what command line)?
(withheld)@ gmail . com
Bad Idea (Tm)

Cheers,
Adam
rhollencamp
Posts: 3
Joined: Tue Sep 23, 2008 9:38 pm

Re: Notes from a n00b

Post by rhollencamp »

I'm using GNU as; I figured that since that's what I'll have to use for inline asm in gcc, might as well use that everywhere else to try and make everything uniform.

About the _kmain: typo on my part, my bad. I meant _kmain. In the wiki, loader.s calls _kmain, while in kernel.c the function is named kmain(...); I wasn't sure if this was how gcc exported function names or what, but I'm guessing not since it only works if they both have the same name (I'm using simply kmain at the moment in both loader.s and kernel.c)

as far as bochs goes, for whatever reason it works fine now without a keymap :P I think the problem was I switched workspaces (to look at wiki to see what the boot line for grub was) and bochs couldn't get keyboard focus back

Robert
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Notes from a n00b

Post by JamesM »

rhollencamp wrote:About the _kmain: typo on my part, my bad. I meant _kmain. In the wiki, loader.s calls _kmain, while in kernel.c the function is named kmain(...); I wasn't sure if this was how gcc exported function names or what, but I'm guessing not since it only works if they both have the same name (I'm using simply kmain at the moment in both loader.s and kernel.c)
DJGPP and GCC on cygwin expects all C identifiers to be prepended by underscores by default. GCC on any normal linux distro does not. The behaviour can be changed by using the --fno-leading-underscores flag, if I recall correctly (the flag name may be a bit off).
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: Notes from a n00b

Post by Combuster »

Which is why people should use a cross-compiler, so you get the same results regardless of wether you're running linux or windows :)
"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
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Notes from a n00b

Post by Solar »

rhollencamp wrote:In the wiki, loader.s calls _kmain, while in kernel.c the function is named kmain(...)...
This bothers me. The whole thing of underscore prefixing is constantly popping up in the forum. IMHO, we have the best solution for the subject online - the GCC cross-compiler tutorial, resulting in "one size fits all" no matter what the platform is.

But apparently we don't even stay consistent to that in our own Wiki...
Every good solution is obvious once you've found it.
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: Notes from a n00b

Post by Combuster »

Solar wrote:But apparently we don't even stay consistent to that in our own Wiki...
Fixed that.
"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 ]
Post Reply