LAB
objective
- compile mips assembly with gcc
- run in emulation
setup
- gcc: aboriginal cross compiler , mipsel
- emulator: qemu-user-static
sudo apt-get install qemu-user-static
vim exit.S
#include <sys/regdef.h>
#include <asm/unistd.h>
.data
.text
.global main
main:
.set noreorder
.cpload t9
.set reorder
li a0, 99
li v0, __NR_exit
syscall
note: file ext must be capital S
compile
include cross gcc in path or point run directly
$mipsel-gcc -o exit exit.S
run
copy qemu to chroot folder
$cp $(which qemu-mipsel-static) .
$sudo chroot . ./qemu-mipsel-static ./exit
/lib/ld-uClibc.so.0: No such file or directory
we get error because we compile dynamicly and the lib folder not include in chroot folder
we need to bind the lib folder for outside the chroot to chroot location
$mkdir lib
$sudo mount --bind <path/to/cross_compile/lib> lib
$sudo chroot . ./qemu-mipsel-static ./exit
checking
echo $?
99 # the return value for exit syscall
No comments:
Post a Comment