I was trying to make a hello world kernel as follows:
kernel.asm
Code:
;States that the code is a 32 bit code
[BITS 32]
[global _start]
;Calls an external C function os_main.
[extern os_main]
_start:
call os_main
;Turns off interrupts
cli
;Halts the CPU
hlt
I compiled this code as follows:
nasm -f aout kernel.asm -o kernel_a.o
It worked fine.
Then I wrote this file:
kernel.h
Code:
#ifndef _KERNEL_H_
#define _KERNEL_H_
#define TOTAL_ROWS 25
#define TOTAL_COLUMNS 80
#define CHAR_SIZE 2
#define VIDEOMEM_ADD 0xb8000
#define WHITE_TEXT_ON_BLACK_SCREEN 0x07
#endif
kernel.c
Code:
#include "kernel.h"
void cls();
int print( char *msg, unsigned int line );
os_main()
{
cls();
print("Hello World!!\n", 0);
}
void cls()
{
char *videomemory = (char *)VIDEOMEM_ADD;
unsigned int i = 0;
while( i < (TOTAL_COLUMNS * TOTAL_ROWS * CHAR_SIZE) )
{
videomemory[i] = ' ';
++i;
videomemory[i] = WHITE_TEXT_ON_BLACK_SCREEN;
++i;
}
}
int print( char *msg, unsigned int line )
{
char *videomemory = (char *)VIDEOMEM_ADD;
unsigned int i = line * TOTAL_COLUMNS * CHAR_SIZE;
while( *msg != 0 )
{
if( '\n' == *msg)
{
++line;
i = line * TOTAL_COLUMNS * CHAR_SIZE;
++msg;
}
else
{
videomemory[i] = *msg;
++msg;
++i;
videomemory[i] = WHITE_TEXT_ON_BLACK_SCREEN;
++i;
}
}
return 1;
}
I compiled this as follows:
gcc -c kernel.c
Then I linked the both the .o files:
ld kernel.o kernel_a.o -o kernel.bin
Then I copied this to /boot folder and created a new entry in GRUB as follows along with existing one:
title Fedora Core 1 (2.4.22-1.2115.nptl)
root (hd0,6)
kernel /vmlinuz-2.4.22-1.2115.nptl ro root=LABEL=/ hdc=ide-scsi rhgb
initrd /initrd-2.4.22-1.2115.nptl.img
title Windows XP Professional SP2
rootnoverify (hd0,0)
chainloader +1
title My Kernel
root (hd0,6)
kernel /vmlinuz.mykernel
and I booted the kernel with My Kernel. At that time it gave me the error as:
Error 13: Invalid or unsupported executable format
I am not able to get, why this error is coming. I also tried searching but could not get much info. Please assist.