8259 Programmable Interrupt Controller (PIC)

대문 / 프로그래밍 / 8259 Programmable Interrupt Controller (PIC)

8259 Programmable Interrupt Controller (PIC)

1.1. 요약

8259 PIC를 제어하기 위해서는 일련의 PIC용 PORT 명령어셋인 ICW1, ICW2, ICW3, ICW4를 알아야 합니다.

PIC초기화 과정에서 ICW1 -> ICW2 -> ICW3 -> ICW4 순서대로 초기화 과정을 거칩니다. 중요한것은 그것이고 그것이 어떻게 이루어지는가를 알면 되겠지요.

ICW1 은 PIC를 초기화 하는 명령입니다. 엣지트리거, 레벨트리거를 이명령으로 결정합니다.

ICW2 는 PIC로부터 받은 IRQ번호를 지정한 offset만큼 더해서 매핑하도록 합니다. 이것은 예외처리신호와 충돌을 회피하는 방법을 위해서 꼭 필요합니다. 보통은 20H로 지정합니다.

ICW3 은 Master/Slave PIC의 연결 방법을 명시합니다. 이때 Master는 각 비트가 IRQ 핀번호와 일치하지만 Slave의 경우는 그냥 숫자로 가르키는것을 알아둘 필요가 있습니다.

ICW4의 경우는 ICW1의 0번 bit를 1로 설정할때만 사용합니다. 이것은 8086모드를 사용하도록 지정할때 사용합니다. PC는 8086모드이겠지요.

1.2. 세부사양

