The K Project. Interrupt and Exception Handling. LSE Team. May 14, 2018 EPITA. The K Project. LSE Team. Introduction. Interrupt Descriptor Table

Similar documents
+ Overview. Projects: Developing an OS Kernel for x86. ! Handling Intel Processor Exceptions: the Interrupt Descriptor Table (IDT)

These three counters can be programmed for either binary or BCD count.

The Purpose of Interrupt

Chapter 12: INTERRUPTS

Mechanisms for entering the system

7/19/2013. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to: Chapter Objectives 12 1 BASIC INTERRUPT PROCESSING

Chapter 12: Interrupts

An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal)

CS 3803 Lab 6 Interrupts Assigned 2/25/10 Point Value: 30

CS 550 Operating Systems Spring Interrupt

An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal)

8086 Interrupts and Interrupt Responses:

Homework. Reading. Machine Projects. Labs. Intel 8254 Programmable Interval Timer (PIT) Data Sheet. Continue on MP3

Week 11 Programmable Interrupt Controller

Chapter 8 PC Peripheral Chips - Pt 3 Interrupts

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

Interrupts. Chapter 20 S. Dandamudi. Outline. Exceptions

Computer Labs: I/O and Interrupts

BASIC INTERRUPT PROCESSING

UMBC. contain new IP while 4th and 5th bytes contain CS. CALL BX and CALL [BX] versions also exist. contain displacement added to IP.

Microkernel Construction

PC Interrupt Structure and 8259 DMA Controllers

Lecture-51 INTEL 8259A Programmable Interrupt Controller

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1

Homework / Exam. Return and Review Exam #1 Reading. Machine Projects. Labs. S&S Extracts , PIC Data Sheet. Start on mp3 (Due Class 19)

W4118: interrupt and system call. Junfeng Yang

UNIT - II PERIPHERAL INTERFACING WITH 8085

Co-processor Math Processor. Richa Upadhyay Prabhu. NMIMS s MPSTME February 9, 2016

2.5 Address Space. The IBM 6x86 CPU can directly address 64 KBytes of I/O space and 4 GBytes of physical memory (Figure 2-24).

1. What is Microprocessor? Give the power supply & clock frequency of 8085?

Operating Systems Engineering Recitation #3 (part 2): Interrupt and Exception Handling on the x86. (heavily) based on MIT 6.

Systems Programming and Computer Architecture ( ) Timothy Roscoe

27 December 2016 Pramod Ghimire. Slide 1 of 16

ECE 485/585 Microprocessor System Design

Microkernel Construction

Pre-virtualization internals

Programming the 8259 PIC: A Tech-Tip Example and Boilerplate

Topics. Interfacing chips

MATH CO-PROCESSOR 8087

Question Bank Microprocessor and Microcontroller

CS 550 Operating Systems Spring System Call

eaymanelshenawy.wordpress.com

EE458 - Embedded Systems Exceptions and Interrupts

UNIT-IV. The semiconductor memories are organized as two-dimensional arrays of memory locations.

The control of I/O devices is a major concern for OS designers

9/19/18. COS 318: Operating Systems. Overview. Important Times. Hardware of A Typical Computer. Today CPU. I/O bus. Network

Lecture-61 Initialization Control Word 2 (ICW2):

Reset, Interrupts, Exceptions, and Break ECE 3534

Lab 2: 80x86 Interrupts

4) In response to the the 8259A sets the highest priority ISR, bit and reset the corresponding IRR bit. The 8259A also places

CHAPTER 6 INTERRUPT AND EXCEPTION HANDLING

Interrupts. Embedded Systems Interfacing. 08 September 2011


S.R.M. INSTITUTE OF SCIENCE & TECHNOLOGY SCHOOL OF ELECTRONICS & COMMUNICATION ENGINEERING

MICROPROCESSOR TECHNOLOGY

Virtual Machines & the OS Kernel

Interrupts Peter Rounce

