But enough with the rambling. I face another (incredibly newbish) problem with using ld.
Firstly, I have this code, which is jumped to by the loader right after entering protected mode, kernel.asm:
Code: Select all
[bits 32]
extern _c_main
; Jump into the main kernel
call _c_main
; Halt the CPU
cli
hlt
Code: Select all
char message[]= "C Kernel loaded.";
int c_main ()
{
char *source = message;
char *destination = (char *)0xB8000;
while (*source)
{
*destination++ = *source++;
*destination++ = 7;
}
return 0;
}
Now my problem is trying to compile the thing.
First I assemble the kernel.asm file to an object file:
Code: Select all
nasm -f coff kernel.asm -o kernel.o
Code: Select all
gcc -O3 -c kernel_c.c -o kernel_c.o
Code: Select all
ld -Ttext 0xFF800000 --oformat binary -o kernel.bin kernel.o kernel_c.o
Anyway now the main problem. I can get so far as having 2 object files, but they won't link. I get this error:
"ld: PE operations on non PE file."
I read somewhere that this was a problem with a certain version of ld, so I tried a few other versions. Other versions just gave the same thing, or actually caused a general protection fault and crashed ("ld has encountered a problem and needs to close").
I also read somewhere to try "aout" instead of "coff", but then ld complained about unknown file formats, so back to "coff" i went.
I'm guessing it's something pretty newbish I'm doing, but I've searched all over the web, read the documentation, and read other examples, and I just can't see what's wrong.
(As a side note, I'd rather do things simply from the command line like this, than use a linker script, if that can be avoided)
Thanks in advance.