From 69f969bb7142a6543945b77797ff398eccf57fa5 Mon Sep 17 00:00:00 2001 From: Enrico Lumetti Date: Wed, 5 May 2021 00:36:32 +0200 Subject: [PATCH] Add aarch64 execution infrastructure --- aarch64-hello.s | 5 +++++ runtime.s | 5 +++++ test-aarch64-run.scm | 11 +++++++++++ test-util.scm | 9 ++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 aarch64-hello.s create mode 100644 runtime.s create mode 100644 test-aarch64-run.scm diff --git a/aarch64-hello.s b/aarch64-hello.s new file mode 100644 index 0000000..2142ffb --- /dev/null +++ b/aarch64-hello.s @@ -0,0 +1,5 @@ +.global _main + +_main: + mov x0, 42 // exit code + ret diff --git a/runtime.s b/runtime.s new file mode 100644 index 0000000..44f3fcf --- /dev/null +++ b/runtime.s @@ -0,0 +1,5 @@ +.global main +main: + bl _main + mov x8, 93 // sys_exit() is at index 93 in kernel functions table + svc #0 // generate kernel call sys_exit(123); diff --git a/test-aarch64-run.scm b/test-aarch64-run.scm new file mode 100644 index 0000000..40674b2 --- /dev/null +++ b/test-aarch64-run.scm @@ -0,0 +1,11 @@ +#lang racket + +(require "test-util.scm") + +(test-eq + (compile-arm-asm "aarch64-hello.s" "a.out") + #t) + +(test-eq + (run-arm-executable "a.out") + 42) diff --git a/test-util.scm b/test-util.scm index 7dc43d0..60388d2 100644 --- a/test-util.scm +++ b/test-util.scm @@ -1,7 +1,14 @@ #lang racket -(provide test-eq) +(require racket/system) + +(provide test-eq compile-arm-asm run-arm-executable) (define (test-eq a b) (if (equal? a b) (displayln "PASS") (error (format "FAIL: ~a != ~a" a b)))) +(define (compile-arm-asm filename outfilename) + (system (format "aarch64-linux-gnu-gcc -static ~a runtime.s -o ~a" filename outfilename))) + +(define (run-arm-executable filename) + (system/exit-code (format "qemu-aarch64 ./~a" filename)))