COS 318: Operating Systems

CS609 Final Term Solved MCQs with References Without Repetitions 14/02/2013

Northern India Engineering College, Delhi (GGSIP University) PAPER I

Interrupts Peter Rounce - room 6.18

INTERRUPTS in microprocessor systems

MICROPROCESSOR TECHNOLOGY

Interrupts. by Rahul Patel, Assistant Professor, EC Dept., Sankalchand Patel College of Engg.,Visnagar

8254 is a programmable interval timer. Which is widely used in clock driven digital circuits. with out timer there will not be proper synchronization

Operating Systems. System calls. Guillaume Salagnac. Fall Insa-Lyon IST Semester

EC6504 MICROPROCESSOR AND MICROCONTROLLER

Ceng 111 Fall 2015 Week 5b

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad

COS 318: Operating Systems

CSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018

b. List different system buses of 8085 microprocessor and give function of each bus. (8) Answer:

MPLAB X Debugging Techniques

Features: 3 8-bit IO ports PA, PB, PC. PA can be set for Modes 0, 1, 2. PB for 0,1 and PC for mode 0 and for BSR. Modes 1 and 2 are interrupt driven.

EC2304-MICROPROCESSOR AND MICROCONROLLERS 2 marks questions and answers UNIT-I

Architecture of 8086 Microprocessor

Windows Interrupts

CPUs. Input and output. Supervisor mode, exceptions, traps. Co-processors. Computers as Components 4e 2016 Marilyn Wolf

Overview. M. Krishna Kumar MM/M4/LU10/V1/2004 1

ECE 372 Microcontroller Design Parallel IO Ports - Interrupts. ECE 372 Microcontroller Design Parallel IO Ports - Interrupts

QUESTION BANK CS2252 MICROPROCESSOR AND MICROCONTROLLERS

Phoenix Technologies, Ltd.

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

Instruction Set Architecture of MIPS Processor

Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

Fredrick M. Cady. Assembly and С Programming forthefreescalehcs12 Microcontroller. шт.

sequence is not needed. (ROM space). Another application is to use the poll mode to expand the number of priority levels to more than 64.

9. PERIPHERAL CHIPS 9a

Understanding the Interrupt Control Unit of the 80C186EC/80C188EC Processor

IA32 Intel 32-bit Architecture

Microprocessors and Microcontrollers. Assignment 1:

CPS104 Computer Organization and Programming Lecture 17: Interrupts and Exceptions. Interrupts Exceptions and Traps. Visualizing an Interrupt

ECE 391 Exam 1 Review Session - Spring Brought to you by HKN

What are Exceptions? EE 457 Unit 8. Exception Processing. Exception Examples 1. Exceptions What Happens When Things Go Wrong

Microprocessors and Interfacng. Question bank

Unit wise Question Bank UNIT-II

For more notes of DAE

Embedded Systems Programming

CSC227: Operating Systems Fall Chapter 1 INTERRUPTS. Dr. Soha S. Zaghloul

Transcription:

and Exception Handling EPITA May 14, 2018 (EPITA) May 14, 2018 1 / 37

and Exception Handling Exception : Synchronous with program execution (e.g. division by zero, accessing an invalid address) : Asynchronous with program execution. Generated by devices external to the CPU (EPITA) May 14, 2018 2 / 37

Figure: IDT (EPITA) May 14, 2018 3 / 37

Register Figure: IDTR (EPITA) May 14, 2018 4 / 37

Load IDT idt_r idtr; idtr.base = idt; /* idt base address */ idtr.limit = sizeof(idt) - 1; /* idt size - 1 */ asm volatile("lidt %0\n" : /* no output */ : "m" (idtr) : "memory"); (EPITA) May 14, 2018 5 / 37

x86 Exceptions Int. Description 0 Divide by 0 1 Debug 2 NMI 3 Breakpoint 4 Overflow 5 Bound Range Exceeded 6 Invalid Opcode (EPITA) May 14, 2018 6 / 37

x86 Exceptions Int. Description 7 Device Not Available 8 Double Fault 9 Coprocessor 10 Invalid TSS 11 Segment not present 12 Stack Segment Fault 13 General Protection 14 Page Fault (EPITA) May 14, 2018 7 / 37

x86 Exceptions and s Int. Description 15 (Intel reserved) 16 x87 FPU (Math Fault) 17 Alignment Check 18 Machine Check 19 SMD Floating Point Ex. 20 Virtualization Ex. 21-31 (Intel reserved) 32-255 User Defined (EPITA) May 14, 2018 8 / 37

x86 int $3 int $0x80 ; Breakpoint ; Syscall Intel s definition, Vol2a The INT n instruction generates a call to the interrupt or exception handler specified with the destination operand (EPITA) May 14, 2018 9 / 37

Context Switching Figure: Stack Usage (EPITA) May 14, 2018 10 / 37

Context Switching isr: ;<save registers> pushl %esp call generic_c_handler add $4, %esp ;<restore registers> add $8, %esp iret.global isr_keyboard isr_keyboard: pushl $0 pushl $33 ; IRQ1 jmp isr (EPITA) May 14, 2018 11 / 37

Programmable Controller Figure: PIC (EPITA) May 14, 2018 12 / 37

Typical wiring of the PIC (Master) IRQ0 - PIT IRQ1 - IRQ2 - Not assigned in PC/XT; cascaded to slave 8256 IRQ3 - UART (COM2 and COM4) IRQ4 - UART (COM1 and COM3) IRQ5 - Hard disk in PC/XT; Parallel port LPT2 in PC/AT IRQ6 - Floppy disk controller IRQ7 - Parallel port LPT1 (EPITA) May 14, 2018 13 / 37

Typical wiring of the PIC (Slave) IRQ8 - RTC IRQ9 - IRQ10 - IRQ11 - IRQ12 - PS/2 mouse controller IRQ13 - Math coprocessor IRQ14 - Hard disk controller 1 IRQ15 - Hard disk controller 2 (EPITA) May 14, 2018 14 / 37

PIC ports 0x20, the master PIC s port A 0x21, the master PIC s port B 0xA0, the slave PIC s port A 0xA1, the slave PIC s port B (EPITA) May 14, 2018 15 / 37

ICW1 0 0 0 1 x 0 x x +---- (1) +------ (2) +---------- (3) 1 ICW4 present (set) or not (clear) 2 single controller (set) or cascade mode (clear) 3 level triggered mode (set) or edge triggered mode(clear) (EPITA) May 14, 2018 16 / 37

ICW2 x x x x x 0 0 0 +------------------ (1) 1 vector base address (EPITA) May 14, 2018 17 / 37

ICW3 Master PIC x x x x x x x x +------------------ (1) Slave PIC 0 0 0 0 0 x x x +-------- (2) 1 For each bit, indicate whether a slave PIC is connected to this pin (set) or not (clear) 2 Indicate to the slave his slave ID (which pin of the master it is connected to) (EPITA) May 14, 2018 18 / 37

ICW4 0 0 0 x x x x 1 --- +------ (1) +--------- (2) +------------ (3) 1 Automatic (set) EOI or normal (clear) EOI 2 Buffering mode 3 Special mode fully nested (set) or not (clear) (EPITA) May 14, 2018 19 / 37

OCW1 x x x x x x x x +------------------ (1) 1 For each bit, indicate whether the corresponding IRQ is masked (set) or not (clear) (EPITA) May 14, 2018 20 / 37

OCW2 x x x 0 0 x x x ----- +------ (1) +-------------- (2) +---------------- (3) +------------------ (4) 1 level to be acted upon when sending a specific command 2 Send an EOI (end of interrupt command) (set) 3 Send a specific (set) or a non-specific (clear) command 4 Rotate priorities (set) or not (clear) (EPITA) May 14, 2018 21 / 37

