compile user program for my os
Posted: Fri Aug 12, 2016 10:31 pm
I am writing a simple elf loader, in order to test it, I compile a program with i686-elf-gcc for my os (to test my elf loader). But it wouldn't compile.
Then I tried compiling with the normal gcc on my machine.
This time my elf loader successfully loads the executable and start executing(I guess a normal c program always starts with the C run time code), but it triggers an exception at a jmp instruction
Now that I can't use the i686-elf-gcc nor the normal gcc to compile programs for my os, what should I do ?
There is a tutorial that teaches how to build a compiler to do that http://wiki.osdev.org/OS_Specific_Toolchain
I guess at the end I will get a compiler that targets my os. but I want to understand, why i686-elf-gcc wouldn't compile it for me?
I am now very confused about these compiler-os relationship stuff, can someone clarify for me ?
Thanks in advance.
Code: Select all
int main() {
int a = 0;
a++;
return 0;
}
Code: Select all
vagrant@vagrant-ubuntu-trusty-32:~/test$ i686-elf-gcc umain.c
/home/vagrant/opt/cross/lib/gcc/i686-elf/4.8.4/../../../../i686-elf/bin/ld: cannot find crt0.o: No such file or directory
/home/vagrant/opt/cross/lib/gcc/i686-elf/4.8.4/../../../../i686-elf/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
This time my elf loader successfully loads the executable and start executing(I guess a normal c program always starts with the C run time code), but it triggers an exception at a jmp instruction
Code: Select all
0x080482c6 in ?? ()
=> 0x80482c6: jmp *0x804a008 // *0x804a008 is equal to 0, so exception occurs here
0x80482cc: add %al,(%eax)
0x80482ce: add %al,(%eax)
0x80482d0: jmp *0x804a00c
0x80482d6: push $0x0
0x80482db: jmp 0x80482c0
0x80482e0: jmp *0x804a010
0x80482e6: push $0x8
0x80482eb: jmp 0x80482c0
0x80482f0: xor %ebp,%ebp
(gdb)
0x00000000 in ?? ()
=> 0x0: Cannot access memory at address 0x0
(gdb) x/1x 0x804a008
0x804a008: 0x00000000
There is a tutorial that teaches how to build a compiler to do that http://wiki.osdev.org/OS_Specific_Toolchain
I guess at the end I will get a compiler that targets my os. but I want to understand, why i686-elf-gcc wouldn't compile it for me?
I am now very confused about these compiler-os relationship stuff, can someone clarify for me ?
Thanks in advance.