Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird linker error gcc when following simple kernel tutorial
    text
    copied!<p>Im following this tutorial on how to make a simple bootable kernel: <a href="http://www.osdever.net/tutorials/view/writing-a-simple-c-kernel" rel="nofollow">http://www.osdever.net/tutorials/view/writing-a-simple-c-kernel</a></p> <p>there are the following required files in the tutorial:</p> <p>kernel.c source code:</p> <pre><code>#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 &lt; (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); }; </code></pre> <p>kernel_start.asm source code: </p> <pre><code>[BITS 32] [global start] [extern _k_main] ; this is in the c file start: call _k_main cli ; stop interrupts hlt ; halt the CPU </code></pre> <p>link.ld source code:</p> <pre><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 = .; } </code></pre> <p>The instructions to compile it are:</p> <pre><code>nasm -f aout kernel_start.asm -o ks.o gcc -c kernel.c -o kernel.o ld -T link.ld -o kernel.bin ks.o kernel.o </code></pre> <p>i am able to successfully execute the first two lines:</p> <pre><code>nasm -f aout kernel_start.asm -o ks.o gcc -c kernel.c -o kernel.o </code></pre> <p>then when i try and run this line :</p> <pre><code>ld -T link.ld -o kernel.bin ks.o kernel.o </code></pre> <p>I get the error:</p> <pre><code>C:\basic_kernel&gt;ld -T link.ld -o kernel.bin ks.o kernel.o ks.o: file not recognized: File format not recognized </code></pre> <p>Does anyone know why this is and how I could fix this? I'm using windows 7 64 bit</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload