Add read support for AArch64

This commit is contained in:
Lucas Schumacher 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; 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_SETTID 0x1000000
#define CLONE_CHILD_CLEARTID 0x200000 #define CLONE_CHILD_CLEARTID 0x200000
uint32_t fork(){ uint32_t fork(){

View File

@ -25,7 +25,7 @@ int main() {
if(pid == 0) return 0; if(pid == 0) return 0;
//TODO: wait on child to remove zombie process //TODO: wait on child to remove zombie process
#if defined(__x86_64__) #if defined(__x86_64__) || defined(__aarch64__)
// Test the read syscall // Test the read syscall
#define INPUT_BUFFER_LEN 4096 #define INPUT_BUFFER_LEN 4096
char input_buffer[INPUT_BUFFER_LEN] = {0}; char input_buffer[INPUT_BUFFER_LEN] = {0};

2
sys.h
View File

@ -6,7 +6,7 @@ void exit(int8_t status);
#define STDIO 1 #define STDIO 1
#define STDERR 2 #define STDERR 2
intptr_t write(int32_t fd, const void* buf, intptr_t size); intptr_t write(int32_t fd, const void* buf, intptr_t size);
#if defined(__x86_64__) #if defined(__x86_64__) || defined(__aarch64__)
intptr_t read(int32_t fd, const void* buf, intptr_t size); intptr_t read(int32_t fd, const void* buf, intptr_t size);
#endif #endif