pintOS를 공부하면서 Interrupt에 대해 작성해봤다.
DPL: Descriptor Privilege Level (2bit)
인텔에서는 주로 Ring 0, Ring 3 두 가지를 사용한다.
중심에 가까워질 수록 권한이 강해진다.
-> 시스템 콜을 호출할 때 Ring 0에 진입한다 라고 생각하면 편함.
inter_entry
가 수행되면 현재 레지스터 상태를 실행중인 스레드의 스택에 저장하고 interrupt_handler
를 호출한다.
interrupt_handler가 수행완료되면 레지스터 상태를 돌려놓고, iretq
를 호출한다.
threads/loader.h
.section .text
.func intr_entry
intr_entry:
/* Save caller's registers. */
subq $16,%rsp
movw %ds,8(%rsp)
movw %es,0(%rsp)
subq $120,%rsp
movq %rax,112(%rsp)
movq %rbx,104(%rsp)
movq %rcx,96(%rsp)
movq %rdx,88(%rsp)
movq %rbp,80(%rsp)
movq %rdi,72(%rsp)
movq %rsi,64(%rsp)
movq %r8,56(%rsp)
movq %r9,48(%rsp)
movq %r10,40(%rsp)
movq %r11,32(%rsp)
movq %r12,24(%rsp)
movq %r13,16(%rsp)
movq %r14,8(%rsp)
movq %r15,0(%rsp)
cld /* String instructions go upward. */
movq $SEL_KDSEG, %rax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movw %ax, %fs
movw %ax, %gs
movq %rsp,%rdi
call intr_handler
movq 0(%rsp), %r15
movq 8(%rsp), %r14
movq 16(%rsp), %r13
movq 24(%rsp), %r12
movq 32(%rsp), %r11
movq 40(%rsp), %r10
movq 48(%rsp), %r9
movq 56(%rsp), %r8
movq 64(%rsp), %rsi
movq 72(%rsp), %rdi
movq 80(%rsp), %rbp
movq 88(%rsp), %rdx
movq 96(%rsp), %rcx
movq 104(%rsp), %rbx
movq 112(%rsp), %rax
addq $120, %rsp
movw 8(%rsp), %ds
movw (%rsp), %es
addq $32, %rsp
iretq
.endfunc
https://modoocode.com/en/inst/sti
인터럽트 플래그가 set되어 있다 -> 외부 인터럽트가 발생했을 때 루틴을 처리할 수 있다.
The IF flag and the STI and CLI instructions do not prohibit the generation of exceptions and NMI interrupts. NMI interrupts (and SMIs) may be blocked for one macroinstruction following an STI.
https://en.wikipedia.org/wiki/Non-maskable_interrupt
주로 응답속도가 중요하거나, interrupt가 비활성화 되지 않아야 할때 사용된다.
최근에는 즉시 집중해야하는 (immediate attention) non-recoverable error를 다룰때 사용된다.
timer: 32 (0x20)
keyboard: 33 (0x21)
serial: 36 (0x24)
disk:
43 : read
44: write
channel 0: 46 -> interrupt_handler 호출
channel 1: 47 -> interrupt_handler 호출
IRQ: Interrupt Request Interrupt request - Wikipedia
IVT: Interrupt Vector Table Interrupt vector table - Wikipedia
IDT: Interrupt Descriptor Table Interrupt descriptor table - Wikipedia
DPL: Descriptor Privilege Level