AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
pic.c File Reference

x86: the PC's two 8259 programmable interrupt controllers (PICs). More...

#include <core/system.h>
#include <core/panic.h>
#include <core/arch.h>
#include <platform/misc.h>
#include <sys/sched.h>
#include <sys/signal.h>
#include <cpu/cpu.h>

Go to the source code of this file.

Macros

#define PIC_CMD   0x00
#define PIC_DATA   0x01
#define ICW1   0x11
#define ICW2_MASTER   0x20
#define ICW2_SLAVE   0x28
#define ICW3_MASTER   0x04
#define ICW3_SLAVE   0x02
#define ICW4   0x01
#define IRQ_ACK   0x20

Functions

static void x86_irq_mask (int irq)
 Masks an IRQ at its 8259.
static void x86_irq_unmask (int irq)
 Unmasks an IRQ at its 8259 (for the slave's, the master's IRQ 2 too).
static void x86_irq_remap (void)
 Initializes the 8259s, with their IRQs at vectors 32 to 47, so that they don't collide with the CPU's exceptions.
static void pic_chip_eoi (unsigned irq)
 Tells the 8259s that an interrupt is handled: the slave too for its own IRQs.
static void pic_chip_mask (unsigned irq)
 Masks an IRQ, for irq.c.
static void pic_chip_unmask (unsigned irq)
 Unmasks an IRQ, for irq.c.
static const char * pic_chip_describe (unsigned irq)
 Describes an IRQ's route, for /proc/interrupts.
static int x86_pic_probe (void)
 Checks that there is an 8259 at the master's ports: it must keep the mask that was written.
void x86_pic_disable (void)
 Masks every IRQ of the 8259s, when the APIC brings the interrupts.
int x86_pic_setup (struct ioaddr *_master, struct ioaddr *_slave)
 Sets up the 8259s, with every IRQ masked.

Variables

static struct ioaddr master
static struct ioaddr slave
static uint16_t pic_mask = 0xFFFF
struct x86_irq_chip x86_pic_chip

Detailed Description

x86: the PC's two 8259 programmable interrupt controllers (PICs).

The 8259s bring the interrupts when there's no APIC (or with apic=off), as an x86_irq_chip (irq.c). With the APIC, they are still set up (their IRQs remapped to vectors 32 to 47, past the exceptions), then masked, and they stay masked.

Definition in file pic.c.

Macro Definition Documentation

◆ ICW1

#define ICW1   0x11

Definition at line 37 of file pic.c.

Referenced by x86_irq_remap().

◆ ICW2_MASTER

#define ICW2_MASTER   0x20

Definition at line 38 of file pic.c.

Referenced by x86_irq_remap().

◆ ICW2_SLAVE

#define ICW2_SLAVE   0x28

Definition at line 39 of file pic.c.

Referenced by x86_irq_remap().

◆ ICW3_MASTER

#define ICW3_MASTER   0x04

Definition at line 40 of file pic.c.

Referenced by x86_irq_remap().

◆ ICW3_SLAVE

#define ICW3_SLAVE   0x02

Definition at line 41 of file pic.c.

Referenced by x86_irq_remap().

◆ ICW4

#define ICW4   0x01

Definition at line 42 of file pic.c.

Referenced by x86_irq_remap().

◆ IRQ_ACK

#define IRQ_ACK   0x20

Definition at line 91 of file pic.c.

Referenced by pic_chip_eoi().

◆ PIC_CMD

#define PIC_CMD   0x00

Definition at line 19 of file pic.c.

Referenced by pic_chip_eoi(), and x86_irq_remap().

◆ PIC_DATA

#define PIC_DATA   0x01

Definition at line 20 of file pic.c.

Referenced by x86_irq_mask(), x86_irq_remap(), x86_irq_unmask(), x86_pic_disable(), and x86_pic_probe().

Function Documentation

◆ pic_chip_describe()

const char * pic_chip_describe ( unsigned irq)
static

Describes an IRQ's route, for /proc/interrupts.

Definition at line 121 of file pic.c.

References pic_chip_describe().

Referenced by pic_chip_describe().

◆ pic_chip_eoi()

void pic_chip_eoi ( unsigned irq)
static

Tells the 8259s that an interrupt is handled: the slave too for its own IRQs.

Definition at line 95 of file pic.c.

References io_out8(), IRQ_ACK, master, pic_chip_eoi(), PIC_CMD, and slave.

