Page 1 of 1

Notes from a n00b

Posted: Tue Sep 23, 2008 9:48 pm
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]

Re: Notes from a n00b

Posted: Tue Sep 23, 2008 10:11 pm
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?

Re: Notes from a n00b

Posted: Wed Sep 24, 2008 1:49 am
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.

Re: Notes from a n00b

Posted: Wed Sep 24, 2008 1:58 am
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

Re: Notes from a n00b

Posted: Wed Sep 24, 2008 12:05 pm
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

Re: Notes from a n00b

Posted: Wed Sep 24, 2008 12:08 pm
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).

Re: Notes from a n00b

Posted: Wed Sep 24, 2008 3:56 pm
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 :)

Re: Notes from a n00b

Posted: Thu Sep 25, 2008 2:01 am
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...

Re: Notes from a n00b

Posted: Thu Sep 25, 2008 4:33 am
by Combuster
Solar wrote:But apparently we don't even stay consistent to that in our own Wiki...
Fixed that.