Last time
Simple version of OS organization:
- Apps
- Abstract layer — unaware of the rest
- Client/server with send/receive primitives
- Virtualization
- Machine + extra instructions
- Extra: system calls
- Pro: same memory
- Kernel
- Hardware
Kernel + Hardware: Abstract machine
System Calls with x86-64 Linux
- Use a
SYSCALL
instruction—privileged
- To invoke, use
rdi, rsi, rdx, r10, r8, r9
- To point to memory, point to address, next register is the size
rax
is the system call number
- Note that memory is not used, just registers
- The kernel uses the
SYSRET
call to return to user code
rax
returns the syscall value (also r11
due to technical reasons)
- Note values from -1 to -4095 means error. The negation of this number is the
errorno
exposed in C/C++
- Cons
- More hassle than function calls
- More state needs to be saved
fd = open("f", O_RDONLY);
int open(char const* f, int flags) {
// move f into %rdi
asm("movqsl %eax, %rax");
// move flags into %rsi
asm("movq %12, %rax");
asm("SYSCALL");
}
Operating System Organization
When creating a large application, what approach should we take?
- An object-oriented program?
- Slow?
- Monolithic (all or nothing, one part breaks, everything does)