中斷描述表 (Interrupt Descriptor Table, IDT) 是 用來定義 IA-32 的系統架構。它是Protected mode 對應 Real Mode 的中斷向量表 ,它表列了 中斷服務程式 (Interrupt Service Routines, ISR). 它有點類似,Global Descriptor Table結構.
IDT的Entry稱作 Gates. 包含了Interrupt Gates, Task Gates, Trap Gates.
位置與大小
IDT位於在CPU的IDTR暫存器,它可以經由LIDT, SIDT指令用來讀取和存取。
Name | Bit | Description |
Limit | 0..15 | Defines the length of the IDT in bytes - 1 (minimum value is 100h, a value of 1000h means 200h interrupts). |
Base | 16..47 | This 32 bits are the linear address where the IDT starts (INT 0) |
這相似於GDT, 例外:
- 位於0~400 memory位址. (此位址用於IDT)
- 總共256個中斷(0~255). 所以IDT應該有256個Entries. 每個Entry對應到一個特定的中斷
- 它可以包含 256 更多或更少 entries. 更多的 entries將被忽略。當一個中斷或例外被呼叫,但它的entry不存在,會產生GPF (General Protection Fault), 表示此IDT Entry的號碼是遺失的。
結構:
這表包含 8-byte Gate entries. 每一個Enty有一個複雜的結構。
struct IDTDescr{ uint16_t offset_1; // offset bits 0..15 uint16_t selector; // a code segment selector in GDT or LDT uint8_t zero; // unused, set to 0 uint8_t type_attr; // type and attributes, see below uint16_t offset_2; // offset bits 16..31 };
它的offset 是一個32bit的數值。分別為兩個部分。
select是一個16bit的數值而且指向一個位於GDT的有效的select.
type_attr 定義如下:
select是一個16bit的數值而且指向一個位於GDT的有效的select.
type_attr 定義如下:
7 0+---+---+---+---+---+---+---+---+| P | DPL | S | GateType |+---+---+---+---+---+---+---+---+
Name | Bit | Full Name | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Offset | 48..63 | Offset 16..31 | Higher part of the offset. | ||||||||||||||||||||
P | 47 | Present | Set to 0 for unused interrupts or for Paging. | ||||||||||||||||||||
DPL | 45,46 | Descriptor Privilege Level | Gate call protection. Specifies which privilege Level the calling Descriptor minimum should have. So hardware and CPU interrupts can be protected from beeing called out of userspace. | ||||||||||||||||||||
S | 44 | Storage Segment | Set to 0 for interrupt gates (see below). | ||||||||||||||||||||
Type | 40..43 | Gate Type 0..3 | Possible IDT gate types :
| ||||||||||||||||||||
0 | 32..39 | Unused 0..7 | Have to be 0. | ||||||||||||||||||||
Selector | 16..31 | Selector 0..15 | Selector of the interrupt function (to make sense - the kernel's selector). The selector's descriptor's DPL field has to be 0. | ||||||||||||||||||||
Offset | 0..15 | Offset 0..15 | Lower part of the interrupt function's offset address (also known as pointer). |
64位的SIDT/LIDT怎么使用
回覆刪除