Basic kernel.c not compiling correctly
-
- Member
- Posts: 83
- Joined: Tue Feb 03, 2009 11:37 am
Basic kernel.c not compiling correctly
So I'm following the guide at http://wiki.osdev.org/Bare_Bones, and the OS is crashing when I run it and I think its because of kernel.bin. My friend did the same thing as the tutorial, sent me his kernel.bin, and I used it with the rest of my files and the OS worked fine. When I use my own kernel.bin it crashes. My kernel.bin is 3kb and his is 5kb. He is using gcc on linux and I am using gcc on cygwin. Any ideas?
Re: Basic kernel.c not compiling correctly
Are you using the Cygwin GCC, or did you build a GCC Cross-Compiler?
Every good solution is obvious once you've found it.
-
- Member
- Posts: 83
- Joined: Tue Feb 03, 2009 11:37 am
Re: Basic kernel.c not compiling correctly
I'm using Cygwin GCC, I tried using versions 3 and 4 but it didn't change anything.
Re: Basic kernel.c not compiling correctly
Surprising. You followed the Bare Bones tutorial all the way through, to the point where you're actually booting the binary using GRUB?
Very surprising. Because, and I quote from the tutorial:
Very surprising. Because, and I quote from the tutorial:
You should have hit a roadblock with one of the above error messages, before you got to the point where you could have booted your kernel......you are strongly encouraged to set up a GCC Cross-Compiler, as it removes all the various toolchain-specific issues you might have ("PE operation on a non-PE file", "unsupported file format", and a number of others).
Every good solution is obvious once you've found it.
-
- Member
- Posts: 83
- Joined: Tue Feb 03, 2009 11:37 am
Re: Basic kernel.c not compiling correctly
I don't understand, what's wrong with GCC on Cygwin... The site said that's best choice for windows.
And I did get two "Unused parameter" warnings, but I got rid of the -Werror and it compiled. I don't think that's the problem...
And I did get two "Unused parameter" warnings, but I got rid of the -Werror and it compiled. I don't think that's the problem...
Re: Basic kernel.c not compiling correctly
The quote reads that the readers might have those errors, not that they will. I personally got it working myself without a cross compiler before.You should have hit a roadblock with one of the above error messages, before you got to the point where you could have booted your kernel...
gsingh2011: If you can, run your system using Bochs and post its crash log here.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: Basic kernel.c not compiling correctly
GCC for Cygwin is targeted to generate Windows executables and object files (PE format). Most people prefer to work on ELF. And any Makefile you would generate for your project is likely to be Cygwin-specific, unless you take care to make it cross-platform, reducing the chances that anyone would help you with your project. And, using Cygwin GCC, you get error messages that other people couldn't reproduce unless they're using Cygwin GCC too. That is why the Wiki recommends building a cross-compiler, to put everyone on the same footing.gsingh2011 wrote:I don't understand, what's wrong with GCC on Cygwin... The site said that's best choice for windows.
Of course you can get it to work on a "regular" Cygwin GCC setup, but in that case you should know what the difference is (PE format) and chose it willingly, as it has some impact on how your project will unfold.
Indeed it isn't, those warnings are because you didn't have any code in main() actually checking the magic number and using the multiboot data structure.And I did get two "Unused parameter" warnings, but I got rid of the -Werror and it compiled. I don't think that's the problem...
Every good solution is obvious once you've found it.
-
- Member
- Posts: 83
- Joined: Tue Feb 03, 2009 11:37 am
Re: Basic kernel.c not compiling correctly
Ok, I'll figure out how to build a compiler and use that in the future. But I doubt that it is the problem in this specific case. Here is the os.log after I typed kernel 200+5 in grub:
os.log
I'm still using Cygwin GCC for this log, but if no one can fix the problem or someone figures out that the problem is the compiler, I'll switch to a different compiler and try it.
os.log
I'm still using Cygwin GCC for this log, but if no one can fix the problem or someone figures out that the problem is the compiler, I'll switch to a different compiler and try it.
Re: Basic kernel.c not compiling correctly
@gsingh2011
When using the cross compiler in Cygwin, make sure you use:
>i586-elf-as.exe -o loader.o loader.s
>i586-elf-gcc-4.3.3.exe -o kernel.o -c kernel.c -Wextra -Werror -nostdlib -nostartfiles -nodefaultlibs
>i586-elf-ld.exe -T linker.ld -o kernel.bin loader.o kernel.o
I got a similar problem, because i was using the cross compiler GCC but not AS and LD, the generated .bin file was only about 3k and while booting reported Error 13.
hope this works for you
When using the cross compiler in Cygwin, make sure you use:
>i586-elf-as.exe -o loader.o loader.s
>i586-elf-gcc-4.3.3.exe -o kernel.o -c kernel.c -Wextra -Werror -nostdlib -nostartfiles -nodefaultlibs
>i586-elf-ld.exe -T linker.ld -o kernel.bin loader.o kernel.o
I got a similar problem, because i was using the cross compiler GCC but not AS and LD, the generated .bin file was only about 3k and while booting reported Error 13.
hope this works for you