아래의 문서는 HelpPC v2.10 에 있는 PIC제어에 대한 자세한 내용이 있어 발췌해봤습니다.
                 8259  Programmable Interrupt Controller  (PIC)

        Initialization Command Word 1 at Port 20h and A0h

        │7│6│5│4│3│2│1│0│  ICW1
         │ │ │ │ │ │ │ └──── 1=ICW4 is needed, 0=no ICW4 needed
         │ │ │ │ │ │ └───── 1=single 8259, 0=cascading 8259's
         │ │ │ │ │ └────── 1=4 byte interrupt vectors, 0=8 byte int vectors
         │ │ │ │ └─────── 1=level triggered mode, 0=edge triggered mode
         │ │ │ └──────── must be 1 for ICW1 (port must also be 20h or A0h)
         └─┴─┴───────── must be zero for PC systems

        Initialization Command Word 2 at Port 21h and A1h

        │7│6│5│4│3│2│1│0│  ICW2
         │ │ │ │ │ └─┴─┴──── 000= on 80x86 systems
         └─┴─┴─┴─┴───────── A7-A3 of 80x86 interrupt vector

        Initialization Command Word 3 at Port 21h and A1h

        │7│6│5│4│3│2│1│0│  ICW3 for Master Device
         │ │ │ │ │ │ │ └──── 1=interrupt request 0 has slave, 0=no slave
         │ │ │ │ │ │ └───── 1=interrupt request 1 has slave, 0=no slave
         │ │ │ │ │ └────── 1=interrupt request 2 has slave, 0=no slave
         │ │ │ │ └─────── 1=interrupt request 3 has slave, 0=no slave
         │ │ │ └──────── 1=interrupt request 4 has slave, 0=no slave
         │ │ └───────── 1=interrupt request 5 has slave, 0=no slave
         │ └────────── 1=interrupt request 6 has slave, 0=no slave
         └─────────── 1=interrupt request 7 has slave, 0=no slave

        │7│6│5│4│3│2│1│0│  ICW3 for Slave Device
         │ │ │ │ │ └─┴─┴──── master interrupt request slave is attached to
         └─┴─┴─┴─┴───────── must be zero

        Initialization Command Word 4 at Port 21h and A1h

        │7│6│5│4│3│2│1│0│  ICW4
         │ │ │ │ │ │ │ └──── 1 for 80x86 mode, 0 = MCS 80/85 mode
         │ │ │ │ │ │ └───── 1 = auto EOI, 0=normal EOI
         │ │ │ │ └─┴────── slave/master buffered mode (see below)
         │ │ │ └───────── 1 = special fully nested mode (SFNM), 0=sequential
         └─┴─┴────────── unused (set to zero)

        Bits

         32     Buffering Mode
         00     not buffered
         01     not buffered
         10     buffered mode slave (PC mode)
         11     buffered mode master (PC mode)

        Operation Control Word 1 / Interrupt Mask Reg.  (Ports 21h & A1h)

        │7│6│5│4│3│2│1│0│  OCW1 - IMR Interrupt Mask Register
         │ │ │ │ │ │ │ └──── 0 = service IRQ0, 1 = mask off
         │ │ │ │ │ │ └───── 0 = service IRQ1, 1 = mask off
         │ │ │ │ │ └────── 0 = service IRQ2, 1 = mask off
         │ │ │ │ └─────── 0 = service IRQ3, 1 = mask off
         │ │ │ └──────── 0 = service IRQ4, 1 = mask off
         │ │ └───────── 0 = service IRQ5, 1 = mask off
         │ └────────── 0 = service IRQ6, 1 = mask off
         └─────────── 0 = service IRQ7, 1 = mask off

        Operation Control Word 2 / Interrupt Command Reg. (Ports 20h & A0h)

        │7│6│5│4│3│2│1│0│  OCW2 - ICR Interrupt Command Register
         │ │ │ │ │ └─┴─┴──── interrupt request level to act upon
         │ │ │ │ └───────── must be 0 for OCW2
         │ │ │ └────────── must be 0 for OCW2
         └─┴─┴─────────── EOI type (see table)

        Bits
        765  EOI - End Of Interrupt code (PC specific)
        001  non-specific EOI command
        010  NOP
        011  specific EOI command
        100  rotate in automatic EOI mode
        101  rotate on non-specific EOI command
        110  set priority command  (uses bits 2-0)
        111  rotate on specific EOI command

        Operation Control Word 3   (Ports 20h & A0h)

        │7│6│5│4│3│2│1│0│  OCW3
         │ │ │ │ │ │ │ └─── 1=read IRR on next read, 0=read ISR on next read
         │ │ │ │ │ │ └──── 1=act on value of bit 0, 0=no action if bit 0 set
         │ │ │ │ │ └───── 1=poll command issued, 0=no poll command issued
         │ │ │ │ └────── must be 1 for OCW3
         │ │ │ └─────── must be 0 for OCW3
         │ │ └──────── 1=set special mask, 0=reset special mask
         │ └───────── 1=act on value of bit 5, 0=no action if bit 5 set
         └────────── not used (zero)

        Other Registers

        IRR - Interrupt Request Register, maintains a bit vector indicating
              which IRQ hardware events are awaiting service.   Highest
              level interrupt is reset when the CPU acknowledges interrupt.
        ISR - In Service Register, tracks IRQ line currently being serviced.
              Updated by EOI command.


                     Hardware Interrupt Sequence of Events:

        1. 8259 IRQ signal is raised high by hardware setting the
           corresponding IRR bits true.

        2. PIC evaluates the interrupt requests and signals the CPU
           where appropriate.

        3. CPU acknowledges the INT by pulsing INTA (inverted)


        4. INTA signal from CPU is received by the PIC, which then sets the
           highest priority ISR bit, and clears the corresponding IRR bit

        5. CPU sends a second INTA pulse which causes the PIC to send the
           interrupt ID byte onto the bus.  CPU begins interrupt processing.

        6. Interrupts of lower and equal priority are blocked until a
           Non-Specific EOI (20h) is sent to the command port.


                            Initialization Procedure

        Initialization
         1. write ICW1 to port 20h
         2. write ICW2 to port 21h
         3. if ICW1 bit D1=1  do nothing
            if ICW1 bit D1=0  write ICW3 to port 20h
         4. write ICW4 to port 21h
         5. OCW's can follow in any order


                  8259 Programmable Interrupt Controller Notes

        - Operation Command Word (OCW), commands that set the 8259 in
          various interrupt modes.  These can be written to the 8259
          anytime after initialization.
        - The 8259 differentiates between the OCW1, OCW2 and OCW3 by the
          port address and the value of the data bits D4 and D3.  ICW2
          through ICW4 are order related and must follow ICW1.  ICW1 is
          identified by an even port number and data bit D4 set to 1.
        - PCs operate in fully nested mode, where a Non-Specific EOI resets
          the interrupt identified by the highest bit value in the ISR
        - 8259s can be chained together where the INT pin (output) of a
          slave 8259 can be used as the input to an IRQ line allowing up
          to 64 priority vectored interrupts.  AT level machines use two
          8259's for a total of 16 hardware interrupt levels
        - the first 8259 ports are located at 20h and 21h
        - the second 8259 ports are located at A0h and A1h
        - PC and AT interrupts are Edge Triggered while PS/2's are Level
          Triggered
        - some ASIC chips designed for Tandy 1000 Systems malfunction if
          specific and non-specific EOIs are mixed
        - for a more in-depth discussion of the 8259, see Intel's "Micro-
          processor and Peripherals Handbook, Volume I"
Retrieved from https://www.minzkn.com:443/moniwiki/wiki.php/8259PIC
last modified 2021-10-21 10:01:04