0Pricing
Assembly Language & x86 Low-Level Systems Programming · Leçon

Le contrôleur d’interruptions programmable (PIC) et APIC

Découvrez comment les demandes d’interruption matérielle atteignent le CPU via le PIC 8259 et l’APIC moderne, notamment le remappage des IRQ, le masquage et la signalisation de fin d’interruption.

Le contrôleur d’interruptions programmable (PIC) et APIC est une leçon Assembly Language & x86 Low-Level Systems Programming gratuite sur CoddyKit. Ceci est la leçon 4 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Assembly Language & x86 Low-Level Systems Programming, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Assembly Language & x86 Low-Level Systems Programming comprend 4 leçons au total.

Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.

Why a Controller Is Needed

The CPU has only a single hardware interrupt pin (INTR), yet a PC has dozens of devices that need attention. A dedicated chip multiplexes these IRQ lines onto that one pin and tells the CPU which device fired.

That chip is the Programmable Interrupt Controller (PIC).

The Legacy 8259 PIC

The classic PC uses two cascaded 8259A chips, giving 15 usable IRQ lines (IRQ0-IRQ15). The master handles IRQ0-7, the slave IRQ8-15 connected through IRQ2.

  • IRQ0 = system timer
  • IRQ1 = keyboard
  • IRQ14/15 = ATA disks

I/O Ports of the PIC

Each PIC is programmed through two I/O ports:

  • Master: command 0x20, data 0x21
  • Slave: command 0xA0, data 0xA1

You send Initialization Command Words (ICWs) and Operation Command Words (OCWs) to these ports.

IRQ Remapping

On boot the PIC maps IRQ0-7 onto interrupt vectors 8-15 — which collide with CPU exceptions like the double fault (vector 8). Kernels remap the PIC, typically to vectors 0x20-0x2F, to avoid this clash.

Remapping in Assembly

Remapping is an ICW sequence: start init, set the new vector offset, define cascade wiring, set 8086 mode.

mov al, 0x11      ; ICW1: begin init, expect ICW4
out 0x20, al      ; master command
out 0xA0, al      ; slave command
mov al, 0x20      ; ICW2: master vector offset 0x20
out 0x21, al
mov al, 0x28      ; ICW2: slave vector offset 0x28
out 0xA1, al

Masking Interrupts

The Interrupt Mask Register (IMR) lets you disable individual IRQ lines. Writing a 1 to a bit masks (ignores) that line; 0 enables it.

in al, 0x21       ; read current master mask
or al, 0x02       ; set bit 1 -> mask IRQ1 (keyboard)
out 0x21, al      ; write it back

End of Interrupt (EOI)

After servicing an IRQ the handler must send an End Of Interrupt command, or the PIC will not deliver further interrupts on that line.

For IRQ8-15 you must EOI both the slave and the master.

mov al, 0x20      ; non-specific EOI
out 0x20, al      ; tell master we are done

Limitations of the PIC

The 8259 design is single-CPU only and supports just 15 lines. It cannot route interrupts to different cores, which makes it useless for SMP systems.

This is why modern hardware moved to the APIC.

The APIC Architecture

The Advanced Programmable Interrupt Controller has two parts:

  • Local APIC — one per CPU core, handles the timer and inter-processor interrupts (IPIs)
  • I/O APIC — routes external device IRQs to any core

Local APIC and IPIs

The Local APIC is memory-mapped (default base 0xFEE00000). It provides a per-core timer and lets one core signal another via an IPI through the Interrupt Command Register — essential for waking up cores during boot.

Disabling the PIC for APIC

To use the APIC you mask all PIC lines by writing 0xFF to both data ports, then enable the Local APIC via the spurious interrupt vector register. Modern OSes prefer the APIC for multicore scaling.

mov al, 0xFF
out 0x21, al      ; mask all master IRQs
out 0xA1, al      ; mask all slave IRQs

Quick Check

Test your understanding of the PIC.

Recap

You learned how device IRQs reach the CPU:

  • The 8259 PIC multiplexes 15 IRQ lines onto one CPU pin
  • IRQs are remapped to vectors 0x20-0x2F to avoid exception clashes
  • The IMR masks lines; an EOI ends each interrupt
  • The APIC replaces the PIC for multicore routing and IPIs

Questions Fréquemment Posées

La leçon « Le contrôleur d’interruptions programmable (PIC) et APIC » est-elle gratuite ?

Oui — le texte complet de « Le contrôleur d’interruptions programmable (PIC) et APIC » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Assembly Language & x86 Low-Level Systems Programming, passe à CoddyKit PRO. Le cours Assembly Language & x86 Low-Level Systems Programming comprend 4 leçons au total.

Qu'est-ce que j'apprendrai dans « Le contrôleur d’interruptions programmable (PIC) et APIC » ?

Découvrez comment les demandes d’interruption matérielle atteignent le CPU via le PIC 8259 et l’APIC moderne, notamment le remappage des IRQ, le masquage et la signalisation de fin d’interruption. Tu pratiques Assembly Language & x86 Low-Level Systems Programming avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.

Dois-je avoir de l'expérience pour commencer Assembly Language & x86 Low-Level Systems Programming ?

Aucune expérience préalable n'est requise. Assembly Language & x86 Low-Level Systems Programming sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 4 sur 4.

Combien de temps prend la leçon « Le contrôleur d’interruptions programmable (PIC) et APIC » ?

La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.

Peux-tu écrire et exécuter du code dans cette leçon Assembly Language & x86 Low-Level Systems Programming ?

Oui. Chaque leçon Assembly Language & x86 Low-Level Systems Programming inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.

Toutes les leçons de ce cours

  1. Comprendre les interruptions et les déroutements
  2. Table des descripteurs d’interruptions (IDT)
  3. Gestionnaires d’exceptions personnalisés
  4. Le contrôleur d’interruptions programmable (PIC) et APIC
← Retour à Assembly Language & x86 Low-Level Systems Programming