Modestus Moon OS  R4
CS 450 project
interrupts.c File Reference
#include <system.h>
#include <core/io.h>
#include <core/serial.h>
#include <core/tables.h>
#include <core/interrupts.h>
Include dependency graph for interrupts.c:

Go to the source code of this file.

Macros

#define PIC1   0x20
 
#define PIC2   0xA0
 
#define ICW1   0x11
 
#define ICW4   0x01
 
#define io_wait()   asm volatile ("outb $0x80")
 

Functions

void divide_error ()
 
void debug ()
 
void nmi ()
 
void breakpoint ()
 
void overflow ()
 
void bounds ()
 
void invalid_op ()
 
void device_not_available ()
 
void double_fault ()
 
void coprocessor_segment ()
 
void invalid_tss ()
 
void segment_not_present ()
 
void stack_segment ()
 
void general_protection ()
 
void page_fault ()
 
void reserved ()
 
void coprocessor ()
 
void rtc_isr ()
 
void sys_call_isr ()
 
void isr0 ()
 
void do_isr ()
 
void init_irq (void)
 
void init_pic (void)
 
void do_divide_error ()
 
void do_debug ()
 
void do_nmi ()
 
void do_breakpoint ()
 
void do_overflow ()
 
void do_bounds ()
 
void do_invalid_op ()
 
void do_device_not_available ()
 
void do_double_fault ()
 
void do_coprocessor_segment ()
 
void do_invalid_tss ()
 
void do_segment_not_present ()
 
void do_stack_segment ()
 
void do_general_protection ()
 
void do_page_fault ()
 
void do_reserved ()
 
void do_coprocessor ()
 

Variables

idt_entry idt_entries [256]
 

Macro Definition Documentation

#define ICW1   0x11

Definition at line 20 of file interrupts.c.

Referenced by init_pic().

#define ICW4   0x01

Definition at line 21 of file interrupts.c.

Referenced by init_pic().

#define io_wait ( )    asm volatile ("outb $0x80")

Definition at line 28 of file interrupts.c.

Referenced by init_pic().

#define PIC1   0x20

Definition at line 16 of file interrupts.c.

Referenced by init_pic().

#define PIC2   0xA0

Definition at line 17 of file interrupts.c.

Referenced by init_pic().

Function Documentation

void bounds ( )

Referenced by init_irq().

void breakpoint ( )

Referenced by init_irq().

void coprocessor ( )

Referenced by init_irq().

void coprocessor_segment ( )

Referenced by init_irq().

void debug ( )

Referenced by init_irq().

void device_not_available ( )

Referenced by init_irq().

void divide_error ( )

Referenced by init_irq().

void do_bounds ( )

Definition at line 152 of file interrupts.c.

References kpanic().

153 {
154  kpanic("Bounds error");
155 }
void kpanic(const char *msg)
Definition: system.c:24
void do_breakpoint ( )

Definition at line 144 of file interrupts.c.

References kpanic().

145 {
146  kpanic("Breakpoint");
147 }
void kpanic(const char *msg)
Definition: system.c:24
void do_coprocessor ( )

Definition at line 196 of file interrupts.c.

References kpanic().

197 {
198  kpanic("Coprocessor error");
199 }
void kpanic(const char *msg)
Definition: system.c:24
void do_coprocessor_segment ( )

Definition at line 168 of file interrupts.c.

References kpanic().

169 {
170  kpanic("Coprocessor segment error");
171 }
void kpanic(const char *msg)
Definition: system.c:24
void do_debug ( )

Definition at line 136 of file interrupts.c.

References kpanic().

137 {
138  kpanic("Debug");
139 }
void kpanic(const char *msg)
Definition: system.c:24
void do_device_not_available ( )

Definition at line 160 of file interrupts.c.

References kpanic().

161 {
162  kpanic("Device not available");
163 }
void kpanic(const char *msg)
Definition: system.c:24
void do_divide_error ( )

Definition at line 132 of file interrupts.c.

References kpanic().

133 {
134  kpanic("Division-by-zero");
135 }
void kpanic(const char *msg)
Definition: system.c:24
void do_double_fault ( )

Definition at line 164 of file interrupts.c.

References kpanic().

165 {
166  kpanic("Double fault");
167 }
void kpanic(const char *msg)
Definition: system.c:24
void do_general_protection ( )

Definition at line 184 of file interrupts.c.

References kpanic().

185 {
186  kpanic("General protection fault");
187 }
void kpanic(const char *msg)
Definition: system.c:24
void do_invalid_op ( )

Definition at line 156 of file interrupts.c.

References kpanic().

157 {
158  kpanic("Invalid operation");
159 }
void kpanic(const char *msg)
Definition: system.c:24
void do_invalid_tss ( )

Definition at line 172 of file interrupts.c.

References kpanic().

173 {
174  kpanic("Invalid TSS");
175 }
void kpanic(const char *msg)
Definition: system.c:24
void do_isr ( )

Definition at line 55 of file interrupts.c.

References COM2, inb, outb, serial_print(), and serial_println().

56 {
57  char in = inb(COM2);
58  serial_print(&in);
59  serial_println("here");
60  outb(0x20,0x20); //EOI
61 }
#define COM2
Definition: serial.h:7
int serial_print(const char *msg)
Definition: serial.c:59
int serial_println(const char *msg)
Definition: serial.c:44
#define inb(port)
Definition: io.h:15
#define outb(port, data)
Definition: io.h:8
void do_nmi ( )

