Lecture 2: The Kernel Interface

Device interface continued

A few more details on our picture from last lecture:

Privilege mode and traps

In order to make it possible for the operating system to provide isolation and access control, the processor has a special "privilege bit" that prevents certain instructions from being executed. There are many words meaning that a cpu has this bit set:

The processor will prevent certain instructions from executing when the privilege bit is cleared. For example:

The privilege bit is set in two ways:

There are three kinds of traps:

The privilege bit is cleared by a special "return from system call" instruction, which the OS will execute when it is done processing a trap or done with initialization.

Terminology:

If you want to write an operating system, you have to write four functions: the initialization routine, the interrupt service routine, the system call handler routine, and the exception handler routine. That is the entire interface that you need to implement.

Processes

Terminology:

For each process, the OS maintains a process control block (PCB), containing the saved state of the registers, the saved virtual memory information (such as a base/bounds register or a page table base register, more on this when we discuss memory).

The operating system gives the illusion of running multiple processes simultaneously by timesharing the CPU: rapidly switching between running processes.

Before running a user process, the kernel will set a hardware timer. When that timer expires, it will raise an interrupt. The interrupt handler routine will save the state of the currently running process into its PCB, then select another process to run, load its state into the processor, and then execute a return from syscall instruction to branch to the new process.

The PCB stores all of the information the OS needs about a process. This includes (but is not limited to):