I am trying to follow the tutorials in this link.
When I go to the part where I start making the test.c file, I try to run the first line of compilation.
gcc -c -g -Os -march=i686 -ffreestanding -Wall -Werror test.c -o test.o
Here is the contents of test.c
__asm__(".code16\n"); __asm__("jmpl $0x0000, $main\n"); void main() { }
When I call the first compilation line, it shows me this error.
test.c:1:0: error: CPU you selected does not support x86-64 instruction set __asm__(".code16\n"); ^
Can someone tell me why this is happening? And if possible, how to fix it?
I am running Ubuntu Desktop x64, well in advance for your help.
EDIT:
I changed the first compilation line to:
gcc -c -g -Os -m32 -ffreestanding -Wall -Werror test.c -o test.o
And it works fine. However, there are two more lines that bring me trouble.
ld -static -Ttest.ld -nostdlib --nmagic -o test.elf test.o
and
objcopy -O binary test.elf test.bin
The first causes an error.
ld: i386 architecture of input file `test.o' is incompatible with i386:x86-64 output
And because of this, I have not tried the final compilation line.
Here is the code for the test.ld file.
ENTRY(main); SECTIONS { . = 0x7C00; .text : AT(0x7C00) { *(.text); } .sig : AT(0x7DFE) { SHORT(0xaa55); } }
Any suggestions on how to fix this?