Download presentation
Presentation is loading. Please wait.
Published byNancy McBride Modified over 9 years ago
1
CS552 Overview © 2009, D. J. Foreman1
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 © 2009, D. J. Foreman2
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 © 2009, D. J. Foreman3
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 © 2009, D. J. Foreman4
5
Kernel Basics States State vectors Interrupts Contexts Context switching Reserved RAM © 2009, D. J. Foreman5
6
Remainder of Course Paging Scheduling & Dispatching Virtualization Multi-tasking File & storage systems Deadlock Security & reliability Distributed systems © 2009, D. J. Foreman6
7
Basic Computer Architecture © 2009, D. J. Foreman7
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 © 2009, D. J. Foreman8
9
Instruction types Risc – Operation code and one operand – e.g.Lx loads content of x into an accumulator CISC – Operation code and TWO operands – e.g.Lx,y loads contents of y into register x © 2009, D. J. Foreman9
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) © 2009, D. J. Foreman10
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 © 2009, D. J. Foreman11
12
Interrupts © 2009, D. J. Foreman12
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 0x80PC style (‘n’ is on stack) – SVCnz/390 style © 2009, D. J. Foreman13
14
© 2009, D. J. Foreman14 Instruction Processing with Interrupts fetchexecute Interrupts allowed? No yes previous inst Interrupt pending? No process interrupt yes
15
© 2009, D. J. Foreman15 Trap or System Call Instruction 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
© 2009, D. J. Foreman16 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
© 2009, D. J. Foreman17 System call example fork (My_fork_loc); {● ● trap (K_FORK, *My_fork_loc); } My_fork_loc:…; *Do_fork Do_fork(loc) { ● ● start_process (loc); mode=0; return; } Trap table *Do_fork User spaceKernel space K_fork is entry # for "FORK" Kernel space
18
x86 specific Interrupts © 2009, D. J. Foreman18
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. © 2009, D. J. Foreman19
20
X86 specific - 2 intarg int0x04 – Calls interrupt handler #4, IF overflow flag is set int0x80 – Calls the service-call handler © 2009, D. J. Foreman20
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 jgeL2 negl %edx movl %edx,_errno movl $-1,%eax popl %ebx addl $4,%esp ret L2: movl%edx,%eax popl %ebx addl $4,%esp ret © 2009, D. J. Foreman21
22
z/390 specific Interrupts © 2009, D. J. Foreman22
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 © 2009, D. J. Foreman23
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 © 2009, D. J. Foreman24
25
Contexts © 2009, D. J. Foreman25
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 © 2009, D. J. Foreman26
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) © 2009, D. J. Foreman27
28
Context Switching From 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 © 2009, D. J. Foreman28
29
Context Switching From 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 © 2009, D. J. Foreman29
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 © 2009, D. J. Foreman30
31
Hex addressIBM z/390 memory content 0IPL PSW or Restart PSW 8IPL CCW1 or Restart old PSW 10IPL CCW2 18External Old PSW 20Supervisor Call Old PSW 28Program Check Old PSW 30Machine Check Old PSW 38I/O Old PSW 58External New PSW 60Supervisor Call New PSW 68Program Check New PSW 70Machine Check New PSW 78I/O New PSW 80External interrupt data 88 (4 bytes)SVC interruption data: 13-14= ILC, 16-31= interruption code (SVC #) paired © 2009, D. J. Foreman31
32
© 2009, D. J. Foreman32 PC-bootable disk layout 0x00-0x02 jump inst to 0x1e 0x03-0x0aPC manufacturer name 0x0b-0x0csectors/cluster 0x0d-0x0freserved for boot record 0x10-0x10# of FAT's 0x11-0x12# root directory entries 0x13-0x14# logical sectors 0x15-0x15media descriptor 0x16-0x17sectors/FAT 0x18-0x19sectors/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) – 2 nd pass – fills in true handlers Enable interrupts © 2009, D. J. Foreman33
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.