Add read support for AArch64
This commit is contained in:
parent
c2d03d048a
commit
6902b49be2
@ -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(){
|
||||
|
||||
@ -25,7 +25,7 @@ int main() {
|
||||
if(pid == 0) return 0;
|
||||
//TODO: wait on child to remove zombie process
|
||||
|
||||
#if defined(__x86_64__)
|
||||
#if defined(__x86_64__) || defined(__aarch64__)
|
||||
// Test the read syscall
|
||||
#define INPUT_BUFFER_LEN 4096
|
||||
char input_buffer[INPUT_BUFFER_LEN] = {0};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user