Pengendali Interupsi Terprogram (PIC) dan APIC
Temukan cara permintaan interupsi perangkat keras mencapai CPU melalui PIC 8259 dan APIC modern, termasuk pemetaan ulang IRQ, masking, dan sinyal akhir interupsi.
Pengendali Interupsi Terprogram (PIC) dan APIC adalah pelajaran Assembly Language & x86 Low-Level Systems Programming gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Assembly Language & x86 Low-Level Systems Programming, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Assembly Language & x86 Low-Level Systems Programming mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
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, data0x21 - Slave: command
0xA0, data0xA1
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, alMasking 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 backEnd 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 doneLimitations 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 IRQsQuick 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
Belajar Assembly dengan tutor AI — gratis
Tulis dan jalankan kode asli di browser kamu, dapatkan bantuan instan dari tutor AI 24/7, dan lanjutkan di mana kamu tinggalkan di web atau aplikasi.
- Kursus
- 12
- Pelajaran
- 48
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Pengendali Interupsi Terprogram (PIC) dan APIC” gratis?
Ya — teks lengkap “Pengendali Interupsi Terprogram (PIC) dan APIC” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Assembly Language & x86 Low-Level Systems Programming, upgrade ke CoddyKit PRO. Kursus Assembly Language & x86 Low-Level Systems Programming mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “Pengendali Interupsi Terprogram (PIC) dan APIC”?
Temukan cara permintaan interupsi perangkat keras mencapai CPU melalui PIC 8259 dan APIC modern, termasuk pemetaan ulang IRQ, masking, dan sinyal akhir interupsi. Kamu berlatih Assembly Language & x86 Low-Level Systems Programming dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Assembly Language & x86 Low-Level Systems Programming?
Tidak diperlukan pengalaman sebelumnya. Assembly Language & x86 Low-Level Systems Programming di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.
Berapa lama pelajaran “Pengendali Interupsi Terprogram (PIC) dan APIC” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Assembly Language & x86 Low-Level Systems Programming ini?
Ya. Setiap pelajaran Assembly Language & x86 Low-Level Systems Programming menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Memahami Interupsi dan Trap
- Tabel Deskriptor Interupsi (IDT)
- Penangan Pengecualian Khusus
- Pengendali Interupsi Terprogram (PIC) dan APIC