Lecture 1: Programming interface
Preparation
- Read OSPP: §3, The programming interface.
- Skim xv6: §0, Operating system interfaces.
Questions from last lecture
- how to do the labs on my Linux
- install the stock gcc/gdb/binutils:
apt-get
or yum
or pacman
- compile our patched qemu - read the tools guide
- or, simply install the stock qemu - easy but not recommended
- how to do the labs on my Mac
- follow the tools guide
- keep homebrew up to date
- reinstall packages if some are incomplete
- why the kernel image is at
0x00100000
but the entry point is at 0x0010000c
- is the BIOS-bootloader handover protocol the same for cdrom as for harddisk
Overview
- Recall JOS: print to screen via MMIO (
0xb8000
on x86)
- arguably the lowest-level print: compare to print in C, Java, Python, etc.
- is it a good programming interface
- History: punch cards - see Holzmann’s To Code Is Human
- Unix system calls & files - see the readings page
- This lecture will use Linux as an example, via
strace
Example: hello
output:
- system calls:
execve
(first), write
, exit_group
(last)
- what’s the first argument of
write
- what’s the relationship between
printf
and write
- what’s the first argument of
exit_group
Example: uptime
output:
- system calls:
open
, lseek
, read
, …
- file:
/proc/uptime
- is this a real file on disk?
(source code)
- other pseudo files: e.g., procfs
cat /proc/cpuinfo
cat /proc/iomem
- compare to JOS’s output
Example: sh and uptime
output:
- system calls:
clone
(old days: fork
), wait4
- what do they do
- how do they communicate
- child vs parent processes: what are copied/shared
Exercises
draw the system calls for the following
Summary & questions
- system calls (and “files”)
- JOS exposes a lower-level set of system calls
- JOS implements POSIX system calls (e.g., like in Linux) as user-space libraries
- why do we need system calls at all - just library functions?
- guess how
strace
is implemented