Commit e329501c authored by benkma's avatar benkma

Lab 12 Completed

parent eddbc88e
......@@ -248,6 +248,9 @@ uintptr_t proc::syscall(regstate* regs) {
pstate_ = ps_exit;
yield_noreturn();
assert(false); // will not be reached
case SYSCALL_SLEEP:
return syscall_sleep(regs->reg_rdi);
default:
// no such system call
......@@ -259,6 +262,17 @@ uintptr_t proc::syscall(regstate* regs) {
// Debugging Information
#pragma GCC push_options
#pragma GCC optimize("O0")
int proc::syscall_sleep(uint64_t msec){
unsigned long now = ticks;
unsigned long end = round_up(now,10) + msec;
while (now < end) {
yield();
now = ticks;
}
return 0;
}
int proc::syscall_map_console(uintptr_t addr) {
if(addr % PAGESIZE || addr > VA_LOWMAX) {
return E_INVAL;
......
......@@ -66,6 +66,7 @@ struct __attribute__((aligned(4096))) proc {
int syscall_fork(regstate* regs);
int syscall_map_console(uintptr_t addr);
int syscall_sleep(uint64_t msec);
uintptr_t syscall_read(regstate* reg);
uintptr_t syscall_write(regstate* reg);
......
......@@ -271,6 +271,7 @@ struct bitset_view {
// Add new system calls here.
// Your numbers should be >=128 to avoid conflicts.
#define SYSCALL_MAP_CONSOLE 128
#define SYSCALL_SLEEP 129
// System call error return values
......
......@@ -4,6 +4,8 @@ static const int order[] = {
2, 7, 6, 4, 1, 8, 5, 3
};
#pragma GCC push_options
#pragma GCC optimize("O0")
void process_main() {
// create 8 processes
int my_idx = 0;
......@@ -29,3 +31,5 @@ void process_main() {
}
sys_exit(0);
}
#pragma GCC pop_options
......@@ -133,7 +133,7 @@ inline pid_t sys_fork() {
// sys_msleep(msec)
// Block for approximately `msec` milliseconds.
inline int sys_msleep(unsigned msec) {
return E_NOSYS;
return make_syscall(SYSCALL_SLEEP, msec);
}
// sys_getppid()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment