UnnamedOS

Programmable Interrupt Controller. More...

+ Collaboration diagram for PIC:

Macros

#define PIC1_CMD   0x20
 the master PIC's command port
 
#define PIC1_DATA   0x21
 the master PIC's data port
 
#define PIC2_CMD   0xA0
 the slave PIC's command port
 
#define PIC2_DATA   0xA1
 the slave PIC's data port
 
#define PIC_EOI   0x20
 "end of interrupt" signals that an IRQ has been handled
 
#define INT_IRQ0   0x20
 where we want to map the master PIC's IRQs
 
#define INT_IRQ8   0x28
 where we want to map the slave PIC's IRQs
 

Functions

void pic_init ()
 Initializes the PIC. More...
 
void pic_send_eoi (uint8_t intr)
 Sends an "end of interrupt" signal. More...
 

Detailed Description

Programmable Interrupt Controller.

The PIC manages IRQs (hardware interrupts). It maps actual IRQs to interrupt vectors. After booting, the IRQs need to be remapped to avoid conflicts.

See also
http://wiki.osdev.org/8259_PIC
http://www.lowlevel.eu/wiki/PIC

Function Documentation

void pic_init ( )

Initializes the PIC.

Before PIC initialization the interrupt vectors look like this:

  • 00-1F: Exceptions
  • 08-0F: IRQ0-7 (PIC1) - conflicts with exceptions!
  • 70-77: IRQ8-15 (PIC2)

We "bend" the mapping "IRQ -> interrupt vector" to prevent those conflicts by re-initializing the master and slave PICs and setting the interrupt vectors 0x20 and 0x28 respectively.

So after initialization we have this:

  • 00-1F: Exceptions
  • 20-27: IRQ0-7 (PIC1) - no more conflicts, all IRQs 0-15 are in a row
  • 28-2F: IRQ8-15 (PIC2)
  • 30-FF: freely usable (syscalls)

Definition at line 25 of file pic.c.

void pic_send_eoi ( uint8_t  intr)

Sends an "end of interrupt" signal.

This tells the master PIC that we're ready to process new interrupts. No new interrupts are fired until an EOI is sent.

Parameters
intrthe interrupt vector that has been handled

For IRQ8-15 (issued by slave), we send an EOI to the slave PIC as well.

Definition at line 61 of file pic.c.

+ Here is the caller graph for this function: