Assembly Language & x86 Low-Level Systems Programming · 강의

프로그래밍 가능 인터럽트 컨트롤러(PIC)와 APIC

8259 PIC와 최신 APIC를 통해 하드웨어 인터럽트 요청이 CPU에 전달되는 방식을 살펴봅니다. IRQ 재매핑, 마스킹, 인터럽트 처리 완료 신호도 다룹니다.

레슨 4/413개 단계

프로그래밍 가능 인터럽트 컨트롤러(PIC)와 APIC은(는) CoddyKit의 무료 Assembly Language & x86 Low-Level Systems Programming 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Assembly Language & x86 Low-Level Systems Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Assembly Language & x86 Low-Level Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

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
무료로 시작

AI 튜터와 함께 Assembly을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
12
레슨
48

자주 묻는 질문

“프로그래밍 가능 인터럽트 컨트롤러(PIC)와 APIC” 강의는 무료인가요?

네 — “프로그래밍 가능 인터럽트 컨트롤러(PIC)와 APIC” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Assembly Language & x86 Low-Level Systems Programming 강의 전체를 잠금 해제할 수 있습니다. Assembly Language & x86 Low-Level Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.

“프로그래밍 가능 인터럽트 컨트롤러(PIC)와 APIC”에서 뭘 배우나요?

8259 PIC와 최신 APIC를 통해 하드웨어 인터럽트 요청이 CPU에 전달되는 방식을 살펴봅니다. IRQ 재매핑, 마스킹, 인터럽트 처리 완료 신호도 다룹니다. 브라우저에서 직접 실행하는 실습 코드로 Assembly Language & x86 Low-Level Systems Programming을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Assembly Language & x86 Low-Level Systems Programming을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Assembly Language & x86 Low-Level Systems Programming은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“프로그래밍 가능 인터럽트 컨트롤러(PIC)와 APIC” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Assembly Language & x86 Low-Level Systems Programming 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Assembly Language & x86 Low-Level Systems Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 인터럽트와 트랩 이해
  2. 인터럽트 설명자 테이블(IDT)
  3. 사용자 정의 예외 처리기
  4. 프로그래밍 가능 인터럽트 컨트롤러(PIC)와 APIC
← Assembly Language & x86 Low-Level Systems Programming(으)로 돌아가기