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 write(int32_t fd, const void* buf, intptr_t size){
|
||||||
intptr_t n_written = 0;
|
intptr_t n_written = 0;
|
||||||
|
//register int32_t fd_w asm("w0") = fd;
|
||||||
asm volatile(
|
asm volatile(
|
||||||
"mov x0, %2\n"
|
// Assembly Instructions
|
||||||
"mov x1, %0\n"
|
"mov x0, %1\n" // Set x0 to value of fd
|
||||||
"mov x2, %1\n"
|
"mov x1, %2\n" // Set x1 to value of buf
|
||||||
"mov x8, #64\n"
|
"mov x2, %3\n" // Set x2 to value of size
|
||||||
"svc #0\n"
|
"mov x8, #64\n" // Syscall number for 'write' is 64 in AArch64
|
||||||
: //TODO: n_written
|
"svc #0\n" // Make syscall
|
||||||
: "r" (buf), "r"(size), "r"(fd)
|
"mov %0, x0\n" // Store return value in n_written
|
||||||
: "x0", "x8" // Clobbered registers
|
// Output operands
|
||||||
|
: "=r"(n_written)
|
||||||
|
// Input operands
|
||||||
|
: "r"((int64_t)fd), "r" (buf), "r"(size)
|
||||||
|
// Clobbered registers
|
||||||
|
: "x0", "x1", "x2", "x8"
|
||||||
);
|
);
|
||||||
return n_written;
|
return n_written;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,12 @@
|
|||||||
|
|
||||||
|
|
||||||
int main() {
|
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
|
// Print the pid in hex
|
||||||
char msg[17] = {' '};
|
char msg[17] = {' '};
|
||||||
msg[16] = '\n';
|
msg[16] = '\n';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user