Limited Direct Execution


CPU virtualization recall

Design goals of CPU virtualization
The question!

How to efficiently virtualize the CPU with control?

Efficient?
Problem!

Problem: working with restricted operations

Solution: hardware support via processor modes
Process modes
System calls
How does a system call happen?
System calls versus normal C calls?
Tracing echo.c
user/usys.S
kernel/trap.c
kernel/syscall.c
kernel/sysproc.c and kernel/sysfile.c
Tracing instructions
1
2
3
4
if (r_scause() == 8) {
    printf("usertrap: syscall from pid %d, syscall number = %ld\n", p->pid, p->trapframe->a7);
    ...
}
1
2
3
4
if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {
    printf("syscall(): number = %d, a0 = %ld, a1 = %ld, a2 = %ld\n", num, p->trapframe->a0, p->trapframe->a1, p->trapframe->a2);
    ...
}

Problem: switching processes

First approach: cooperative processes
Second approach: non-cooperative processes
Second approach: non-cooperative processes
Timer interrupt and regaining control
kernel/trap.c
kernel/proc.c