我正在尝试按照
this链接中的教程.
@H_502_2@当我开始编写test.c文件的部分时,我尝试运行第一个编译行.
gcc -c -g -Os -march=i686 -ffreestanding -Wall -Werror test.c -o test.o@H_502_2@这是test.c的内容
__asm__(".code16\n"); __asm__("jmpl $0x0000,$main\n"); void main() { }@H_502_2@当我调用第一个编译行时,它会显示我的错误.
test.c:1:0: error: cpu you selected does not support x86-64 instruction set __asm__(".code16\n"); ^@H_502_2@谁能告诉我为什么会这样?如果可能的话,如何修复它? @H_502_2@我正在运行Ubuntu Desktop x64,请提前感谢您的帮助. @H_502_2@编辑: @H_502_2@我已将第一个编译行更改为:
gcc -c -g -Os -m32 -ffreestanding -Wall -Werror test.c -o test.o@H_502_2@它似乎工作正常.但是,还有两条线路给我带来了麻烦.
ld -static -Ttest.ld -nostdlib --nmagic -o test.elf test.o@H_502_2@和
objcopy -O binary test.elf test.bin@H_502_2@第一个抛出了我的错误.
ld: i386 architecture of input file `test.o' is incompatible with i386:x86-64 output@H_502_2@因此,我还没有尝试最后的编译. @H_502_2@这是test.ld文件的代码.
ENTRY(main); SECTIONS { . = 0x7C00; .text : AT(0x7C00) { *(.text); } .sig : AT(0x7DFE) { SHORT(0xaa55); } }@H_502_2@对于如何解决这个问题,有任何的建议吗?
解决方法
供应-m32而不是-march = i686.