xv6 Overview CS 450 : Operating Systems Michael Saelee - - PowerPoint PPT Presentation

xv6 overview
SMART_READER_LITE
LIVE PREVIEW

xv6 Overview CS 450 : Operating Systems Michael Saelee - - PowerPoint PPT Presentation

xv6 Overview CS 450 : Operating Systems Michael Saelee <lee@iit.edu> Computer Science Science Agenda - Architectural overview - Features & limitations - Hardware dependencies/features Computer Science Science Agenda - Code


slide-1
SLIDE 1

xv6 Overview

CS 450 : Operating Systems Michael Saelee <lee@iit.edu>

slide-2
SLIDE 2

Computer Science Science

Agenda

  • Architectural overview
  • Features & limitations
  • Hardware dependencies/features
slide-3
SLIDE 3

Computer Science Science

Agenda

  • Code review:
  • Headers and Process structures
  • Bootstrap procedure
  • Scheduling & Context switching
  • Sleep & Wakeup
  • Trap / Syscall mechanism
slide-4
SLIDE 4

Computer Science Science

§Architectural Overview

slide-5
SLIDE 5

Computer Science Science

xv6 is a monolithic, preemptively-multitasked, multiprocessor-capable, 32-bit, UNIX-like

  • perating system
slide-6
SLIDE 6

Computer Science Science

some limitations:

  • max addressable memory: 2GB
  • few supported devices (e.g., no network)
  • no support for kernel-level threading
slide-7
SLIDE 7

Computer Science Science

System call Description fork() Create process exit() Terminate current process wait() Wait for a child process to exit kill(pid) Terminate process pid getpid() Return current process’s id sleep(n) Sleep for n seconds exec(filename, *argv) Load a file and execute it sbrk(n) Grow process’s memory by n bytes

  • pen(filename, flags)

Open a file; flags indicate read/write read(fd, buf, n) Read n byes from an open file into buf write(fd, buf, n) Write n bytes to an open file close(fd) Release open file fd dup(fd) Duplicate fd pipe(p) Create a pipe and return fd’s in p chdir(dirname) Change the current directory mkdir(dirname) Create a new directory mknod(name, major, minor) Create a device file fstat(fd) Return info about an open file link(f1, f2) Create another name (f2) for the file f1 unlink(filename) Remove a file

limited syscall API:

slide-8
SLIDE 8

Computer Science Science

very limited set of user-level programs:

  • shell, cat, echo, grep, kill, 


ln, ls, mkdir, rm, wc

  • no compiler/debugger/editor
  • development (kernel/user) takes

place on another platform!

slide-9
SLIDE 9

Computer Science Science

§Hardware Dependencies / Features

slide-10
SLIDE 10

Computer Science Science

xv6 runs on an x86 (Intel) processor, and relies on many of its hardware features e.g., privilege levels (kernel/user mode), interrupt vector & procedure, segmentation & paging (VM)

slide-11
SLIDE 11

Computer Science Science

Recall: 2-bit current privilege level (CPL) flag

  • CPL=3 ➞ “user” mode
  • CPL=0 ➞ “supervisor/kernel” mode
  • guards special instructions & hardware
  • also restricts access to interrupt 


& VM structures

slide-12
SLIDE 12

Computer Science Science

CPL is actually part of the %cs register, which specifies the code segment address %cs and %eip (x86 PC) identify an instruction to execute and its privilege level

slide-13
SLIDE 13

Computer Science Science

but CPL cannot be modified directly!

  • lower (raise priority) via int instruction
  • raise (lower priority) via iret instruction
slide-14
SLIDE 14

Computer Science Science

int instruction (and h.w. interrupt) result in interrupt descriptor table (IDT) lookup

  • fetches target %cs and %eip (aka

“gate”) for corresponding handler

  • restricts entry points into kernel
  • install base address of IDT with lidt
slide-15
SLIDE 15

Computer Science Science

xv6 also relies on x86 segmentation and paging to implement virtual memory

slide-16
SLIDE 16

Computer Science Science

Global Descriptor Table (GDT) Linear Address Space Segment Segment Descriptor Offset Logical Address Segment Base Address Page

  • Phy. Addr.
  • Lin. Addr.

Segment Selector Dir Table Offset Linear Address Page Table Page Directory Entry Physical Space Entry (or Far Pointer) Paging Segmentation Address Page

slide-17
SLIDE 17

Computer Science Science

Linear Address Space (or Physical Memory) Segment Registers CS Segment Descriptors Limit Access Base Address SS Limit Access Base Address DS Limit Access Base Address ES Limit Access Base Address FS Limit Access Base Address GS Limit Access Base Address Limit Access Base Address Limit Access Base Address Limit Access Base Address Limit Access Base Address Stack Code Data Data Data Data

Segment descriptors

slide-18
SLIDE 18

Computer Science Science

“Flat” model

Linear Address Space (or Physical Memory) Data and FFFFFFFFH Segment Limit Access Base Address Registers CS SS DS ES FS GS Code Code- and Data-Segment Descriptors Stack Not Present

slide-19
SLIDE 19

Computer Science Science

IA-32 paging (4KB pages)

Directory Table Offset Page Directory PDE with PS=0 CR3 Page Table PTE 4-KByte Page Physical Address 31 21 11 12 22 Linear Address 32 10 12 10 20 20

slide-20
SLIDE 20

Computer Science Science

Physical Page Number A V L D

6

A

5

C D

4

W T

3

U

2

W

1

P

7 8 9 10 11 12 31

P W U WT CD A D AVL

  • Present
  • Writable
  • User
  • 1=Write-through, 0=Write-back
  • Cache Disabled
  • Accessed
  • Dirty (0 in page directory)
  • Available for system use

20

VIrtual address Physical Address

12 10

Dir T able Offset

10

1 1023 PPN Flags

20 12 12

PPN Offset PPN Flags 1 1023

20 12

Page T able CR3 Page table and page directory entries are identical except for the D bit.

slide-21
SLIDE 21

Computer Science Science

§Demo & Code Review