Emulate ARM x64 architecture

Giovanny Andres Ortegon Espitia
2 min readMay 21, 2021

In the before article, we learn how to configure ARM x32 step by step. Now we will learn about ARM x64 architecture.

In this section we will learn install, assemble, link and debug in this architecture.

Install some GNU and Linux tools:

$ sudo apt-get update && sudo apt-get upgrade -y

$ sudo apt-get install build-essential

Compiler

$ sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu binutils-aarch64-linux-gnu-dbg

For emulate, execute and debuger we use:

$ sudo apt-get install qemu-user qemu-user-static

Debugger

$ sudo apt-get install gdb-multiarch

Compile

For testing, we create a file called hello_armx64.s

$ vim hello_armx64.s

hello_armx64.s

Assemble

$ /usr/aarch64-linux-gnu/bin/as -g hello_armx64.s -o hello_armx64.o

or

$ aarch64-linux-gnu-as -g hello_armx64.s -o hello_armx64.o

Note: don’t forget flag -g for debugging

Link

$ /usr/aarch64-linux-gnu/bin/ld hello_armx64.o -o hello_armx64

or

$ aarch64-linux-gnu-ld hello_armx64.o -o hello_armx64

Execute

$ ./hello_armx64

or

$ qemu-aarch64 ./hello_armx64

Debugger

We go to use qemu-arm and gdb-multiarch for debugging program because ARM processor use different registers and qemu helps to emulate them.

First step:

Create a gdb server with qemu and its port with this command:

$ qemu-arm -L /usr/aarch64-linux-gnu -g 1234 ./hello_armx64

Note: you can use another number for the port but it must be the same in gdb-multiarch.

It waits for response. Then, start gdb-multiarch with next commands:

$ gdb-multiarch -q — nh -ex ‘set architecture arm’ -ex ‘file hello_armx64’ -ex ‘target remote :1234’ -ex ‘layout split’ -ex ‘layout regs’

  • -q : Do not print version number on startup.
  • — nh: Do not read ~/.gdbinit.
  • -ex: Execute a single GDB command.
  • Set architecture arm: specifies type of architecture
  • Layout split: Divide screen to show code.
  • Layout regs: Shows all registers of ARM achitecture.

Note: You can remove some flags used for gdb-multiarch like layout split or layout regs but never -ex ‘target remote : 1234’ it binds with qemu port.

debugging hello_armx64

start to debug:

(gdb) b _start

Note: dont use gdb command: run only next or si (stepi)

(gdb ) net

Note: gdb uses normal commands for debugging.

That’s all. Now we have to learn how to configure ARM x

--

--