Home arrow Forums
OSDEV Forums  


anonymous
Visitor

Fresh Osdever
Posts: 0
graphgraph
Karma: 0  
Loading C kernel - 2005/06/26 15:34 hi,
i want to load my C Kernel (without using any initial assembly code) using GRUB. My C Kernel looks like this :
---------------------------------------------------------------------------
#define BOOT_MAGIC 0x1BADB002
static unsigned int boot_magic =BOOT_MAGIC;
static unsigned int boot_flags =0;
static unsigned int boot_check =-(BOOT_MAGIC);

char *location = (void *)0xb8000;
int offset = 0;

void print(const char *input)
{
while(*input) switch(*input)
{
case '\n':
offset += (160 - (offset % 160));
input++;
break;
default:
location[offset++] = *input++;
location[offset++] = 7;
}
}

void clear()
{
location = (void *)0xb8000;
char *p = location;
while((int)p < 0xc0000) *p++ = 0;
}

_start()
{
clear();
print("This kernel is only half-a-screen and can print.\nHave fun.\n");
while(1);
}
----------------------------------------------------------------------------
And i compile it with gcc with following options :
------------------------------------------------------------------------
gcc -ffreestanding example.c -Ttext 0x100000 -nostdlib -oformat=elf32-i386 -o example
-----------------------------------------------------------------------------
But when i try to load it from GRUB prompt it says 'unsupported format' ! What is the problem? Do i need to add something to my kernel? When i try loading my previous kernel (using some iinitial assembly code for calling my C function) it works.
  | | The administrator has disabled public write access.
OSDEV
Community
Advertisement
   
root
Moderator

Moderator
Posts: 121
graphgraph
Karma: 1  
Re: Loading C kernel - 2005/06/26 18:35 You need to output the binary thourgh a linker (ld) script supporting the multiboot features.

I'm not on my box now, but hopefully a member will give you a sample ld script for that.

Generaly, -Ttext 0x100000 isn't enough.
  | | The administrator has disabled public write access.
anonymous
Visitor

Fresh Osdever
Posts: 0
graphgraph
Karma: 0  
Re: Loading C kernel - 2005/06/29 07:23 I'm not sure if this will help you.
It's just taken from the simple C kernel tut on bonafide..

OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0xFF800000 : {
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data : {
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
  | | The administrator has disabled public write access.
anonymous
Visitor

Fresh Osdever
Posts: 0
graphgraph
Karma: 0  
Re: Loading C kernel - 2005/08/18 08:00 Can you tell me how you have set up yur GRUB.
i need it for my purpose.

Prudhvi Krishna
  | | The administrator has disabled public write access.
bubach
User

Senior Osdever
Posts: 33
graphgraph
Karma: 0  
Re: Loading C kernel - 2005/08/22 09:20 Don't you need a assembly stub file that fixes the GRUB things before jumping to your main()?
I'm no expert on GRUB and C, but thats what I have seen people do.
  | | The administrator has disabled public write access.

A WebArticles site. Sponsored by Evoleto. Motorola V525 / Business Directory / Delaware Incorporation / Home Made Bazaar