【发布时间】:2014-12-28 19:09:02
【问题描述】:
我正在尝试遵循 this 链接中的教程。
当我开始制作 test.c 文件的部分时,我尝试运行第一行编译。
gcc -c -g -Os -march=i686 -ffreestanding -Wall -Werror test.c -o test.o
这里是test.c的内容
__asm__(".code16\n");
__asm__("jmpl $0x0000, $main\n");
void main() {
}
当我调用第一个编译行时,它显示了这个错误。
test.c:1:0: error: CPU you selected does not support x86-64 instruction set
__asm__(".code16\n");
^
谁能告诉我为什么会这样?如果可能,如何解决?
我正在运行 Ubuntu Desktop x64,提前感谢您的帮助。
编辑:
我已将第一行编译更改为:
gcc -c -g -Os -m32 -ffreestanding -Wall -Werror test.c -o test.o
而且它似乎工作正常。但是,还有两行给我带来了麻烦。
ld -static -Ttest.ld -nostdlib --nmagic -o test.elf test.o
和
objcopy -O binary test.elf test.bin
第一个给我的错误。
ld: i386 architecture of input file `test.o' is incompatible with i386:x86-64 output
因此,我没有尝试编译的最后一行。
这是 test.ld 文件的代码。
ENTRY(main);
SECTIONS
{
. = 0x7C00;
.text : AT(0x7C00)
{
*(.text);
}
.sig : AT(0x7DFE)
{
SHORT(0xaa55);
}
}
关于如何解决此问题的任何建议?
【问题讨论】:
-
` .code16 ' 或 ` .code16gcc ' 指令之前的汇编语言指令用于在 16 位模式下运行。