xv6 Overview - ZHILING LANbluesky.cs.iit.edu/cs450/slides/04-xv6.pdfxv6 is a monolithic,...

20
Science Computer Science xv6 Overview CS 450: Operating Systems Sean Wallace <[email protected]>

Transcript of xv6 Overview - ZHILING LANbluesky.cs.iit.edu/cs450/slides/04-xv6.pdfxv6 is a monolithic,...

  • ScienceComputer Science

    xv6 OverviewCS 450: Operating Systems

    Sean Wallace

  • Agenda• Architectural overview

    • Features & limitations

    • Hardware decencies/features

    • Code review

    • Headers and Process structures

    • Bootstrap procedure

    • Scheduling & Context switching

    • Sleep & Wakeup

    • Trap/Syscall mechanism

    2

  • Architectural Overview

    3

  • xv6 is a monolithic, preemptively-multitasked, multiprocessor-capable, 32-bit, UNIX-like operating system.

    4

  • • Some limitations:

    • Max addressable memory: 2GB

    • Few supported devices (e.g., no network)

    • No support for kernel-level threading

    5

  • Limited syscall API

    6

    System Call Descriptionfork() Create processexit() Terminate current processwait() Wait for a child process to exitkill(pid) Terminate process pidgetpid() Return current process’s idsleep(n) Sleep for n secondsexec(filename, *argv) Load a file and execute itsbrk(n) Grow process’s memory by n bytesopen(filename, flags) Open a file; flags indicate read/writeread(fd, buf, n) Read n bytes from an open file into bufwrite(fd, buf, n) Write n bytes to an open fileclose(fd) Release open file fddup(fd) Duplicate fdpipe(p) Create a pipe and return fd’s in pchdir(dirname) Change the current directory mkdir(dirname) Create a new directorymknod(name, major, minor) Create a device filefstat(fd) Return info about an open filelink(f1, f2) Create another name (f2) for the file f1unlink(filename) Remove a file

  • • 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!

    7

  • Hardware Dependencies / Features

    8

  • • xv6 run 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)

    9

  • • 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

    10

  • CPL is actually part of the %cs register, which specifics the code segment address.

    %cs and %eip (x86 PC) identify an instruction to execute and its privilege level.

    11

  • • But CPL cannot be modified directly!

    • Lower (raise priority) via int instruction.

    • Raise (lower priority) via iret instruction.

    12

  • • int instruction (and hardware 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

    13

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

    14

  • 15

    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)

    PagingSegmentation

    Address

    Page

  • Linear Address Space(or Physical Memory)

    SegmentRegisters

    CS

    SegmentDescriptors

    LimitAccessBase Address

    SS LimitAccessBase Address

    DS LimitAccessBase Address

    ES LimitAccessBase Address

    FS LimitAccessBase Address

    GS LimitAccessBase Address

    LimitAccessBase Address

    LimitAccessBase Address

    LimitAccessBase Address

    LimitAccessBase Address

    Stack

    Code

    Data

    Data

    Data

    Data

    Segment Descriptors16

  • Linear Address Space

    (or Physical Memory)

    Data and

    FFFFFFFFHSegment

    LimitAccess

    Base Address

    Registers

    CS

    SS

    DS

    ES

    FS

    GS

    Code

    0

    Code- and Data-Segment

    Descriptors

    Stack

    Not Present

    “Flat” Model17

  • 0

    Directory Table Offset

    Page Directory

    PDE with PS=0

    CR3

    Page Table

    PTE

    4-KByte Page

    Physical Address

    31 21 111222

    Linear Address

    32

    10

    12

    10

    20

    20

    IA-32 Paging (4KB Pages)18

  • 19

  • Demo & Code Review

    20