Fix AArch64 write return value
This commit is contained in:
parent
d37d65b500
commit
c2d03d048a
@ -14,15 +14,21 @@ void exit(int8_t status){
|
||||
|
||||
intptr_t write(int32_t fd, const void* buf, intptr_t size){
|
||||
intptr_t n_written = 0;
|
||||
//register int32_t fd_w asm("w0") = fd;
|
||||
asm volatile(
|
||||
"mov x0, %2\n"
|
||||
"mov x1, %0\n"
|
||||
"mov x2, %1\n"
|
||||
"mov x8, #64\n"
|
||||
"svc #0\n"
|
||||
: //TODO: n_written
|
||||
: "r" (buf), "r"(size), "r"(fd)
|
||||
: "x0", "x8" // Clobbered registers
|
||||
// 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, #64\n" // Syscall number for 'write' is 64 in AArch64
|
||||
"svc #0\n" // Make syscall
|
||||
"mov %0, x0\n" // Store return value in n_written
|
||||
// Output operands
|
||||
: "=r"(n_written)
|
||||
// Input operands
|
||||
: "r"((int64_t)fd), "r" (buf), "r"(size)
|
||||
// Clobbered registers
|
||||
: "x0", "x1", "x2", "x8"
|
||||
);
|
||||
return n_written;
|
||||
}
|
||||
|
||||
@ -3,8 +3,12 @@
|
||||
|
||||
|
||||
int main() {
|
||||
uint64_t pid = fork();
|
||||
// Test the write syscall
|
||||
intptr_t n = write(STDIO, "Hello\n", 6);
|
||||
if(n != 6) return n;
|
||||
|
||||
// Test the fork syscall
|
||||
uint64_t pid = fork();
|
||||
// Print the pid in hex
|
||||
char msg[17] = {' '};
|
||||
msg[16] = '\n';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user