Lecture 005

x86 Privilege

Has 4 privilege levels: to protect data and prevent user from executing privileged instruction (modify control registers or change how the processor is running)

For project 2~4, PL0 is kernel, PL3 is user. Interrupts, exception usually transfer from PL3 to PL0 (sometimes PL0 to PL0 page fault). Running user code means getting from PL0 to PL3

Linear Virtual Address

Memory segment: a range of the same variety of memory

x86-32 has mandatory segments: each has privilege levels

Segment Related Stuff:

When the processor fetches an instruction, it asks for an address of the form CS:EIP. So if %EIP is 0x100, this indicates the 256'th byte of the CS segment.

Segment selector bit pattern

Segment selector bit pattern

Segment descriptor bit pattern

Segment descriptor bit pattern

When calculating instruction pointer address:

When doing PUSH, POP, MOVL, the instruction specifies which segment register to use (%SS for PUSH, POP, %DS for MOVL). Note that the base address for all segments can be the same, and the limit can all be infinity. Which renders the while segment thing useless, except for making hardware happy so that they have different access permission (you can not have one segment that has all read, write, execute permission). So it's main job isn't address space translation, but permission separation. In modern CPU and OS, this segment table does not exist.

For this semester, we have 4 segments:

See: Here for more details.

Segments need not to be fully backed by physical memory, and can overlap

Exception, Trap, Interrupt

Kind of instruction

Synchronous "surprises": cannot be deferred

Asynchronous "surprises" can be deferred (I/O)

What happens:

Exception: PARTICULAR instruction violate pre-condition

Trap: PARTICULAR instruction ask system for help

Interrupt: an I/O device needs attention

device get kernel's attention by raising a hardware interrupt as well

When exception

Device Interrupt

Programmable Interrupt Controller (PIC)

Two daisy-chained PICs

Two daisy-chained PICs

Inside PICs

Inside PICs

When device has some bytes to send. It first tell processor that there are bytes. Processor will ask which bytes, device will respond. Finally processor will indicate that it has finished processing those bytes, and device can send next interrupt.

When device has some bytes to send. It first tell processor that there are bytes. Processor will ask which bytes, device will respond. Finally processor will indicate that it has finished processing those bytes, and device can send next interrupt.

Interrupt Management:

Interrupt Discriptor Table (IDT): maps interrupt/exception/trap (one table for all) to a function pointer and some flags

More info on section 5.12 of intel-sys.pdf

Trap Gate: an entry in the IDT looks like this

Trap Gate: an entry in the IDT looks like this

Device Communication

inb(port), outb(port, data): controlled by I/O ports (cursor)

Memory mapped IO: communication via virtual memory (video memory for screen display)

I/O ports:

Sample interaction for transmitting 2 bytes:

outb(command_port, SELECT_R12_LOWER);
outb(data_port, 32);
outb(command_port, SELECT_R12_UPPER);
outb(data_port, 0);

Simics

P1 Makefile: build floppy disk images

Simics boots and runs simics60 in build directory

Uses xchg %bx, %bx as breakpoint for debugging

scriptable using python

Table of Content