Definition at line 140 of file interrupts.c.

References kpanic().

141 {
142  kpanic("NMI");
143 }
void kpanic(const char *msg)
Definition: system.c:24
void do_overflow ( )

Definition at line 148 of file interrupts.c.

References kpanic().

149 {
150  kpanic("Overflow error");
151 }
void kpanic(const char *msg)
Definition: system.c:24
void do_page_fault ( )

Definition at line 188 of file interrupts.c.

References kpanic().

189 {
190  kpanic("Page Fault");
191 }
void kpanic(const char *msg)
Definition: system.c:24
void do_reserved ( )

Definition at line 192 of file interrupts.c.

References serial_println().

193 {
194  serial_println("die: reserved");
195 }
int serial_println(const char *msg)
Definition: serial.c:44
void do_segment_not_present ( )

Definition at line 176 of file interrupts.c.

References kpanic().

177 {
178  kpanic("Segment not present");
179 }
void kpanic(const char *msg)
Definition: system.c:24
void do_stack_segment ( )

Definition at line 180 of file interrupts.c.

References kpanic().

181 {
182  kpanic("Stack segment error");
183 }
void kpanic(const char *msg)
Definition: system.c:24
void double_fault ( )

Referenced by init_irq().

void general_protection ( )

Referenced by init_irq().

void init_irq ( void  )

Definition at line 68 of file interrupts.c.

References bounds(), breakpoint(), coprocessor(), coprocessor_segment(), debug(), device_not_available(), divide_error(), double_fault(), general_protection(), idt_set_gate(), invalid_op(), invalid_tss(), nmi(), overflow(), page_fault(), reserved(), rtc_isr(), segment_not_present(), stack_segment(), and sys_call_isr().

Referenced by kmain().

69 {
70  int i;
71 
72  // Necessary interrupt handlers for protected mode
73  u32int isrs[17] = {
75  (u32int)debug,
76  (u32int)nmi,
79  (u32int)bounds,
91  };
92 
93  // Install handlers; 0x08=sel, 0x8e=flags
94  for(i=0; i<32; i++){
95  if (i<17) idt_set_gate(i, isrs[i], 0x08, 0x8e);
96  else idt_set_gate(i, (u32int)reserved, 0x08, 0x8e);
97  }
98  // Ignore interrupts from the real time clock
99  idt_set_gate(0x08, (u32int)rtc_isr, 0x08, 0x8e);
100  idt_set_gate(60, (u32int)sys_call_isr, 0x08, 0x8e);
101 }
void divide_error()
void invalid_op()
void breakpoint()
void sys_call_isr()
void overflow()
void page_fault()
void stack_segment()
void general_protection()
void double_fault()
void segment_not_present()
void idt_set_gate(u8int idx, u32int base, u16int sel, u8int flags)
Definition: tables.c:27
void debug()
void coprocessor()
void bounds()
unsigned long u32int
Definition: system.h:27
void invalid_tss()
void rtc_isr()
void nmi()
void device_not_available()
void coprocessor_segment()
void reserved()
void init_pic ( void  )

Definition at line 109 of file interrupts.c.

References ICW1, ICW4, io_wait, outb, PIC1, and PIC2.

Referenced by kmain().

110 {
111  outb(PIC1,ICW1); //send initialization code words 1 to PIC1
112  io_wait();
113  outb(PIC2,ICW1); //send icw1 to PIC2
114  io_wait();
115  outb(PIC1+1,0x20); //icw2: remap irq0 to 32
116  io_wait();
117  outb(PIC2+1,0x28); //icw2: remap irq8 to 40
118  io_wait();
119  outb(PIC1+1,4); //icw3
120  io_wait();
121  outb(PIC2+1,2); //icw3
122  io_wait();
123  outb(PIC1+1,ICW4); //icw4: 80x86, automatic handling
124  io_wait();
125  outb(PIC2+1,ICW4); //icw4: 80x86, automatic handling
126  io_wait();
127  outb(PIC1+1,0xFF); //disable irqs for PIC1
128  io_wait();
129  outb(PIC2+1,0xFF); //disable irqs for PIC2
130 }
#define PIC1
Definition: interrupts.c:16
#define PIC2
Definition: interrupts.c:17
#define ICW1
Definition: interrupts.c:20
#define ICW4
Definition: interrupts.c:21
#define io_wait()
Definition: interrupts.c:28
#define outb(port, data)
Definition: io.h:8
void invalid_op ( )

Referenced by init_irq().

void invalid_tss ( )

Referenced by init_irq().

void isr0 ( )
void nmi ( )

Referenced by init_irq().

void overflow ( )

Referenced by init_irq().

void page_fault ( )

Referenced by init_irq().

void reserved ( )

Referenced by init_irq().

void rtc_isr ( )

Referenced by init_irq().

void segment_not_present ( )

Referenced by init_irq().

void stack_segment ( )

Referenced by init_irq().

void sys_call_isr ( )

Referenced by init_irq().

Variable Documentation

idt_entry idt_entries[256]

Definition at line 17 of file tables.c.

Referenced by idt_set_gate(), and init_idt().