Done by “Limited Direct Execution”
OS loads program data and args and then gives control to the process
Problems:
Must prevent user:
When user needs to perform I/O, invoke kernel mode OS via system calls
i.e. the C standard library has a function called printf
that internally does a write
system call.
How does a system call work?
%eax
%eax
, the value is an offset of a table of syscalls (so index 4).x86-64 although adds the syscall
instruction which avoids the trap mechanism.
Saving Process State
Restoring Process State
iret
pops and restores the trap frame
and returns to process in user mode.
iret
will also change the privilege modeiret
(restore trap frame from kernel stack)Cooperative multitasking is done then, because we have made it so processes can trap to the OS and the OS can do its thing.
Preemptive Multiasking isn’t too hard then, we just need hardware assistance to schedule a periodic clock interrupt at fixed time intervals (e.g. 1ms).
The decision is a policy, the switch is a mechanism (carried out by a low level dispatcher). Talking about which policies to schedule and related algorithms is up next.