forked from open-education-hub/operating-systems
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ummthespruce <[email protected]>
- Loading branch information
1 parent
c25c91f
commit 62a60e2
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
content/chapters/software-stack/lab/support/basic-syscall/arm/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 *~ |
54 changes: 54 additions & 0 deletions
54
content/chapters/software-stack/lab/support/basic-syscall/arm/hello.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <register>, #<value> , moves an 8 bit value*/ | ||
/* ldr <register>, =<value>,loads a value, usually an address */ | ||
/* svc #<value>, 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 |