Recommended methodology Write IDT management fonctions allocate/clean IDT set an interrupt gate in the IDT set a trap gate in the IDT Write the context saving/restoring routines in assembly code Implement the exceptions and interrupts wrappers Write a function which builds the IDT and loads it Initialize the PIC send ICWs to both master and slave PICs mask all interrupts Write very simple debug handlers like: printing an error message when executing a division by zero printing a string when a key is pressed Do not forget to enable hardware interrupts using sti (EPITA) May 14, 2018 22 / 37

Possible bug causes You forgot to save or restore some registers in your context You did not consider that gcc automatically generates the prolog/epilog for C functions The stack is misaligned when iret is executed PICs are not acknowledged after returning from an ISR ( SubRoutine) (EPITA) May 14, 2018 23 / 37

Registers 0x60: I/0 buffer 0x64: Status register (EPITA) May 14, 2018 24 / 37

Status Register x x x x x x x x +---- Output buffer full +------ Input buffer full +-------- System flag +---------- Command/Data +------------ inhibit +-------------- Auxiliary device output buffer +---------------- General purpose time-out +------------------ Parity error (EPITA) May 14, 2018 25 / 37

scancode x x x x x x x x ------------- +--------- Key number +----------------- Key press (clear) or release (set) (EPITA) May 14, 2018 26 / 37

Recommended methodology Ensure that the event manager is working Initialize driver Add the keyboard interrupt gate to the IDT Update the PIC to unmask the IRQ line 1 Write a very simple keyboard handler: Read scancodes from I/O port 0x60 Extra features such as modifier keys or simultaneous key strikes support are not mandatory Implement getkey() You must implement a queue for the keyboard buffer (EPITA) May 14, 2018 27 / 37

- Possible bug causes Execution context may be corrupted. Hardware interrupts may have been disabled with cli or may not have been enabled with sti The keyboard interrupt may be masked in the PIC The previous IRQ has not been ACKED The previous key has not been fetched (EPITA) May 14, 2018 28 / 37

Programmable Interval Counter 0: fire an interrupt at a user-defined frequency. Counter 1: historically used in order to periodically refresh the RAM, but it not used anymore. Counter 2: linked with the PC speaker, so you can use it in order to generate sound (EPITA) May 14, 2018 29 / 37

PIT Operation Modes Mode 0: on terminal count Mode 1: hardware retriggerable one-shot Mode 2: rate generator Mode 3: square generator Mode 4: Software Triggered Strobe Mode 5: Hardware Triggered Strobe (EPITA) May 14, 2018 30 / 37

PIT Configuration c c io io m m m b ---- ----- ------- +-- (1) +-------- (2) +--------------- (3) +---------------------- (4) 1 Binary counter (unset) or BCD counter (set) 2 Mode to use (LSB first then MSB) 3 Registers read/write policy 4 Counter to setup (EPITA) May 14, 2018 31 / 37

PIT Registers 0x40 : Counter 0 0x41 : Counter 1 0x42 : Counter 2 0x43 : Control Register (EPITA) May 14, 2018 32 / 37

PIT Programming divider = Write into control register Write the divider on the counter register internal frequency desired frequency Internal frequency : 1193182 (EPITA) May 14, 2018 33 / 37

PIT Programming unsigned long gettick(void); Counter 0 Mode 2 rate : 100 Hz (EPITA) May 14, 2018 34 / 37

PIT - Possible bug causes Execution context may be corrupted. Hardware interrupts may have been disabled with cli or may not have been enabled with sti The timer interrupt may be masked in the PIC. (EPITA) May 14, 2018 35 / 37

Advices Use X Macro (EPITA) May 14, 2018 36 / 37

Contact #k (irc.rezosup.org) labos.lse with [K] tag k[at]lse.epita.fr bitz[at]lse.epita.fr nathan.gauer[at]lse.epita.fr (EPITA) May 14, 2018 37 / 37