Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22033

Weird linker error gcc when following simple kernel tutorial

$
0
0

Im following this tutorial on how to make a simple bootable kernel: http://www.osdever.net/tutorials/view/writing-a-simple-c-kernel

there are the following required files in the tutorial:

kernel.csource code:

#define WHITE_TXT 0x07 // white on black textvoid 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]='';        i++;        vidmem[i]=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[i]=*message;            *message++;            i++;            vidmem[i]=WHITE_TXT;            i++;        };    };    return(1);};

kernel_start.asmsource code:

[BITS 32][global start][extern _k_main] ; this is in the c filestart:  call _k_main  cli  ; stop interrupts  hlt ; halt the CPU

link.ldsource code:

OUTPUT_FORMAT("binary")ENTRY(start)SECTIONS{  .text  0x100000 : {    code = .; _code = .; __code = .;    *(.text)    . = ALIGN(4096);  }  .data  : {    data = .; _data = .; __data = .;    *(.data)    . = ALIGN(4096);  }  .bss  :  {    bss = .; _bss = .; __bss = .;    *(.bss)    . = ALIGN(4096);  }  end = .; _end = .; __end = .;}

The instructions to compile it are:

nasm -f aout kernel_start.asm -o ks.ogcc -c kernel.c -o kernel.old -T link.ld -o kernel.bin ks.o kernel.o

i am able to successfully execute the first two lines:

nasm -f aout kernel_start.asm -o ks.ogcc -c kernel.c -o kernel.o

then when i try and run this line :

ld -T link.ld -o kernel.bin ks.o kernel.o

I get the error:

C:\basic_kernel>ld -T link.ld -o kernel.bin ks.o kernel.oks.o: file not recognized: File format not recognized

Does anyone know why this is and how I could fix this?I'm using windows 7 64 bit


Viewing all articles
Browse latest Browse all 22033

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>