From 61927b3f2960105d888c4fec7a6f5caed38d6be9 Mon Sep 17 00:00:00 2001 From: ummthespruce <130300985+ummthespruce@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:10:40 +0200 Subject: [PATCH] software-stack/lab: Add arm implementation for basic-syscall exercise Add arm skeleton from basic-syscall exercise Signed-off-by: Andrei Lipan --- .../lab/support/basic-syscall/arm/Makefile | 18 +++++++ .../lab/support/basic-syscall/arm/hello.s | 54 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 content/chapters/software-stack/lab/support/basic-syscall/arm/Makefile create mode 100644 content/chapters/software-stack/lab/support/basic-syscall/arm/hello.s diff --git a/content/chapters/software-stack/lab/support/basic-syscall/arm/Makefile b/content/chapters/software-stack/lab/support/basic-syscall/arm/Makefile new file mode 100644 index 0000000000..ba8fab91af --- /dev/null +++ b/content/chapters/software-stack/lab/support/basic-syscall/arm/Makefile @@ -0,0 +1,18 @@ +CC = aarch64-linux-gnu-gcc +AS = aarch64-linux-gnu-as +QEMU = qemu-aarch64 + +.PHONY: all clean + +all: hello + +hello: hello.o + +hello.o: hello.s + +run: hello + $(QEMU) ./hello + +clean: + -rm -f hello.o hello + -rm -f *~ diff --git a/content/chapters/software-stack/lab/support/basic-syscall/arm/hello.s b/content/chapters/software-stack/lab/support/basic-syscall/arm/hello.s new file mode 100644 index 0000000000..10390a57b3 --- /dev/null +++ b/content/chapters/software-stack/lab/support/basic-syscall/arm/hello.s @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +.section .bss + + .lcomm buffer, 128 + + /* + * We need to add some padding due to a QEMU bug, present + * on the 4.2.1 version, that produces a SEGFAULT; + * the program works perfectly fine otherwise + */ + .p2align 12 + +.equ len, 128 + +.section .rodata + +hello: + .ascii "Hello, world!\n\0" + +bye: + .ascii "Bye, world!\n\0" + +.section .text + +.global main + + + +main: + /* syscall calling in arm found at */ + /* https://arm64.syscall.sh/ */ + + /* needed instructions: */ + + /* mov , # , moves an 8 bit value*/ + /* ldr , =,loads a value, usually an address */ + /* svc #, syscall (use value 0 for syscall) */ + /* ret , return*/ + + + /* Call write(1, "Hello, world!\n", 14). */ + /* x8 <- __NR_write (index of write syscall: 64) */ + /* x0 <- first syscall argument (fd: 1) */ + /* x1 <- second syscall argument (buffer: hello) */ + /* x2 <- third syscall argument (length: 14) */ + + + /* Call exit(0). */ + /* x8 <- __NR_exit (index of exit syscall: 93) */ + /* x0 <- first syscall argument (error_code: 0) */ + + + ret