1 / 33

CS552

CS552. Overview. Generalized O/S structure. Basic interrupt handler Determines cause Uses branch table to specific handler I/O manager Performs I/O for the user’s requests Directly Via drivers Paging Basic error handling Scheduler Dispatcher.

jcarma
Download Presentation

CS552

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS552 Overview

  2. Generalized O/S structure • Basic interrupt handler • Determines cause • Uses branch table to specific handler • I/O manager • Performs I/O for the user’s requests • Directly • Via drivers • Paging • Basic error handling • Scheduler • Dispatcher

  3. Generalized O/S Operation“Booting” & login • Load self into RAM • Display logon screen • Enter h/w wait state - NO CPU cycles occur • Display pressed keys on screen • Call logon manager • Create a Process Control Block for user • Create an address space for user • Load GUI code into user’s address space • Load “user mode” state with address of GUI

  4. Generalized GUI Operation • Create windows and buttons • Wait for user interaction • User presses keys or uses mouse • I/O interrupt occurs (hardware gate flips) • O/S • handles interrupt (in kernel mode) • posts a flag for GUI to see • Value of key pressed • position of mouse • Returns to GUI in user mode (always) • GUI performs required action on the screen

  5. Kernel Basics • States • State vectors • Interrupts • Contexts • Context switching • Reserved RAM

  6. Remainder of Course • Paging • Scheduling & Dispatching • Virtualization • Multi-tasking • File & storage systems • Deadlock • Security & reliability • Distributed systems

  7. Basic Computer Architecture

  8. Components • Elementary instructions • Load • Add, subtract, etc • Store • Compare • Branch • Data access • Register (like a pointer) • Displacement • offset or “distance in bytes, from register contents

  9. Instruction types • Risc • Operation code and one operand • e.g. L x loads content of x into an accumulator • CISC • Operation code and TWO operands • e.g. L x,y loads contents of y into register x

  10. States • Define current machine capabilities • Interrupts allowed or not • Privileged instructions allowed or not • (ie; kernel mode vs. user mode) • Memory protection key or state (# and/or on/off) • Next sequential instruction to perform • Addressing mode • User-mode flag (div by 0, etc)

  11. Current State Vector • Contains the state information • Is NOT a memory location or data structure • Changeable by events (interrupts) • I/O completion or external signals • Machine failure, program failure (÷0), service call • Changeable by privileged instructions • Vector is loaded from data in RAM • Saved to RAM by hardware events

  12. Interrupts

  13. Interrupts - Generalized • Two types • Hardware (MAY be “turned off” by kernel) • I/O • Clock/interval timer • Program exception (e.g.; div by 0) • Paging • Addressing (32/64 bit) • Software (Service call - ALWAYS allowed) • Program requests for kernel service • Machine language instruction causes hardware “trap” • Int 0x80 PC style (‘n’ is on stack) • SVC n z/390 style

  14. Instruction Processing with Interrupts No No Interruptsallowed? Interrupt pending? yes fetch execute previousinst yes processinterrupt

  15. Trap or System CallInstruction • Atomic operation • Causes an interrupt (type=service request) • Kernel processes normally • Common service request handler • Uses code to select address in trap table • Trap table contains addresses of specific programs for specific request

  16. Traps or Kernel Calls • Examples • Cout << x; • Seek (device, position); • X=ftime(); • User functions expand into assembly code for a "trap" or "svc" instruction • "trap" causes a H/W switch to the kernel • Kernel performs op and returns to user

  17. fork (My_fork_loc); { ● ● ● trap (K_FORK, *My_fork_loc); } My_fork_loc:…; System call example User space Kernel space Traptable Do_fork(loc) { ● ● start_process (loc); mode=0; return; } *Do_fork *Do_fork Kernel space K_fork is entry # for "FORK"

  18. x86 specific Interrupts

  19. Allowing x86 interrupts • The x86 has an interrupt flag (IF) in the FLAGS register. Only for hardware interrupts. • cli sets this flag to 0 - disabled • sti sets it to 1 - enabled • Instructions that load values into the FLAGS register (such as popf and iret) may also modify this flag.

  20. X86 specific - 2 • int arg • int 0x04 • Calls interrupt handler #4, IF overflow flag is set • int 0x80 • Calls the service-call handler

  21. Example: the setuid system call • Coded as: _syscall1(int,setuid, uid_t, uid); expands to: _setuid: subl $4,%exp pushl %ebx movzwl 12(%esp),%eax movl %eax,4(%esp) movl $23,%eax movl 4(%esp),%ebx int $0x80 --->trap into kernel movl %eax,%edx --return from kernel testl %edx,%edx jge L2 negl %edx movl %edx,_errno movl $-1,%eax popl %ebx addl $4,%esp ret L2: movl %edx,%eax popl %ebx addl $4,%esp ret

  22. z/390 specific Interrupts

  23. Allowing z/390 interrupts • Program Status Word controls hardware interrupts • Bits 0-7 • Bits 20-23 • (fixedpoint overflow, decimal overflow, exp underflow, significance) • LPSW instruction loads all 64 bits of status • SSM instruction sets individual bits 0-7 only • See slides on setting Machine State

  24. Reserved space in RAM • Allows software/hardware interaction • Different for every machine architecture • Key to understanding of machine control • Key to understanding of Operating Systems

  25. Contexts

  26. User Mode • Normal programs: • (payroll, taxes, compilers, etc.) • Cannot perform ANY privileged instructions • Cannot branch or jump into kernel • Kernel does not branch or jump to user code • MUST use a “state switch” instruction • Must use “exposed” functions via Service Calls

  27. Kernel Mode • Can access ANY memory • Can use ANY instructions • NOT for doing “problem solving” • Manages users • Pages • Access to CPU • Access to devices (disk, monitor, etc)

  28. Context SwitchingFrom Kernel To User • Set up values for new state vector • Save any kernel registers and stack data • Atomic state change • Interrupts on • Privilege off • Memory protect on • Set IC

  29. Context SwitchingFrom User to Kernel • Set up values for service call • Issue service call (assembler instruction) • Atomic state change occurs • Interrupts off • Privilege on • Memory protect off • Set IC to predefined interrupt handler in kernel • Save any user’s registers and stack data

  30. Reserved RAM • Defined in hardware • Used by kernel only • Same for ANY O/S on that type of machine: • IBM-compatible PC • z/390 • MAC • powerPC • Sun

  31. paired paired

  32. PC-bootable disk layout 0x00-0x02 jump inst to 0x1e 0x03-0x0a PC manufacturer name 0x0b-0x0c sectors/cluster 0x0d-0x0f reserved for boot record 0x10-0x10 # of FAT's 0x11-0x12 # root directory entries 0x13-0x14 # logical sectors 0x15-0x15 media descriptor 0x16-0x17 sectors/FAT 0x18-0x19 sectors/track 0x1a-0x10b # surfaces (heads) 0x1c-0x1d # hidden sectors 0x1e-… boot program

  33. Preparing for Interrupts (PC) • BIOS loads the initial address of the IDT table into the idtr register • Linux init moves & re-inits the table • setup_idt( ) – an assembly language function • fills all of idt_table with ignore(int) • 2nd pass – fills in true handlers • Enable interrupts

More Related