Page 1 of 1

how bootloader boot kernel by c?

Posted: Mon May 12, 2003 10:19 am
by bgcq
i write a bootloader and copy it to a flopy,it's ok.now i want to left bootloader load a kernel file by compiled c source code?is it posible?

Re:how bootloader boot kernel by c?

Posted: Mon May 12, 2003 11:29 am
by Whatever5k
Well, if you linked your object to ELF or something that GRUB knows, it will be able to boot your kernel, yes.

Re:how bootloader boot kernel by c?

Posted: Tue May 13, 2003 4:05 am
by Pype.Clicker
the alternative is to compile your C kernel to a plain binary file (see your compiler and linker options) and to link it to a small ASM file (called a stub) that will setup the stack and call the C kernel entry point ...

This should be described in details in the FAQ of Mega-Tokyo or in BonaFide development (see .:QuickLinkz:.)

Re:how bootloader boot kernel by c?

Posted: Thu May 15, 2003 6:08 am
by Thunder
you have to compile with your compiler to .o file (object file) then you have to have linker script that shows ld linker how to make flat file and where in memory to start.

Go to osdev.neopages.net in downloads you will see some kernel examples. There will be kernel example (there will be this kerenl.ld file)

If you compile under gcc, the compiling is like that:
gcc my_kernel.c -c kernel.o

Re:how bootloader boot kernel by c?

Posted: Fri May 16, 2003 5:18 am
by bgcq
in linux platform

i write a file named test.c:
#include <stdio.h>
main()
{
printf("hello,world");
}
then i use follow command to generate obj:
gcc -c test.c
after i get test.o then i want to use follow command to generate bin:
ld test.o -o kernel.bin -oformat binary -Ttext 0x100000
but the err msg is follow,where i make a mistake?
cant open binary:no exist directory

Re:how bootloader boot kernel by c?

Posted: Fri May 16, 2003 5:38 am
by Pype.Clicker
reading the manual for ld would teach you that the correct parameter is --oformat <output-format>

as the linker didn't recognized '-oformat', it just skipped it and believed "binary" was Yet Another Input File :)

Re:how bootloader boot kernel by c?

Posted: Fri May 16, 2003 11:38 am
by df
your also using printf, which you cant use like you want to use it.

Re:how bootloader boot kernel by c?

Posted: Fri May 16, 2003 9:01 pm
by bgcq
i use -oformat-binary,it is ok,the error is i miss '-' befor binary,but printf isn't recognition,i see some stuff say use libc,how to do,where have samples?

Re:how bootloader boot kernel by c?

Posted: Sun May 18, 2003 8:53 am
by Unexpected
Hi,
How can I link an ELF with LD ?

Re:how bootloader boot kernel by c?

Posted: Sun May 18, 2003 1:26 pm
by Pype.Clicker
it depends on the object format supported by your version of LD. If it's a Linux LD, then the ELF format is the one by default. Otherwise, (i.e. if you're using DJGPP or CYGWIN), you 'll have to find a elf-version of the binutils because those environment uses COFF and the tools can't support multiple formats.

Re:how bootloader boot kernel by c?

Posted: Sun May 18, 2003 2:41 pm
by Tim
If you're on Cygwin, you'll need to link to PE (an EXE file), then convert to ELF using the objcopy program.

Re:how bootloader boot kernel by c?

Posted: Mon May 19, 2003 6:30 am
by Unexpected
I'm using DJGPP.. So I need some tools? Where can I find those?

Re:how bootloader boot kernel by c?

Posted: Mon May 19, 2003 6:44 am
by Pype.Clicker
bgcq wrote: i use -oformat-binary,it is ok,the error is i miss '-' befor binary,but printf isn't recognition,i see some stuff say use libc,how to do,where have samples?
you should read http://www.mega-tokyo.com/os/os-faq-libc.html#no_printf

there are small OS-targetted implementation of the LIBC, but i personnally chose to implement my own set of basic functions for my OS, so i don't really know where you could find one ...