54 lines
1.5 KiB
C
54 lines
1.5 KiB
C
#if defined(__aarch64__)
|
|
|
|
void exit(int8_t status){
|
|
asm ( "mov x0, %0\n" // Move the exit status into register x0
|
|
"mov x8, #93\n" // Syscall number for 'exit' is 93 in AArch64
|
|
"svc #0\n" // Make the syscall
|
|
: // No output operands
|
|
: "r" ((long)status) // Input operand: status
|
|
: "x0", "x8" // Clobbered registers
|
|
);
|
|
}
|
|
|
|
intptr_t write(int32_t fd, const void* buf, intptr_t size){
|
|
intptr_t n_written = 0;
|
|
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"(count), "r"(fd)
|
|
: "x0", "x8" // Clobbered registers
|
|
);
|
|
return n_written;
|
|
}
|
|
|
|
#define CLONE_CHILD_SETTID 0x1000000
|
|
#define CLONE_CHILD_CLEARTID 0x200000
|
|
uint32_t fork(){
|
|
long int rtn;
|
|
long int flags = CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID;
|
|
asm volatile (
|
|
// Assembly Instructions
|
|
"mov x8, #220\n" // Syscall number for 'clone' is 220 in AArch64
|
|
"mov x0, %1\n" // clone flags
|
|
"mov x1, #0\n" // child stack pointer
|
|
"mov x2, #0\n" // parent_tidptr
|
|
"mov x3, #0\n" // tls
|
|
"mov x4, #0\n" // child_tidptr
|
|
"svc #0\n" // Make the syscall
|
|
"mov %0, x0\n" // save return value
|
|
// Output operands
|
|
: "=r" (rtn)
|
|
// Input operand
|
|
: "r" (flags)
|
|
// Clobbered registers
|
|
: "x0", "x1", "x2", "x3", "x4", "x8"
|
|
);
|
|
return (uint32_t)rtn;
|
|
}
|
|
|
|
#endif
|