Pure C Kernel

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
kan
Posts: 19
Joined: Sat Jan 22, 2005 12:00 am
Location: India

Pure C Kernel

Post 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!
Nothings Impossible :)
Legend
Member
Member
Posts: 195
Joined: Tue Nov 02, 2004 12:00 am
Contact:

Re: Pure C Kernel

Post by Legend »

I would use a structure for the multiboot header instead of 3 seperate variables, to control alignment.
*post*
Post Reply