你如何在 QEMU 上运行 elf 文件?这是我最好的猜测:
qemu-system-i386 -hda kernel.elf
Run Code Online (Sandbox Code Playgroud)
这行得通吗?elf 文件是从本教程生成的内核。
最小的可运行示例
来源:https : //github.com/cirosantilli/aarch64-bare-metal-qemu/tree/27537fb1dd0c27d6d91516bf4fc7e1d9564f5a40
运行:
make
qemu-system-aarch64 -M virt -cpu cortex-a57 -nographic -kernel test64.elf -serial mon:stdio
Run Code Online (Sandbox Code Playgroud)
结果:将单个字符打印H到 UART,然后进入无限循环。
来源:
==> test64.ld <==
ENTRY(_Reset)
SECTIONS
{
. = 0x40000000;
.startup . : { startup64.o(.text) }
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss COMMON) }
. = ALIGN(8);
. = . + 0x1000; /* 4kB of stack memory */
stack_top = .;
}
==> test64.c <==
volatile unsigned int * const UART0DR = (unsigned int *) 0x09000000;
void print_uart0(const char *s) {
while(*s != '\0') { /* Loop until end of string */
*UART0DR = (unsigned int)(*s); /* Transmit char */
s++; /* Next char */
}
}
void c_entry() {
print_uart0("Hello world!\n");
}
==> startup64.s <==
.global _Reset
_Reset:
mov x0, 0x48
ldr x1, =0x09000000
str x0, [x1]
b .
==> Makefile <==
CROSS_PREFIX=aarch64-linux-gnu-
all: test64.elf
startup64.o: startup64.s
$(CROSS_PREFIX)as -g -c $< -o $@
test64.elf: startup64.o
$(CROSS_PREFIX)ld -Ttest64.ld $^ -o $@
clean:
rm -f test64.elf startup64.o test64.o
Run Code Online (Sandbox Code Playgroud)
您0x40000000几乎可以将入口地址更改为任何内容(只要它没有映射到某个设备的内存?)。
QEMU 只是解析 Elf 文件中的入口地址,然后将 PC 放在那里开始。您可以使用 GDB 进行验证:
qemu-system-aarch64 -M virt -cpu cortex-a57 -nographic -kernel test64.elf -S -s &
gdb-multiarch -q -ex 'file test64.elf' -ex 'target remote localhost:1234'
Run Code Online (Sandbox Code Playgroud)
这里我列出了一些可能感兴趣的其他设置:如何制作裸机 ARM 程序并在 QEMU 上运行它们?
在 Ubuntu 18.04 上测试。
| 归档时间: |
|
| 查看次数: |
7124 次 |
| 最近记录: |