Courses/Computer Science/CPSC 457.W2012/Lecture Notes/SysArch

= System Architecture and System Calls =

This session will briefly consider a typical hardware environment that an OS is responsible for managing, with a focus on the x86 platform.

We will work from our previous discussion of x86 assembly language programming and see how system calls are made (i.e., their calling convention on x86/Linux), how they are defined, how they can be traced, and how they differ from "normal" function calls.

= Focus Questions =


 * How does a program become a process (cont.)?
 * How do low-level hardware primitives enable the higher-level resource management and isolation guarantees of an Operating System kernel?

= Notes =


 * Slides from today
 * USRA 2012
 * Encouragement / Laptops
 * "Big" Picture:
 * Userland / Kernel split
 * x86 CPU core architecture, data path, assembly language
 * DPL bits in segment descriptors help label memory pages as belonging to a particular privilege "ring"
 * System Architecture Environment and assembly programming (x86 legacy)
 * GDT and IDT
 * http://www.phrack.com/issues.html?issue=59&id=4&mode=txt
 * examine process creation via fork(2)
 * System Call Invocation
 * We examined how to write a small assembly program that write "hello" to stdout. This involved discovering what the Linux system call invocation convention was
 * eax holds the syscall number, which we can get from unistd.h
 * ebx, ecx, edx, esi, edi hold the system call arguments (either the values or pointers to them, as appropriate -- you can check the manual page for the specific system call to discover the argument types)
 * issue an INT 0x80 instruction; this causes the CPU to generate an interrupt and trap to the OS (via the IDT). The CPU then transitions to supervisor mode (CPL bits set to 00). This is one of the mechanisms that enforce a userspace / kernel split.
 * NASM documentation
 * VDSO note / sidebar (i.e., how system calls are really invoked)
 * VDSO definition: http://kernelnewbies.org/KernelGlossary#V
 * Linux-gate vdso insight: http://www.trilithium.com/johan/2005/08/linux-gate/
 * SYSENTER/SYSEXIT trivia: http://lkml.org/lkml/2002/12/18/218
 * An explanation of various aspects of the Linux system call mechanism, including the VDSO: http://www.win.tue.nl/~aeb/linux/lk/lk-4.html

= Readings =
 * None - catch up on previous reading or svn tutorial material.

= Background / Reference =


 * The Intel IA32 Developer Manuals, Volume 1: http://www.intel.com/products/processor/manuals/
 * Section 2.1 (skim this)
 * Section 2.2 (paying particular attention to the description of the pipelined microarchitecture)
 * Chapter 3 (paying particular attention to 3.1 (and Figure 3-1), 3.2, 3.3, 3.4)
 * The Intel IA32 Developer Manuals, Volume 3A: http://www.intel.com/products/processor/manuals/
 * Chapter 2 (paying special attention to Figure 2-1, Section 2.2, Figure 2-3, and Section 9.1)