Interrupt And Exception Handling On The X86

3y ago
38 Views
2 Downloads
270.39 KB
13 Pages
Last View : 8d ago
Last Download : 3m ago
Upload by : Rosa Marty
Transcription

6.828: Operating System EngineeringInterrupt and ExceptionHandling on the x86( Lecture 8 )

x86 Interrupt Vectors- Every Exception/Interrupt type is assigned a number:- its vector- When an interrupt occurs, the vector determines what code isinvoked to handle the interrupt.- JOS example: vector 14 page fault handlervector 32 clock handler scheduler0236111213141832-255Divide ErrorNon-Maskable InterruptBreakpoint ExceptionInvalid OpcodeSegment Not PresentStack-Segment FaultGeneral Protection FaultPage FaultMachine CheckUser Defined Interrupts

Sources: Hardware InterruptsHardware Interrupt Types:Non-Maskable Interrupt- Never ignoredINTRx86 CPUINTR Maskable- Ignored when IF is 0PIC8259ANMIPIC: Programmable Interrupt Controller (8259A)- Has 16 wires to devices (IRQ0 – IRQ15)- Can be programmed to map IRQ0-15 vector number- Vector number is signaled over INTR line.- In JOS/lab4:vector (IRQ# OFFSET)

Sources: Software-generated InterruptsProgrammed Interrupts- x86 provides INT instruction.- Invokes the interrupt handler for vector N (0-255)- JOS: we use 'INT 0x30' for system callsSoftware Exceptions- Processor detects an error condition while executingan instruction.- Ex: divl %eax, %eax- Divide by zero if EAX 0- Ex: movl %ebx, (%eax)- Page fault or seg violation if EAX is un-mappedvirtual address.- Ex: jmp BAD JMP- General Protection Fault (jmp'd out of CS)

Enabling / Disabling InterruptsMaskable Hardware Interrupts- Clearing the IF flag inhibits processing hardwareinterrupts delivered on the INTR line.- Use the STI (set interrupt enable flag) and CLI (clearinterrupt enable flag) instructions.- IF affected by: interrupt/task gates, POPF, and IRET.Non-Maskable Interrupt- Invoked by NMI line from PIC.- Always Handled immediately.- Handler for interrupt vector 2 invoked.- No other interrupts can execute until NMI is done.

IDT: Interrupt Descriptor TableIDT:- Table of 256 8-byte entries (similar to the GDT).- In JOS: Each specifies a protected entry-point into the kernel.- Located anywhere in memory.IDTR register:- Stores current IDT.lidt instruction:- Loads IDTR with address and sizeof the IDT.- Takes in a linear address.

IDT EntriesSelectorOffsetPDPLD[bit 40]Segment Selector for dest. code segmentOffset to procedure entry pointSegment Present FlagDescriptor Privilege LevelSize of gate: 1 32 bits; 0 16 bits0 interrupt gate; 1 trap gate

JOS: Interrupts and Address Spaces- JOS approach tries to minimize segmentation usage- so ignore segmentation issues with interruptsPriority Level Switch- CPL is low two bits of CS (11 kernel, 00 user)- Loading new CS for handler can change CPL.- JOS interrupt handlers run with kernel CPL.Addressing Switch- No address space switch when handler invoked.- Paging is not changed.- However in: Kernel VA regions now accessibleStack Switch (User » Kernel)- stack switched to a kernel stack before handler is invoked.

TSS: Task State Segment- Specialized Segment for hardwaresupported multi-tasking(we don't use this x86 feature)- TSS Resides in memory- TSS descriptor goes into GDT(size and linear address of the TSS)- ltr(GD TSS) loads descriptor- In JOS's TSS:- SS0:ESP0 kernel stack usedby interrupt handlers.- All other TSS fields ignored

Exception Entry MechanismKernel»Kernel(New State)SSunchangedESP(new frame pushed)CS:EIP (from IDT)User»Kernel(New State)SS:ESP TSS ss0:esp0CS:EIP (from IDT)EFLAGS:interrupt gates: clear IF

JOS Trap Frame(inc/trap.h)struct Trapframe {.u inttf trapno;/* below here defined by x86 hardware */u inttf err;u inttf eip;u shorttf cs;u int :0;u inttf eflags;/* below only when crossing rings(e.g. user to kernel) */u inttf esp;u shorttf ss;u int :0;};

Exception Return Mechanismiret: interrupt return instruction(top of stack should point to old EIP)Where do we return?- Hardware Interruptsold CS:EIP points past last completed instruction.- Traps(INT 30, . )old CS:EIP points past instruction causing exception- Faults(page fault, GPF, . )old CS:EIP points to instruction causing exception- Aborts(hardware errors, bad system table vals.)uncertain CS:EIP, serious problems, CPU confused

Example: Page Fault ExceptionsWhy?x86 Page Translation Mechanism encountered an errortranslating a linear address into a physical address.Error Codespecial error code format:CR2 registerLinear Address thatgenerated the exception.Saved CS:EIPPoint to the instruction that generated the exception

14 Page Fault 18 Machine Check 32-255 User Defined Interrupts - Every Exception/Interrupt type is assigned a number: -its vector - When an interrupt occurs, the vector determines what code is invoked to handle the interrupt. - JOS example: vector 14 page fault handler vector 32 clock handler scheduler

Related Documents:

Interrupt Model When an interrupt event occurs: Processor does an automatic procedure call CALL automatically done to address for that interrupt Push current PC, Jump to interrupt address Each event has its own interrupt address The global interrupt enable bit (in SREG) is

SiFive Interrupt Cookbook 1.1 Introduction Embedded systems rely heavily on handling interrupts which are asynchronous events designed to be managed by the CPU. SiFive core designs include options for a simple timer and software interrupt generator, a fully featured local interrupt controller, and optionally, a global interrupt controller.

A. Empirical studies on exception handling practices Prior research studied exception handling based on source code and issue trackers. Cabral and Marques [14] studied exception handling practices from 32 projects in both Java and.Net without considering the flow of exceptions. Prior work by Jo et al. [15] focuses on uncaught exceptions of .

Interrupt Service Routine (Handler) ! Interrupt cause the ISR to be executed when – the interrupt is armed (interrupt specific arm bit is set – P1IE) – interrupts in general are enabled (GIE is set in SR) – and the interrupt signal is asserted (either internally or externally) For each typ

Later, we’ll study steps for interrupt programming in C, via 2 examples. 9.1.1 USART RXD Complete interrupt 9.1.2 External interrupts 1. Include header file avr\interrupt.h . 2. Use C macro ISR() to declare the interrupt handler and update IVT. 3. Enable the specific interrupt. 4. Configure details abo

To acknowledge an interrupt the Interrupt Flag corresponding to the event should be cleared (through the IFC register) in the ISR. The OR function between the interrupt flags ensures that the IRQ . CC0 - Compare Match/Input Capture on Channel 0 CC1 - Compare Match/Input Capture on Channel 1 CC2 - Compare Match/Input Capture on .

When trap flag is set, program can be run in single step mode. 2. Interrupt Flag (IF): a. It is an interrupt enable/disable flag. b. If it is set, the maskable interrupt of 8086 is enabled and if it is reset, the interrupt is disabled. c. It can be set by executing instruction sit and can be

In adult social care, we look after vulnerable people. That makes it vital to pay close attention to health and safety. To help us do this, Induction Standard 3 sets out what care workers must know about health and safety at work. This includes: your own and others’ healt h and safety responsibilities safe moving and positioning