Adding wait system call
This commit is contained in:
parent
4f15c9fd01
commit
02c0816e41
@ -19,6 +19,7 @@ main(int argc, const char *argv[])
|
||||
char buf[256];
|
||||
|
||||
printf("System Shell\n");
|
||||
|
||||
while (1) {
|
||||
fputs("Shell> ", stdout);
|
||||
fgets(buf, sizeof(buf), stdin);
|
||||
@ -31,12 +32,13 @@ void
|
||||
Cmd_Help(int argc, const char *argv[])
|
||||
{
|
||||
printf("cat Print file\n");
|
||||
printf("bkpt Trigger a kernel breakpoint\n");
|
||||
printf("date Print current date and time\n");
|
||||
printf("echo Echo arguments\n");
|
||||
printf("exit Exit shell\n");
|
||||
printf("help Display the list of commands\n");
|
||||
printf("ls List files in a directory\n");
|
||||
printf("date Print current date and time\n");
|
||||
printf("bkpt Trigger a kernel breakpoint\n");
|
||||
printf("spawn Spawn a process\n");
|
||||
}
|
||||
|
||||
void
|
||||
@ -124,6 +126,23 @@ Cmd_Hexdump(int argc, const char *argv[])
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Cmd_Spawn(int argc, const char *argv[])
|
||||
{
|
||||
int fd;
|
||||
uint64_t status;
|
||||
uintptr_t offset = 0;
|
||||
|
||||
if (argc != 2) {
|
||||
fputs("Requires an argument\n", stdout);
|
||||
return;
|
||||
}
|
||||
|
||||
status = OSSpawn(argv[1]);
|
||||
// XXX: check errors
|
||||
OSWait(status);
|
||||
}
|
||||
|
||||
void
|
||||
DispatchCommand(char *buf)
|
||||
{
|
||||
@ -168,6 +187,8 @@ DispatchCommand(char *buf)
|
||||
exit(0);
|
||||
} else if (strcmp(argv[0], "ls") == 0) {
|
||||
Cmd_List(argc, (const char **)argv);
|
||||
} else if (strcmp(argv[0], "spawn") == 0) {
|
||||
Cmd_Spawn(argc, (const char **)argv);
|
||||
} else if (strcmp(argv[0], "#") == 0) {
|
||||
// Ignore comments
|
||||
} else if (buf[0] != '\0') {
|
||||
|
@ -5,9 +5,10 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
uint64_t OSTime();
|
||||
void OSExit(int status);
|
||||
uint64_t OSGetPID();
|
||||
void OSExit(int status);
|
||||
uint64_t OSSpawn(const char *path);
|
||||
uint64_t OSWait(uint64_t pid);
|
||||
|
||||
// Memory
|
||||
void *OSMemMap(void *addr, uint64_t len, int flags);
|
||||
|
@ -31,6 +31,12 @@ OSSpawn(const char *path)
|
||||
return syscall(SYSCALL_SPAWN, path);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
OSWait(uint64_t pid)
|
||||
{
|
||||
return syscall(SYSCALL_WAIT, pid);
|
||||
}
|
||||
|
||||
void *
|
||||
OSMemMap(void *addr, uint64_t len, int flags)
|
||||
{
|
||||
|
@ -4,9 +4,10 @@
|
||||
|
||||
#define SYSCALL_NULL 0x00
|
||||
#define SYSCALL_TIME 0x01
|
||||
#define SYSCALL_EXIT 0x02
|
||||
#define SYSCALL_SPAWN 0x03
|
||||
#define SYSCALL_GETPID 0x04
|
||||
#define SYSCALL_GETPID 0x02
|
||||
#define SYSCALL_EXIT 0x03
|
||||
#define SYSCALL_SPAWN 0x04
|
||||
#define SYSCALL_WAIT 0x05
|
||||
|
||||
// Memory
|
||||
#define SYSCALL_MMAP 0x08
|
||||
|
@ -24,6 +24,13 @@ Syscall_Time()
|
||||
return KTime_GetEpochNS();
|
||||
}
|
||||
|
||||
uint64_t
|
||||
Syscall_GetPID()
|
||||
{
|
||||
Thread *cur = Thread_Current();
|
||||
return cur->tid;
|
||||
}
|
||||
|
||||
void
|
||||
Syscall_Exit(uint64_t status)
|
||||
{
|
||||
@ -101,10 +108,10 @@ Syscall_Spawn(uint64_t user_path)
|
||||
}
|
||||
|
||||
uint64_t
|
||||
Syscall_GetPID()
|
||||
Syscall_Wait(uint64_t pid)
|
||||
{
|
||||
Thread *cur = Thread_Current();
|
||||
return cur->tid;
|
||||
NOT_IMPLEMENTED();
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
@ -379,13 +386,15 @@ Syscall_Entry(uint64_t syscall, uint64_t a1, uint64_t a2,
|
||||
return 0;
|
||||
case SYSCALL_TIME:
|
||||
return Syscall_Time();
|
||||
case SYSCALL_GETPID:
|
||||
return Syscall_GetPID();
|
||||
case SYSCALL_EXIT:
|
||||
Syscall_Exit(a1);
|
||||
return 0; // To eliminate warning
|
||||
case SYSCALL_SPAWN:
|
||||
return Syscall_Spawn(a1);
|
||||
case SYSCALL_GETPID:
|
||||
return Syscall_GetPID();
|
||||
case SYSCALL_WAIT:
|
||||
return Syscall_Wait(a1);
|
||||
case SYSCALL_MMAP:
|
||||
return Syscall_MMap(a1, a2, a3);
|
||||
case SYSCALL_MUNMAP:
|
||||
|
Loading…
Reference in New Issue
Block a user