Page 1 of 2
Basic OS gives errors
Posted: Tue Feb 03, 2009 11:54 am
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:
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?
Re: Basic OS gives errors
Posted: Tue Feb 03, 2009 11:57 am
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
Re: Basic OS gives errors
Posted: Tue Feb 03, 2009 1:28 pm
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
Re: Basic OS gives errors
Posted: Tue Feb 03, 2009 2:38 pm
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
You forgot to mention that a console window full of warnings is ugly.
JJ
Re: Basic OS gives errors
Posted: Tue Feb 03, 2009 2:46 pm
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
Re: Basic OS gives errors
Posted: Tue Feb 03, 2009 3:49 pm
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
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.
Re: Basic OS gives errors
Posted: Tue Feb 03, 2009 4:12 pm
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
Re: Basic OS gives errors
Posted: Wed Feb 04, 2009 3:15 am
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
Re: Basic OS gives errors
Posted: Wed Feb 04, 2009 10:42 am
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.
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.
Re: Basic OS gives errors
Posted: Wed Feb 04, 2009 10:57 am
by JJeronimo
xDDunce wrote:which, again, is bad practice. the kernel should never return.
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.
Re: Basic OS gives errors
Posted: Wed Feb 04, 2009 11:13 am
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.
Re: Basic OS gives errors
Posted: Wed Feb 04, 2009 11:46 am
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.
Re: Basic OS gives errors
Posted: Wed Feb 04, 2009 12:20 pm
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
] 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.
Re: Basic OS gives errors
Posted: Wed Feb 04, 2009 12:28 pm
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).
Re: Basic OS gives errors
Posted: Wed Feb 04, 2009 1:19 pm
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;
}