Add support for AARCH64

This commit is contained in:
Lucas Schumacher 2025-02-16 17:15:21 -05:00
parent feddb27588
commit a48fbcf1a2

27
print.c
View File

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