Basic OS gives errors

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.
gsingh2011
Member
Member
Posts: 83
Joined: Tue Feb 03, 2009 11:37 am

Basic OS gives errors

Post by gsingh2011 »

I am using the exact code for the loader.s, kernel.c, and linker.ld that you can find here:http://wiki.osdev.org/Bare_Bones. When I run the commands, I get this:
Image

I am using Cygwin on Windows XP. The commands ran in the bash file compile.sh are:

Code: Select all

cd nasm-2.06rc1
./nasm -f elf -o ../loader.o ../loader.s
cd ..
gcc-4 -o kernel.o -c kernel.c -Wall -Wextra -nostdlib
ld -T linker.ld -o kernel.bin loader.o kernel.o
Anyone know why I'm getting those errors?
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: Basic OS gives errors

Post by xDDunce »

hiya,

first thing i see is there should be an underscore infront of kmain making it _kmain, so you need to edit your loader.s to make it so.

and as for the warnings, they're just warnings. ignore them. unless you are using a strip program, they don't mean much to be honest.

if this doesnt work then i guess i missed something.

cheers,
James
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: Basic OS gives errors

Post by Combuster »

For undefined reference to kmain:
* use a GCC Cross-Compiler
* use -fno-leading-underscores
* add underscores for each c function you call from assembly
they're just warnings. ignore them.
Warnings indicate bugs, potential bugs, bad coding practice or design, so you should fix them, not ignore them. Let alone tell others to do so [-X
"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 ]
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Re: Basic OS gives errors

Post by JJeronimo »

Combuster wrote:
they're just warnings. ignore them.
Warnings indicate bugs, potential bugs, bad coding practice or design, so you should fix them, not ignore them. Let alone tell others to do so [-X
You forgot to mention that a console window full of warnings is ugly. :-)

JJ
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Basic OS gives errors

Post by AJ »

JJeronimo wrote:You forgot to mention that a console window full of warnings is ugly. :-)
Indeed - no news is good news :). I suggest using the -W flags from Solar's Makefile tutorial:

Code: Select all

-Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align \
              -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations \
              -Wredundant-decls -Wnested-externs -Winline -Wno-long-long \
              -Wconversion -Wstrict-prototypes
Cheers,
Adam

PS: If adding them to a big project, add them one at a time :wink:
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: Basic OS gives errors

Post by xDDunce »

Combuster wrote:
they're just warnings. ignore them.
Warnings indicate bugs, potential bugs, bad coding practice or design, so you should fix them, not ignore them. Let alone tell others to do so [-X
yes... i actually meant just the ones stated. i see no way of correcting them, and i doubt anyone else does without adding useless, functionless, time-wasting, space-filling code.

and before you say it... yes, i need to think more before posting.

cheers,
James.
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Re: Basic OS gives errors

Post by JJeronimo »

xDDunce wrote:
Combuster wrote:yes... i actually meant just the ones stated. i see no way of correcting them, and i doubt anyone else does without adding useless, functionless, time-wasting, space-filling code.
In this case, you are right.
Sincerely speaking, I didn't know GCC warned against unused parameters. I thought it would only warn against unused (non-parameter) local variables.

JJ
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Basic OS gives errors

Post by AJ »

xDDunce wrote:i see no way of correcting them, and i doubt anyone else does without adding useless, functionless, time-wasting, space-filling code.

Code: Select all

int main(int /* argc */, char** /* argv */) 
{
   return(0);
}
Cheers,
Adam
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: Basic OS gives errors

Post by xDDunce »

AJ wrote:
xDDunce wrote:i see no way of correcting them, and i doubt anyone else does without adding useless, functionless, time-wasting, space-filling code.

Code: Select all

int main(int /* argc */, char** /* argv */) 
{
   return(0);
}
Cheers,
Adam

which, again, is bad practice. the kernel should never return. :lol: especially if you're using C++ because of the destructors list.

also the fact that the parameters defined there are commented out so they wont be compiled, and that therefore means the variables don't actually exist. resulting in an incomplete multiboot header.

cheers,
James.
JJeronimo
Member
Member
Posts: 202
Joined: Wed Oct 18, 2006 3:29 pm

Re: Basic OS gives errors

Post by JJeronimo »

xDDunce wrote:which, again, is bad practice. the kernel should never return. :lol:
Are you sure? I think this is just an implementation detail.
The main() can be just the "bootup driver[1]", which falls out of scope once the multitasking stuff is on.
And it's not the kernel that is returning. It's just the main() function, which happens to be in the kernel binary.

JJ

[1] A driver is someone/thing that drives. Not necessary in the "device driver" sense.
User avatar
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: Basic OS gives errors

Post by xDDunce »

even so, isn't a driver just another program but with higher priviliges than just plain old user mode? just like the kernel. so returning from any main() function (be it main(), kmain() or anything similar) should not be done as it will cause a termination of the program.

cheers,
James.
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: Basic OS gives errors

Post by Combuster »

In kernel space, there is no C library, no runtime. What main does when it returns is not defined until YOU program it.
"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
xDDunce
Member
Member
Posts: 173
Joined: Tue Aug 12, 2008 4:04 pm
Contact:

Re: Basic OS gives errors

Post by xDDunce »

Combuster wrote:In kernel space, there is no C library, no runtime. What main does when it returns is not defined until YOU program it.
and by standard (standard being what the general consensus [can't spell :lol: ] does), that will be your destructors list (if using C++) which kills all global classes. which, if done unintentionaly, will cause triple faults left, right and center. so technicly, you should return when shutting down (if at all), to ensure all important data is written to disk and such. followed by the actual shutdown sequence. it's the fastest, simplest and most reliable way. and from what i see, most (if not all) tutorials do it, along with many of the open source projects i have taken a look at recently.
User avatar
abachler
Member
Member
Posts: 33
Joined: Thu Jan 15, 2009 2:21 pm

Re: Basic OS gives errors

Post by abachler »

make sure you are using the cross compiler version, as the gcc you download is not compiled as a cross compiler, you have to specificalyl recompie it to be a true cross compiler, otherwise it will mangle the function names (as it should).
quok
Member
Member
Posts: 490
Joined: Wed Oct 18, 2006 10:43 pm
Location: Kansas City, KS, USA

Re: Basic OS gives errors

Post by quok »

AJ wrote:
xDDunce wrote:i see no way of correcting them, and i doubt anyone else does without adding useless, functionless, time-wasting, space-filling code.

Code: Select all

int main(int /* argc */, char** /* argv */) 
{
   return(0);
}
Cheers,
Adam
Even better, but GCC specific:

Code: Select all

int main( int argc __attribute__((unused)), char *argv __attribute__((unused)) )
{
    return 0;
}
Post Reply