This is a bare metal system for arm with print module, it's built on Ubuntu 16.04. I mainly followed these tutorials:
https://os.phil-opp.com/first-edition/
https://balau82.wordpress.com/2010/02/28/hello-world-for-bare-metal-arm-using-qemu/
https://balau82.wordpress.com/2010/11/30/emulating-arm-pl011-serial-ports/
You can go this page or just type on your command:
curl https://sh.rustup.rs -sSf | sh
First install with default options (you can also directly install the nightly version), this allows you to start with normal rust programming (remember to add $HOME/.cargo/bin to your $PATH). Then, type:
rustup toolchain install nightly
to install the nightly version of rust. The nightly version of rust allows us to use some features which are essential to write the system. Then switch your default rust toolchain to the nightly version:
rustup default nightly-x86_64-unknown-linux-gnu
Install the xargo and add rust-src for building the core:
cargo install xargo
rustup component add rust-src
I use the aarch64-none-elf-gcc toolchain for cross compiling. You can download here or just clone my whole project (they are in bin and libexec). Then change the path in the Makefile:
CROSS_COMPILE ?= path_to_the_toolchain/bin/aarch64-none-elf-
Install the qemu:
sudo apt-get install qemu
make qemu
You should see the output:
Press Ctrl-A and then X to exit QEMU
qemu-system-aarch64 -M virt -cpu cortex-a57 \
-smp 1 -m 128 \
-nographic \
-kernel hello.elf
Hello world!
0x123456
If you want to debug the system, you can use the aarch64-none-elf-gdb in the toolchain. Qemu implements a gdb connector using a TCP connection. To do so, you can run the qemu with options -s and -S.
-s: shorthand for -gdb tcp::1234
-S: freeze the CPU at startup, you can connect your gdb at this time
For convenience, you can just type:
make dqemu
Now you are running the qemu without output, the command freezes the system before executing any code and waits for a connection on the TCP port 1234. Open another terminal and run aarch64-none-elf-gdb and enter:
target remote localhost:1234
file hello.elf
or just:
make gdb