-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrap.c
67 lines (61 loc) · 1.19 KB
/
trap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "defs.h"
#include "trap.h"
#include "x86.h"
#include "timer.h"
extern struct proc *cp;
void trap(struct trapframe *tf)
{
if(tf->trapno != 32)
//kprintf("Trapno: %d", tf->trapno);
if(tf->trapno == T_SYSCALL){
//kprintf("trap: SYSCALL: %d\n", tf->eax);
cp->tf = tf;
syscall();
return;
}
switch(tf->trapno){
case T_IRQ0 + IRQ_TIMER:
timer_callback();
EOI(tf->trapno);
break;
case T_PGFLT:
page_fault(tf->err);
EOI();
break;
case T_IRQ0 + IRQ_7:
spurious(tf->trapno);
break;
case T_IRQ0 + IRQ_KBD:
//spurious(tf->trapno);
consoleint();
EOI(tf->trapno);
return;
default:
kprintf("Unhandled trapno: %d.\n", tf->trapno);
kprintf("Errno: %d", tf->err);
PANIC("TRAP");
}
// this calls scheduler on timer interrupt
if(cp->state == RUNNING && tf->trapno == T_IRQ0 + IRQ_TIMER)
yield();
}
void spurious(uint32_t trapno)
{
outb(0x20, 0x0B);
unsigned char irr = inb(0x20);
if ( irr & 0x80 ) {
EOI(trapno);
}
}
void EOI(uint32_t trapno)
{
// IRQ involving slave (meaning IRQ8 - 15), send EOI to slave
if (trapno <= 47 && trapno >= 40){
outb(0xA0, 0x20);
}
// Any IRQ, send EOI to master
if (1){//trapno >= 32){
if(trapno !=32)
outb(0x20, 0x20);
}
}