Add aarch64 execution infrastructure

This commit is contained in:
Enrico Lumetti 2021-05-05 00:36:32 +02:00
parent ad82c64d4d
commit 69f969bb71
4 changed files with 29 additions and 1 deletions

5
aarch64-hello.s Normal file
View File

@ -0,0 +1,5 @@
.global _main
_main:
mov x0, 42 // exit code
ret

5
runtime.s Normal file
View File

@ -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);

11
test-aarch64-run.scm Normal file
View File

@ -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)

View File

@ -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)))