Add read support for AArch64

This commit is contained in:
2025-04-14 14:09:14 -04:00
parent c2d03d048a
commit 6902b49be2
3 changed files with 22 additions and 2 deletions

View File

@@ -33,6 +33,26 @@ intptr_t write(int32_t fd, const void* buf, intptr_t size){
return n_written;
}
intptr_t read(int32_t fd, const void* buf, intptr_t size){
intptr_t n_read = 0;
asm volatile(
// Assembly Instructions
"mov x0, %1\n" // Set x0 to value of fd
"mov x1, %2\n" // Set x1 to value of buf
"mov x2, %3\n" // Set x2 to value of size
"mov x8, #63\n" // Syscall number for 'read' is 63 in AArch64
"svc #0\n" // Make syscall
"mov %0, x0\n" // Store return value in n_read
// Output operands
: "=r"(n_read)
// Input operands
: "r"((int64_t)fd), "r" (buf), "r"(size)
// Clobbered registers
: "x0", "x1", "x2", "x8"
);
return n_read;
}
#define CLONE_CHILD_SETTID 0x1000000
#define CLONE_CHILD_CLEARTID 0x200000
uint32_t fork(){