MonkOS  v0.1
A simple 64-bit operating system (x86_64)
interrupt.h File Reference

Interrupt handling operations. More...

#include <core.h>
#include <kernel/x86/cpu.h>

Go to the source code of this file.

Data Structures

struct  interrupt_context_t
 A record describing the CPU state at the time of the interrupt. More...
 

Macros

#define IRQ_TIMER   0
 
#define IRQ_KEYBOARD   1
 
#define TRAP_IRQ_TIMER   0x20
 
#define TRAP_IRQ_KEYBOARD   0x21
 
#define PIC_PORT_CMD_MASTER   0x20
 Command port for master PIC. More...
 
#define PIC_PORT_CMD_SLAVE   0xa0
 Command port for slave PIC. More...
 
#define PIC_PORT_DATA_MASTER   0x21
 Data port for master PIC. More...
 
#define PIC_PORT_DATA_SLAVE   0xa1
 Data port for slave PIC. More...
 
#define PIC_CMD_EOI   0x20
 End of interrupt. More...
 

Typedefs

typedef void(* isr_handler) (const interrupt_context_t *context)
 Interrupt service routine called when an interrupt occurs. More...
 

Functions

void interrupts_init ()
 Initialize all interrupt tables. More...
 
void isr_set (int interrupt, isr_handler handler)
 Set an interrupt service routine for the given interrupt number. More...
 
void irq_enable (uint8_t irq)
 Tell the PIC to enable a hardware interrupt. More...
 
void irq_disable (uint8_t irq)
 Tell the PIC to disable a hardware interrupt. More...
 

Detailed Description

Interrupt handling operations.

Definition in file interrupt.h.


Data Structure Documentation

struct interrupt_context

A record describing the CPU state at the time of the interrupt.

Definition at line 41 of file interrupt.h.

Data Fields
registers_t regs all general-purpose registers.
uint64_t error exception error identifier.
uint64_t interrupt interrupt vector number.
uint64_t retaddr interrupt return address.
uint64_t cs code segment.
uint64_t rflags flags register.
uint64_t rsp stack pointer.
uint64_t ss stack segment.

Macro Definition Documentation

#define IRQ_TIMER   0

Definition at line 20 of file interrupt.h.

Referenced by timer_init().

#define IRQ_KEYBOARD   1

Definition at line 21 of file interrupt.h.

Referenced by kb_init().

#define TRAP_IRQ_TIMER   0x20

Definition at line 24 of file interrupt.h.

Referenced by timer_init().

#define TRAP_IRQ_KEYBOARD   0x21

Definition at line 25 of file interrupt.h.

Referenced by kb_init().

#define PIC_PORT_CMD_MASTER   0x20

Command port for master PIC.

Definition at line 28 of file interrupt.h.

Referenced by isr_keyboard(), and isr_timer().

#define PIC_PORT_CMD_SLAVE   0xa0

Command port for slave PIC.

Definition at line 29 of file interrupt.h.

#define PIC_PORT_DATA_MASTER   0x21

Data port for master PIC.

Definition at line 30 of file interrupt.h.

#define PIC_PORT_DATA_SLAVE   0xa1

Data port for slave PIC.

Definition at line 31 of file interrupt.h.

#define PIC_CMD_EOI   0x20

End of interrupt.

Definition at line 34 of file interrupt.h.

Referenced by isr_keyboard(), and isr_timer().

Typedef Documentation

typedef void(* isr_handler) (const interrupt_context_t *context)

Interrupt service routine called when an interrupt occurs.

Parameters
[in]contextThe CPU state at the time of the interrupt.

Definition at line 74 of file interrupt.h.

Function Documentation

void interrupts_init ( )

Initialize all interrupt tables.

Initialize a table of interrupt service routine thunks, one for each of the 256 possible interrupts. Then set up the interrupt descriptor table (IDT) to point to each of the thunks.

Interrupts should not be enabled until this function has been called.

Referenced by kmain().

void isr_set ( int  interrupt,
isr_handler  handler 
)

Set an interrupt service routine for the given interrupt number.

Interrupts should be disabled while setting these handlers. To disable an ISR, set its handler to null.

Parameters
[in]interruptInterrupt number (0-255).
[in]handlerInterrupt service routine handler function.

Referenced by exceptions_init(), kb_init(), and timer_init().

void irq_enable ( uint8_t  irq)

Tell the PIC to enable a hardware interrupt.

Parameters
[in]irqIRQ number to enable (0-15).

Referenced by kb_init(), timer_enable(), and timer_init().

void irq_disable ( uint8_t  irq)

Tell the PIC to disable a hardware interrupt.

Parameters
[in]irqIRQ number to enable (0-15).

Referenced by timer_disable().