Referenced by pic_chip_eoi().

◆ pic_chip_mask()

void pic_chip_mask ( unsigned irq)
static

Masks an IRQ, for irq.c.

Definition at line 107 of file pic.c.

References pic_chip_mask(), and x86_irq_mask().

Referenced by pic_chip_mask().

◆ pic_chip_unmask()

void pic_chip_unmask ( unsigned irq)
static

Unmasks an IRQ, for irq.c.

Definition at line 114 of file pic.c.

References pic_chip_unmask(), and x86_irq_unmask().

Referenced by pic_chip_unmask().

◆ x86_irq_mask()

void x86_irq_mask ( int irq)
static

Masks an IRQ at its 8259.

Definition at line 48 of file pic.c.

References io_out8(), master, panic, PIC_DATA, pic_mask, slave, and x86_irq_mask().

Referenced by pic_chip_mask(), and x86_irq_mask().

◆ x86_irq_remap()

void x86_irq_remap ( void )
static

Initializes the 8259s, with their IRQs at vectors 32 to 47, so that they don't collide with the CPU's exceptions.

Definition at line 79 of file pic.c.

References ICW1, ICW2_MASTER, ICW2_SLAVE, ICW3_MASTER, ICW3_SLAVE, ICW4, io_out8(), master, PIC_CMD, PIC_DATA, slave, and x86_irq_remap().

Referenced by x86_irq_remap(), and x86_pic_setup().

◆ x86_irq_unmask()

void x86_irq_unmask ( int irq)
static

Unmasks an IRQ at its 8259 (for the slave's, the master's IRQ 2 too).

Definition at line 62 of file pic.c.

References io_out8(), master, panic, PIC_DATA, pic_mask, slave, and x86_irq_unmask().

Referenced by pic_chip_unmask(), and x86_irq_unmask().

◆ x86_pic_disable()

void x86_pic_disable ( void )

Masks every IRQ of the 8259s, when the APIC brings the interrupts.

Definition at line 152 of file pic.c.

References io_out8(), master, PIC_DATA, slave, and x86_pic_disable().

Referenced by x86_apic_setup(), x86_pic_disable(), and x86_pic_setup().

◆ x86_pic_probe()

int x86_pic_probe ( void )
static

Checks that there is an 8259 at the master's ports: it must keep the mask that was written.

Returns 0, or -ENODEV.

Definition at line 136 of file pic.c.

References io_in8(), io_out8(), master, PIC_DATA, slave, and x86_pic_probe().

Referenced by x86_pic_probe(), and x86_pic_setup().

◆ x86_pic_setup()

int x86_pic_setup ( struct ioaddr * _master,
struct ioaddr * _slave )

Sets up the 8259s, with every IRQ masked.

Parameters
_masterthe master's ports (0x20)
_slavethe slave's ports (0xA0)
Returns
0, or -ENODEV if there's no 8259

Definition at line 165 of file pic.c.

References ioaddr::addr, ioaddr_type_str(), master, printk(), slave, x86_irq_remap(), x86_pic_disable(), x86_pic_probe(), and x86_pic_setup().

Referenced by x86_pc_pic_init(), and x86_pic_setup().

Variable Documentation

◆ master

struct ioaddr master
static

◆ pic_mask

uint16_t pic_mask = 0xFFFF
static

Definition at line 45 of file pic.c.

Referenced by x86_irq_mask(), and x86_irq_unmask().

◆ slave

struct ioaddr slave
static

◆ x86_pic_chip

struct x86_irq_chip x86_pic_chip
Initial value:
= {
.name = "8259",
.mask = pic_chip_mask,
.unmask = pic_chip_unmask,
.eoi = pic_chip_eoi,
.describe = pic_chip_describe,
}
static void pic_chip_eoi(unsigned irq)
Tells the 8259s that an interrupt is handled: the slave too for its own IRQs.
Definition pic.c:95
static void pic_chip_unmask(unsigned irq)
Unmasks an IRQ, for irq.c.
Definition pic.c:114
static void pic_chip_mask(unsigned irq)
Masks an IRQ, for irq.c.
Definition pic.c:107
static const char * pic_chip_describe(unsigned irq)
Describes an IRQ's route, for /proc/interrupts.
Definition pic.c:121

Definition at line 126 of file pic.c.

Referenced by x86_pc_irq_init().