关键字: qemu
mips
QEMU是一个处理器模拟软件,可以用来在PC中模拟ARM、MIPS等多种架构的软硬件运行环境。QEMU主要有两种模拟模式:
QEMU功能强大,现在的版本安装起来也很简单。但在Ubuntu版本中,只需要一条命令就可以把QEMU的User模式和System模式的可执行文件安装好
apt install qemu-user-static qemu-system-mips
注意这里我们安装的是qemu-user模式的static版本,也就是静态链接的qemu。
安装好qemu命令后,我们可以编译一个我们自己编写的mips-linux应用程序并运行起来。在此之前我们需要安装一个能够编译mips应用程序的编译器,同样的,使用一条简单的命令就可以完成
apt install gcc-mips-linux-gnu
安装好编译器以后,我们使用一段helloworld C代码测试一下:
root@OptiPlex-7050:/home/lester# cat > xx.c << EOF
#include <stdio.h>
#include <endian.h>
int main()
{
int x = 0x1234;
printf("0x%x, htole32 0x%x, htobe32 0x%x\n", x, htole32(x), htobe32(x));
return 0;
}
EOF
编译这段代码的命令如下:
root@OptiPlex-7050:/home/lester# mips-linux-gnu-gcc -static xx.c
root@OptiPlex-7050:/home/lester# file a.out
a.out: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=58b4213f431eedcd37b362a38662113d6ff0b7dc, not stripped
从上可以看出,编出来的程序的MIPS的。
然后使用qemu命令运行测试:
root@OptiPlex-7050:/home/lester# qemu-mips-static ./a.out
0x1234, htole32 0x34120000, htobe32 0x1234
原文:https://www.cnblogs.com/sinpo828/p/13674479.html