CS4414

  • xv6 の講義

lecture1 What are OSes?

Piazza: kind a LETUS?

xv6:

  • simplified OS based on old unix
    • created by MIT

goal: protection

kernel mode, user mode
address transition

exception: changes user mode to kernel mode

interrupts: trigger by external event

  • ex. ketboard, network
    fault: bad triggered by program. ex. invalid memry access, dev by 0
    traps: triggered by explicit program action ex. syscall
    aborts: something hw broke

allocationg memory, r/w file need privileged instructions
-> run in kernel mode

iret: switch back to user mode
priviliged ops(ex. change mem layout, i/o, exceptions) allowed in kernel mode

unix layer

app -(stdlib fns)- stdlib/shell -(syscall)- kernel -(hw interface)- hardware

xv6

  • based on 6th edition unix
  • moded multicore, use 32-bit x86

write syscall in xv6: user mode

movl $16, %eax
int $0x40

eax: syscall num
int: interupts

write: int $0x40

lecture2

2022-03-21

interrupt table setup

trap.c(run on boot)

lidt(idt, sizeof(idt)) # sets the interrupt descriptor table, table of handler functions for each interrupt type
SETGATE(idt[T_SYSCALL], 1, SEG_KCODE<<3, vectors[T_SYSCALL], DPL_USER)

the trap function

trap(struct trapframe *tf)
myproc(): pseudo-global variable: currently running process

if tf->trapno == T_SYSCALL && myproc is not killed: syscall()
otherwise: exit()

syscall function

syscall num check && syscalls[curproc->tf->eax](): func ptrs

syswrite

write(file, buffer, size) = (f, p, n)
do validation: returns -1 means error

xv6 memory layout

larger addresses: for kernel (larger to KERNBASE)
free memory: kernel stack allocated(processor switches stacks)
1 kernel stack/process

  • todo user memory space are not mapped to phys addresses space?

timer interrupt

yield(): maybe context switch
wakeup(): sleep syscall
lapiceoi(): tell hardware we have handle this interrupt

I/O

ide: disk interface
kbd: ketboard
uart: serial port(external terminal)

case T_IRQ0 + IRQ_IDE: ideintr(); lapiceoi();

質問への回答の後, make sence? って聞くのかっこいい

context switch

switch threads, user address spaces + kernel stack (to use for exception)

thread switching

struct context {
uint edi, esi, ebx, ebp // register values, esp: stack ptr
uint eip // PC
}

void swtch(struct context **old, struct context *new)

swtch.s

watchlater 54:00まで見た

参考文献