apps,nanos-lite,proc: context switch when syscall
This commit is contained in:
parent
e3ac38b863
commit
6d2bc81df2
|
@ -7,7 +7,7 @@ static _RegSet* do_event(_Event e, _RegSet* r) {
|
|||
_RegSet *ret = NULL;
|
||||
switch (e.event) {
|
||||
case _EVENT_TRAP: ret = schedule(r); break;
|
||||
case _EVENT_SYSCALL: ret = do_syscall((uintptr_t *)e.cause); break;
|
||||
case _EVENT_SYSCALL: ret = do_syscall((uintptr_t *)e.cause); ret = schedule(r); break;
|
||||
default: panic("Unhandled event ID = %d", e.event);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ int main() {
|
|||
init_fs();
|
||||
|
||||
load_prog("/bin/pal");
|
||||
load_prog("/bin/hello");
|
||||
|
||||
_trap();
|
||||
|
||||
|
|
|
@ -21,12 +21,22 @@ void load_prog(const char *filename) {
|
|||
pcb[i].tf = _make(stack, (void *)entry, NULL);
|
||||
}
|
||||
|
||||
static int cnt = 0;
|
||||
|
||||
_RegSet* schedule(_RegSet *prev) {
|
||||
Log("schedule");
|
||||
// when current == NULL at the very beginning, it will not cover
|
||||
// any valid data, so it will be safe to write to memory near NULL
|
||||
current->tf = prev;
|
||||
current = &pcb[0];
|
||||
if (current == &pcb[0]) {
|
||||
cnt ++;
|
||||
if (cnt == 1000) {
|
||||
current = &pcb[1];
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
current = &pcb[0];
|
||||
}
|
||||
_switch(¤t->as);
|
||||
return current->tf;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue