okay ... entering tutor mode.
You need to know that there are many formats for executable files, like COFF, ELF, AOUT, OBJ, PE, etc. all those are standards and informations about them are available on wotsit.
GRUB knows the ELF format and can load it correctly, but it doesn't know about other file formats. However, it does understand flat binary files that have the so-called "Multiboot header" included (look at the GRUB documentation if you need), so by asking -faout instead of -felf, you're actually generating a .bin file that GRUB will not understand correctly.
From there, you have two options:
- either you're working under windows, which uses PE/COFF as a native executable format, and your compiler/linker does not know anything about ELF formats, in which case you need to download another compiler toolchain that *will* support it. Don't ask where, i dunno.
- either you're working under linux, which uses ELF as native executable format (at least since kernel 2.2). However, the 'elf' target itself is not valid under linux. There are many variants of ELF, depending on whether you're on a 32 or 64 bits equipment or whether you're on big-endian or little-endian CPU. As there are chances you're on an Intel Pentium based system, "elf32-i386" should be the target you must use.
hope i made myself clearer this time ...
thankyou sir,
i understood the things.
now let me tell u what i did ?
my files are :
kernel_start.asm //kernel startup file which calls the kernel's main function
i created an object file of the above using nasm as
#nasm -f elf kernel_strat.asm -o ks.o
kernel.c //this is the kernel c file
i created an object file of the above using gcc as
#gcc -c kernel.c -o kernel.o
in linker script file named 'link.ld' i marked output format as 'elf32-i386'(OUTPUT_FORMAT("elf32-i386"))
and i linked those two object files using ld as follows...
#ld -N -T link.ld -o kernel.elf ks.o kernel.o
i got kernel.elf sizing 5.2 kb
i copied it into directory named kernel in the floppy and i tried to load it using grub...
unfortunately i got the same error
error 13:invalid or unsupported file format
please check the error and please do try to help me out.
=---------------8<-----------------
kernel_start.asm
////////////////
[BITS 32]
[global start]
[extern k_main] ;
start:
call k_main
cli ;
hlt ;
-------8<-----------------
kernel.c
////////////////////////////
#define WHITE_TXT 0x07 // white on black text
void k_clear_screen();
unsigned int k_printf(char *message, unsigned int line);
k_main() // like main in a normal C program
{
k_clear_screen();
k_printf("Hi!\nHow's this for a starter OS?", 0);
};
void k_clear_screen() // clear the entire text screen
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
while(i < (80*25*2))
{
vidmem
=' ';
i++;
vidmem=WHITE_TXT;
i++;
};
};
unsigned int k_printf(char *message, unsigned int line) // the message and then the line #
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
i=(line*80*2);
while(*message!=0)
{
if(*message=='\n') // check for a new line
{
line++;
i=(line*80*2);
*message++;
} else {
vidmem=*message;
*message++;
i++;
vidmem=WHITE_TXT;
i++;
};
};
return(1);
};
----------8<--------------