Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.

Slides:



Advertisements
Similar presentations
Processor Privilege-Levels
Advertisements

1 Homework Reading –Intel 8254 Programmable Interval Timer (PIT) Data Sheet Machine Projects –Continue on MP3 Labs –Continue in labs with your assigned.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
Unit 4 Chapter-1 Multitasking. The Task State Segment.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Ring-transitions for EM64T How the CPU can accomplish transitions among its differing privilege-levels in 64-bit mode.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Task-Switching How the x86 processor assists with context-switching among multiple program-threads.
Exceptions and Interrupts
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Processor Exceptions A survey of the x86 exceptions and mechanism for handling faults, traps, and aborts.
8086 emulation Using Virtual-8086 mode to execute real-mode procedures in a protected-mode environment.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
EM64T ‘fast’ system-calls A look at the requirements for using Intel’s ‘syscall’ and ‘sysret’ instructions in 64-bit mode.
Page-Faults in Linux How can we study the handling of page-fault exceptions?
Exceptions and Interrupts How does Linux handle service- requests from the cpu and from the peripheral devices?
The various x86 ‘modes’ On understanding key differences among the processor’s several execution-architectures.
Processor Privilege-Levels How the x86 processor accomplishes transitions among its four distinct privilege-levels.
Deferred segment-loading An exercise on implementing the concept of ‘load-on-demand’ for the program-segments in an ELF executable file.
Venturing into protected-mode A first look at the CPU registers and instructions which provide the essential supporting infrastructure.
Timeout for some demos An instructive look at how the Linux Operating System sets up system data-structures.
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
1 CE6105 Linux 作業系統 Linux Operating System 許 富 皓.
Resolving interrupt conflicts An introduction to reprogramming of the 8259A Interrupt Controllers.
Processor Exceptions A survey of the x86 exceptions and mechanism for handling faults, traps, and aborts.
The Keyboard Controller Essential steps for implementing an interrupt service routine for the Keyboard Controller.
Resolving interrupt conflicts An introduction to reprogramming of the 8259A Interrupt Controllers.
Task-Switching How the x86 processor assists with context-switching among multiple program-threads.
The i/o-sensitive instructions An introduction to the software emulation of i/o-sensitive instructions in Virtual-8086 mode.
Linux Operating System
Linux Operating System
Venturing into protected-mode
The Keyboard Controller Essential steps for implementing an interrupt service routine for the Keyboard Controller.
Introduction to Interrupts
Homework / Exam Return and Review Exam #1 Reading Machine Projects
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2012 Lecture 15: Protected mode intro.
8086 emulation Using Virtual-8086 mode to execute real-mode procedures in a protected-mode environment.
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
Interrupts – (Chapter 12)
UNIT 2 Memory Management Unit and Segment Description and Paging
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Interrupts in the guest VM A look at the steps needed to “reflect” hardware interrupts back into the ROM-BIOS for servicing.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
1 i386 Memory Management Professor Ching-Chi Hsu 1998 年 4 月.
EFLAG Register of The The only new flag bit is the AC alignment check, used to indicate that the microprocessor has accessed a word at an odd.
Microprocessor system architectures – IA32 tasks Jakub Yaghob.
7. IRQ and PIC ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Information Security - 2. Task Switching Every process has an associated Task State Segment, whose starting point is stored in the Task register. A task.
BIOS and DOS Interrupts Basic Input /Outpu System Disk Operating System.
1 Interrupts A Course in Microprocessor Electrical Engineering Dept. University of Indonesia.
Homework / Exam Return and Review Exam #1 Reading Machine Projects
Homework Reading Machine Projects Labs
Interrupts and exceptions
Descriptor Table & Register
Microprocessor and Assembly Language
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Homework Reading Machine Projects Labs
Anton Burtsev February, 2017
Discussions on hw5 Objectives:
Interrupts In 8085 and 8086.
Homework Reading Labs S&S Extracts ,
Interrupts – (Chapter 12)
x86 segmentation, page tables, and interrupts
8259 Chip The Intel 8259 is a family of Programmable Interrupt Controllers (PIC) designed and developed for use with the Intel 8085 and Intel 8086 microprocessors.
Interrupt Driven I/O References Text: Tanenbaum ch.1.4.3, ch Receiver Interrupt Program Example:
Discussions on hw5 Objectives:
Presentation transcript:

Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt

Rationale Usefulness of a general-purpose computer is dependent on its ability to interact with various peripheral devices attached to it (e.g., keyboard, display, disk-drives, etc.) Devices require a prompt response from the cpu when various events occur, even when the cpu is busy running a program The x86 interrupt-mechanism provides this

