Page 1 of 1

ELF LINKING PROBLEM

Posted: Fri Sep 20, 2002 11:24 am
by drizzt
I have a probably stupid problem about linking a simple kernel written in C and asm...
First of all, my boot loader put the kernel at 0000:0600h, then switch into protected mode and jump to the kernel location.

Here is my very simple asm kernel code:

[BITS 32]
[GLOBAL _start]
[EXTERN main]

; NOTE: We are already in protected mode setting up by the boot loader.

; Here is the start of the kernel code...
_start:
   ; Turn off floppy motor
   mov    dx, 0x03F2
   mov    al, 0x0C
out    dx, al

   ; Call the C main procedure
   jmp main


And here is the C program:

void clear_screen();

// C-kernel start
int main()
{
   clear_screen();
   for(;;);
}

void clear_screen()
{
   char *video_mem = (char *) 0xB8000;
   unsigned int i=0;

   while(i < 80*25*2)
   {
      video_mem=0x02; // Smile
      i++;
      video_mem=0x0E; // Yellow
      i++;
   }
}

It should fill the screen with yellow smiles, but it doesn't work... Here is my compiling script:

nasm -f elf -o kernel.o kernel.s
gcc -c main.c -o kernel_c.o
ld -Ttext 0x600 -o kernel.bin kernel.o kernel_c.o

P.S. I compile all under LINUX with gcc 2.96, ld 2.11.92.0.12 and nasm 0.98...
It seems to me very strange, because I don't see errors... and it doesn't work also if I compile the asm file in a.out format... :o

Re:ELF LINKING PROBLEM

Posted: Fri Sep 20, 2002 3:26 pm
by drizzt
ouch! it's all OK! there was really a stupid error... in the dd command!!! I didn't copy the entire kernel.bin file to the disk... sorry ::)