Add waitpid and execve

This commit is contained in:
2026-01-17 15:19:52 -05:00
parent ea0ec6a818
commit 73ad441585
5 changed files with 249 additions and 153 deletions

View File

@@ -81,6 +81,50 @@ uint32_t fork(){
return (uint32_t)rtn;
}
// SYS_EXECVE 221
int32_t execve(const char* filename, const char* argv[], const char* envp[]){
long int rtn;
asm volatile(
// Assembly Instructions
"mov x0, %0\n" // Set x0 to value of filename
"mov x1, %1\n" // Set x1 to value of argv
"mov x2, %2\n" // Set x2 to value of envp
"mov x8, #221\n" // Syscall number
"svc #0\n" // Make syscall
// Output operands
: "=r"(rtn)
// Input operands
: "r"(filename), "r" (argv), "r"(envp)
// Clobbered registers
: "x0", "x1", "x2", "x8", "memory"
);
return (int32_t)rtn;
}
uint32_t wait4(uint32_t pid, int* wstatus, int options, void* rusage) {
uint64_t rtn;
asm volatile (
// Assembly Instructions
"mov x8, #260\n" // Syscall number for 'listen' is 201 in AArch64
"mov x0, %1\n" // pid
"mov x1, %2\n" // wstatus
"mov x2, %3\n" // options
"mov x3, %4\n" // rusage
"svc #0\n" // Make the syscall
"mov %0, x0\n" // save return value
// Output operands
: "=r" (rtn)
// Input operand
: "r" ((uint64_t)pid), "r"(wstatus), "r"((int64_t)options), "r"(rusage)
// Clobbered registers
: "x0", "x1", "x8", "memory"
);
return (uint32_t)rtn;
}
uint32_t waitpid(uint32_t pid, int* wstatus, int options) {
return wait4(pid, wstatus, options, 0);
}
int32_t openat(int32_t fd, const char* filename, uint32_t flags, uint32_t mode) {
long int rtn;
asm volatile (