New requirements Unlike real-mode, where all code executes with full privileges (i.e., ring 0), protected- mode code usually is executed with some privilege restrictions Normally these restrictions prevent direct control of the peripheral devices Thus, when responding to an interrupt in protected-mode, a ring-transition (and its accompanying stack-switch) are needed

Interrupt-Gate Descriptors start-offset[ ] code-segment selectorstart-offset[ ] gate type P0 DPLDPL Legend: P=present (1=yes, 0=no) DPL=Descriptor Privilege-Level (0,1,2,3) code-selector (specifies memory-segment containing procedure code) start-offset (specifies the procedure’s entry-point within its code-segment) gate-types: 0x6 = 16bit Interrupt-Gate, 0x7 = 16-bit Trap-Gate 0xE = 32bit Interrupt-Gate, 0xF = 32-bit Trap-Gate

Trap-Gate vs. Interrupt-Gate The only distinction between a Trap-Gate and an Interrupt-Gate is in whether or not the CPU will automatically clear the IF-bit (Interrupt-Flag in EFLAGS register) as part of its response to an interrupt-request This is needed in cases where an Interrupt Service Routine executes outside ring0, so could not execute ‘cli’ or ‘sti’ instructions

16bit-Gate vs. 32bit-Gate The CPU constructs different stackframes for the 16-bit versus the 32-bit gate-types IP CS FLAGS SP SS EIP EFLAGS ESP SS:SPSS:ESP 16-bits32-bits CS SS

Return-from-Interrupt The programmer who writes an Interrupt Service Routine must know whether the Gate was 16-bit or 32-bit, in order to use the correct ‘interrupt-return’ instruction In a code-segment whose default-bit is 0 (i.e., USE16), the ‘iret’ instruction performs the correct return-actions for a 16-bit Gate Use ‘iretd’ for returning with a 32-bit Gate

Interrupt Descriptor Table The Gate-Descriptors for device interrupts form an array (called the IDT) and reside in a special system memory-segment The CPU will locate the IDT by referring to the value in its IDTR register (48-bits) A pair of special instructions exists which allow reading and writing this register: –sidt [mem]; store IDTR to memory-operand –lidt [mem] ; load IDTR from memory-operand

Format of register IDTR base_address[ ]segment-limit[ ] bits32-bits The instruction ‘lidt’ is privileged (can only be executed in ring 0), but the instruction ‘sidt’ is unprivileged (it can execute in any ring) These features are analogous to the instructions ‘sgdt’ and ‘lgdt’ used to store or to load GDTR (Global Descriptor Table Register)

Register relationships GDTR IDTR Interrupt-gate code-descriptor Interrupt Descriptor Table (256 entries) ISR code-segment Global Descriptor Table INT ID

Two Interrupt-Controllers x86 CPU Master PIC Slave PIC INTR Programmable Interval-TimerKeyboard controller

Each PIC has a Mask Register IRQ 7 IRQ 6 IRQ 5 IRQ 4 IRQ 3 IRQ 2 IRQ 1 IRQ 0 Master PIC Interrupt-mask (I/O-port 0x21) IRQ 15 IRQ 14 IRQ 13 IRQ 12 IRQ 11 IRQ 10 IRQ 9 IRQ 8 Slave PIC Interrupt-mask (I/O-port 0xA1) If mask-bit is 1, the corresponding device-interrupts are masked; if mask-bit is 0, the corresponding device-interrupts are unmasked

Demo-program: ‘tickdemo.s’ Let’s look at a protected-mode program that handles the timer-tick interrupts Its ISR (Interrupt Service Routine) is very similar to the real-mode interrupt-handler It increments a 32-bit counter (at 40:6C), and it sets a flag (at 40:70) at midnight It decrements an 8-bit counter (at 40:40), and turns off diskette motors when zero It sends EOI-notification to Master PIC

Defining INT-8 Gate-Descriptor 0x0000 sel_CSisrPIT 0x bit Interrupt-Gate selector for ring0 code-segment label for the interrupt-handler’s entry-point P=1 DPL=0 type=6

Key Steps in the Demo Initialize the Descriptor-Table(s) Enter Protected-Mode with IF=0 Load GDTR, IDTR and segment-selectors Mask all device-interrupts except timer Set IF=1 to enable interrupts Continuously show tick-count (for 10secs) Reset IF=0 to disable interrupts (for exit)

In-class Exercise Apply your knowledge of privilege-rings to modify this demo so that its main routine (i.e., ‘exec_timer_tick_demo’) executes at privilege-level 3 (instead of at ring 0) You will need to add more descriptors to the Global Descriptor Table (for code and stack at ring3), and also a Call-Gate for returning to ring0 from ring3 (for quitting)