X hits on this document

10 views

0 shares

0 downloads

0 comments

3 / 6

CPSC 410/611: Operating Systems

Projects: Exceptions + Interrupts

+

Handling Interrupts/Exceptions

g l o b a l _ i s r 0 g l o b a l _ i s r 1 g l o b a l _ i s r 2

; 0: Divide By Zero Exception

_

isr0: cli push byte 0 push byte 0

; push dummy ; push interrupt no

...

jmp isr_common_stub

g l o b a l _ i s r 8

g l o b a l _ i s r 3 0 g l o b a l _ i s r 3 1

; 8: Double Fault Exception (Error Code!) _isr8: cli ; don’t push dummy! push byte 8 j m p i s r _ c o m m o n _ s t u b

/* This defines what the stack looks like when the exception/interrupt reaches the exception dispatcher. */ typedef struct regs { unsigned int gs, fs, es, ds; /* pushed in common stub */ unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax; /* pushed by pusha */

unsigned int int_no, err_code;

/ * p u s h e d i n _ i s r X X * /

unsigned int eip, cs, eflags, useresp, ss; /* pushed by processor */ } REGS;

extern _fault_handler ; The common ISR stub. isr_common_stub: pusha push ds push es push fs push gs mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov eax, esp push eax mov eax, _fault_handler call eax pop eax pop gs pop fs pop es pop ds popa add esp, 8 ; pop code and int no iret

+

High-Level Int/Exc Handler

extern _dispatch_exception ; The common ISR stub. isr_common_stub: pusha push ds push es push fs push gs mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov eax, esp push eax m o v e a x , _ d i s p a t c h _ e x c e p t i call eax pop eax pop gs pop fs pop es pop ds popa add esp, 8 ; pop code and int no iret /* Exception handlers are functions that take a pointer to a REGS structure as input and return void. */ typedef void (* ExceptionHandler)(REGS*); /* List of registered exception handlers. */ o n s t a t i c E x c e p t i o n H a n d l e r h a n d l e r _ t a b l e [ E X C E P T I O N _ T A B L E _ S I Z E ] ; void dispatch_exception(REGS * _r) { unsigned int exc_no = _r->int_no; /* get exception no */ ExceptionHandler handler = handler_table[exc_no]; if (handler) /* Is a handle registered? */ handler(_r); /* If so, fire it up! */ }

3

Document info
Document views10
Page views10
Page last viewedFri Oct 28 20:43:11 UTC 2016
Pages6
Paragraphs138
Words1665

Comments