Page 1 of 1

Pure C Kernel

Posted: Sat Jun 25, 2005 11:00 pm
by kan
hi,
can i load kernel written in pure C from GRUB (ofcourse with some inline assembly) ? someone from this board suggested me a following minimum C Kernel Code for the same pupose :
------------------------------------------------------------------------------------------
#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 use following compile options :

gcc -ffreestanding example.c -Ttext 0x100000 -nostdlib -oformat=elf32-i386 -o example
------------------------------------------------------------------------------------------
when i try to load this kernel from grub it says 'unsupported format'.
What might be the reason for grub not being able to load this kernel??
Magic number has been provided, what else do i need to add this code?
I tried compiling it in binary format(default) but i won't boot from grub!

Re: Pure C Kernel

Posted: Sat Jun 25, 2005 11:00 pm
by Legend
I would use a structure for the multiboot header instead of 3 seperate variables, to control alignment.