Add waitpid and execve
This commit is contained in:
45
arch/mips.c
45
arch/mips.c
@@ -1,5 +1,19 @@
|
||||
#if defined(__mips__)
|
||||
#include "../int.h"
|
||||
#include "../sys.h"
|
||||
|
||||
/*
|
||||
#ifndef _START_DEFINED
|
||||
#define _START_DEFINED
|
||||
extern int main(int c, char** v);
|
||||
void __start() {
|
||||
void* fp = __builtin_frame_address(0);
|
||||
register int argc asm("a0") = *(uintptr_t*)(fp+32);
|
||||
register char** argv asm("a1") = fp+36;
|
||||
exit(main(argc, argv));
|
||||
}
|
||||
|
||||
#endif */ /* ifndef _START_DEFINED */
|
||||
|
||||
#include "generic.h"
|
||||
|
||||
@@ -59,6 +73,37 @@ uint32_t fork(){
|
||||
return (uint32_t)rtn;
|
||||
}
|
||||
|
||||
uint32_t waitpid(uint32_t pid, int* wstatus, int options) {
|
||||
int child_pid = 0;
|
||||
asm volatile (
|
||||
"move $a0, %1\n"
|
||||
"move $a1, %2\n"
|
||||
"move $a2, %3\n"
|
||||
"li $v0, 4007\n"
|
||||
"syscall\n"
|
||||
"move %0, $v0\n"
|
||||
: "=r"(child_pid)
|
||||
: "r"(pid), "r"(wstatus), "r"(options)
|
||||
: "a0", "a1", "a2", "v0", "memory"
|
||||
);
|
||||
return child_pid;
|
||||
}
|
||||
|
||||
int32_t execve(const char* filename, const char* argv[], const char* envp[]){
|
||||
int rtn;
|
||||
asm volatile (
|
||||
"move $a0, %0\n"
|
||||
"move $a1, %1\n"
|
||||
"move $a2, %2\n"
|
||||
"li $v0, 4011\n"
|
||||
"syscall\n"
|
||||
: "=r"(rtn)
|
||||
: "r"(filename), "r"(argv), "r"(envp)
|
||||
: "a0", "a1", "a2", "a3", "v0"
|
||||
);
|
||||
return (int32_t)rtn;
|
||||
}
|
||||
|
||||
int32_t openat(int32_t fd, const char* filename, uint32_t flags, uint32_t mode) {
|
||||
int32_t file = 0;
|
||||
asm volatile (
|
||||
|
||||
Reference in New Issue
Block a user