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
Robert Hollencamp
[email protected]
Notes from a n00b
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: Notes from a n00b
The multiboot information and magic number do things for GRUB, check the multiboot documents.rhollencamp wrote:What exactly are the two parameters supposed to do?
Seriously? That's odd, I see no issues in the wiki tutorial code.rhollencamp wrote:loader.s calls _kmain; ld threw me an unresolved external, renaming kmain to _kmin in kernel.c works fine
That's a Bochs issue (obviously) and I don't know why that happens. I don't use Bochs.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
By the way, are you using GNU assembler or NASM?
Re: Notes from a n00b
Obviously.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...
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.
Re: Notes from a n00b
More people should start of by reading up on theory first - make sure you absorb all that information and it will be useful laterrhollencamp wrote:but it's more of a theoretical class which makes me sad
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.* 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...
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!* loader.s calls _kmain; ld threw me an unresolved external, renaming kmain to _kmin in kernel.c works fine
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)?* 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
Bad Idea (Tm)(withheld)@ gmail . com
Cheers,
Adam
-
- Posts: 3
- Joined: Tue Sep 23, 2008 9:38 pm
Re: Notes from a n00b
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 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
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 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
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).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)
- 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: Notes from a n00b
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
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.rhollencamp wrote:In the wiki, loader.s calls _kmain, while in kernel.c the function is named kmain(...)...
But apparently we don't even stay consistent to that in our own Wiki...
Every good solution is obvious once you've found it.
- 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: Notes from a n00b
Fixed that.Solar wrote:But apparently we don't even stay consistent to that in our own Wiki...