how bootloader boot kernel by c?

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.
Post Reply
bgcq

how bootloader boot kernel by c?

Post 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?
Whatever5k

Re:how bootloader boot kernel by c?

Post by Whatever5k »

Well, if you linked your object to ELF or something that GRUB knows, it will be able to boot your kernel, yes.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:how bootloader boot kernel by c?

Post 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:.)
Thunder

Re:how bootloader boot kernel by c?

Post 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
bgcq

Re:how bootloader boot kernel by c?

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:how bootloader boot kernel by c?

Post 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 :)
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:how bootloader boot kernel by c?

Post by df »

your also using printf, which you cant use like you want to use it.
-- Stu --
bgcq

Re:how bootloader boot kernel by c?

Post 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?
Unexpected

Re:how bootloader boot kernel by c?

Post by Unexpected »

Hi,
How can I link an ELF with LD ?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:how bootloader boot kernel by c?

Post 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.
Tim

Re:how bootloader boot kernel by c?

Post 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.
Unexpected

Re:how bootloader boot kernel by c?

Post by Unexpected »

I'm using DJGPP.. So I need some tools? Where can I find those?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:how bootloader boot kernel by c?

Post 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 ...
Post Reply