Operating Systems Engineering
Based on MIT 6.828 (2014, lec3-5)
Operating Systems Engineering Recitation 2: Boot and fjrst process - - PowerPoint PPT Presentation
Operating Systems Engineering Recitation 2: Boot and fjrst process Based on MIT 6.828 (2014, lec3-5) Focus on xv6 An educational OS based on UNIX V6 only a few abstractions \ services Processes File system I/O (via fjle
Based on MIT 6.828 (2014, lec3-5)
– nothing in RAM, need to read kernel from disk
– copy fjrst “boot” sector to 0x7c00 in mem – boot sector = bootasm.S + bootmain.c – executing at end of bootasm.S – stack below 0x7c00, so we can call into C – call bootmain
– bootmain() – sheet 85
– copy kernel from disk to mem (0x100000 phys addr)
– jump to kernel's fjrst instruction
– can't use 0x0
memory mapped devices 0x0->1M →
– can use 0x200000 (2MB)?
– it is a DRAM address – kernel must be able to fjnd itself
– entry->elf_entry from ELF header – not 0x100000 but 0x10000c
– linker put 0x10000c in the ELF header
#0 0x801033b2 in main () at main.c:19
– instructions - actual computation fmow – data - variables used in computation – stack – organize procedures calls
– page table – kernel stack – fjle descriptor table
– Separated memory, fjle descriptors – Prevent resource exhaustion (fairness)
– Against buggy programs – Against malicious programs
cs: CPL
– CPL in low 2 bits of CS – CPL=0 -> can modify cr*, devices, can use any PTE – CPL=3 -> can't modify cr*, or use devs, and PTE_U enforced
– set CPL=0 – jump sys_open()
the user to jump to a kernel address?
– saves the values of cs and eip on stack – system call returns with iret – restores old cs and eip
– UNUSED, EMBRYO, SLEEPING, RUNNABLE,
RUNNING, ZOMBIE
– program memory (<0x80000000) – kernel instructions and data (>0x80100000)
– p->kstack + code – p->state – p->pgdir
– thread state stored in kernel stack:
main() sheet 12 →
– allocproc() sheet 22, set up stack for "returning" to user space
– Fill in kernel part of address space (setupkvm) – Fill in user part of address space
– Setup trapframe to exit kernel
– Set process to runnable
trapret:
popal popl %gs popl %fs popl %es popl %ds addl $0x8, %esp # trapno # and errcode iret
– replace initcode with /init binary – run /init which
Questions?
Backup Slides
hardware mechanisms
privileges
– easy kernel subsystem interactions
– complex interactions => bugs => system crash – no isolation in the kernel
– A micro kernel tries to run most
services as daemons in user space.
speed context-switching engine
– complex service interactions => bugs => service crash but system alive! – kernel isolated from services, services isolated from user
– complex OS subsystem interactions using IPC – a lot of of messaging and context switching involved
– concept of an exokernel is orthogonal
to that of micro- vs. monolithic kernels.
– there are no forced abstractions – security separated from abstraction
privileges
– simplicity and performance – freedom: users can implement their own optimal subsystems
– additional efgort from users and system maintainers