From a48fbcf1a2e1e1d6284d53d865598a1c8bf899ab Mon Sep 17 00:00:00 2001 From: Lucas Schumacher Date: Sun, 16 Feb 2025 17:15:21 -0500 Subject: [PATCH] Add support for AARCH64 --- print.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/print.c b/print.c index f2f9b88..09dc57b 100644 --- a/print.c +++ b/print.c @@ -1,20 +1,42 @@ long print(const void *buf, long count) { +#if defined(__x86_64__) asm volatile ( "syscall" : : "a"(1), "D"(1), "S"(buf), "d"(count) // RDI, RSI, RDX are used in x86-64 for write args : "rcx", "r11", "memory" ); + #elif defined(__aarch64__) + asm ( "mov x0, #1\n" // Move the exit status into register x0 + "mov x1, %0\n" // Syscall number for 'exit' is 93 in AArch64 + "mov x2, %1\n" // Syscall number for 'exit' is 93 in AArch64 + "mov x8, #64\n" // Syscall number for 'exit' is 93 in AArch64 + "svc #0\n" // Make the syscall + : // No output operands + : "r" (buf), "r"(count) // Input operand: status + : "x0", "x8" // Clobbered registers + ); + #endif return 0; } -void exit(int e) { +void exit(int status) { +#if defined(__x86_64__) asm volatile( "syscall" : - : "a"(60), "D"(e) + : "a"(60), "D"(status) : ); + #elif defined(__aarch64__) + asm ( "mov x0, %0\n" // Move the exit status into register x0 + "mov x8, #93\n" // Syscall number for 'exit' is 93 in AArch64 + "svc #0\n" // Make the syscall + : // No output operands + : "r" ((long)status) // Input operand: status + : "x0", "x8" // Clobbered registers + ); + #endif for(;;); } @@ -26,7 +48,6 @@ int main() { return 69; } void __libc_start_main() {exit(main());} - /* #if defined(__x86_64__) printf("Compiled for x86_64 architecture\n");