-
Notifications
You must be signed in to change notification settings - Fork 13
Interrupt Descriptors Table #26
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
--- | ||
title: Interrupt descriptor table | ||
tags: x86, x64 | ||
category: Interrupts | ||
description: IDT specification | ||
--- | ||
:source-language: c | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this, since there's no longer any C code. |
||
|
||
== Interrupt Descriptor Table | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No heading for the entire article, that is done automatically. |
||
|
||
// TODO: articles "GDT" and "Interrupts" are not written yet | ||
|
||
Interrupt Descriptor Table is a binary data structure specific to IA-32 (xref:x86[x86]) and x86_64 architectures. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add "the" or "an". |
||
It is used by the CPU to lookup an interrupt service routines (ISR) when an xref:interrupts[interrupt] is issued. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "interrupt service routine" singular |
||
It is protected mode and long mode counterpart to real mode interrupt vector table (IVT). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "the protected mode and long mode counterpart" |
||
|
||
IMPORTANT: IDT requires a working xref:gdt[GDT] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add "an" or "the" |
||
|
||
=== IDTR | ||
IDTR is a register containing the IDT's address and limit. | ||
|
||
[cols="1,3"] | ||
|=== | ||
| Size | ||
| One less than the size of the IDT in bytes | ||
|
||
| Offset | ||
| The linear address of the IDT | ||
|=== | ||
|
||
==== Layout | ||
|
||
[cols="1,1,1"] | ||
|=== | ||
| Architecture | ||
| Size | ||
| Offset | ||
|
||
| IA-32 | ||
| 16 (0 -- 15) | ||
| 31 (16 -- 48) | ||
|
||
| x86_64 | ||
| 16 (0 -- 15) | ||
| 63 (16 -- 79) | ||
|=== | ||
|
||
==== Things to know | ||
* IDT can contain up to 256 (0..255) ISR vectors. Entries above this limit will be ignored. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "the" or "an" |
||
* In contrast to GDT, the first entry of the IDT is valid and used. | ||
|
||
=== IDT entry | ||
|
||
|
||
==== IA-32 | ||
On 32-bit processors, IDT entries are 8-bytes long, therefore to access a particular entry the raw index must be multiplied by 8 and added to the IDTR Offset. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "offset" definitely lower case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Offset is made here upper case on purpose, as it's a field of the IDTR descriptor. |
||
|
||
|
||
===== Gate descriptor | ||
|
||
[cols="2,1,3"] | ||
|=== | ||
| Name | ||
| Position (in bits) | ||
| Description | ||
|
||
| Offset (0 -- 15) | ||
| 0 -- 15 | ||
| ISR entry point address. In trap gates should be set to zero. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In trap gates should be zero? Do you mean task gates? |
||
|
||
| Segment selector | ||
| 16 -- 31 | ||
| GDT segment selector. In trap gates used to specify a TSS selector. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, do you mean task gate, instead of trap gate? |
||
|
||
| Reserved | ||
| 32 -- 39 | ||
| -- | ||
|
||
| Gate Type | ||
| 40 -- 43 | ||
| Type of the gate. See below. | ||
|
||
| 0 | ||
| 44 | ||
| -- | ||
|
||
| DPL | ||
| 45 -- 46 | ||
| Descriptor privilege level. Ignored by hardware interrupts. | ||
|
||
| Present | ||
| 47 | ||
| Indicates whether the entry is valid | ||
|
||
| Offset (16 -- 31) | ||
| 48 -- 63 | ||
| -- | ||
|=== | ||
|
||
|
||
// TODO: x86_64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add x86_64 stuff here |
||
|
||
|
||
=== Gate types | ||
|
||
[cols="1,3"] | ||
|=== | ||
| `0x5` | ||
| Task gate | ||
|
||
| `0x6` | ||
| 16-bit interrupt gate | ||
|
||
| `0x7` | ||
| 16-bit trap gate | ||
|
||
| `0xE` | ||
| 32-bit interrupt gate | ||
|
||
FedorLap2006 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `0xF` | ||
| 32-bit trap gate | ||
|=== | ||
|
||
==== Interrupt Gate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. section headers are sentence case |
||
An interrupt gate is used to indicate an interrupt service routine (ISR). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe there is a better verb than "indicate" |
||
|
||
When an assembly interrupt call is issued, the CPU looks up the ISR by specified index in the IDT, stores necessary registers in the stack and jumps to the entry point. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There probably should be a comma between "stack" and "and". |
||
|
||
IMPORTANT: Usage of 16-bit gates is highly unadvised, as the CPU cannot properly return to 32-bit mode using `iret`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "unadvised" means taking a decision rashly, without advice |
||
|
||
If the CPU was running in 32-bit mode, and the specified selector is a 16-bit gate, it will switch to 16-bit Protected Mode and jump to the entry point. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "protected mode is lower case" |
||
|
||
==== Trap Gate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see previous comment |
||
Trap gate is sometimes used for syscalls and exceptions. It is very similar to interrupt gate, however, in contrast to interrupt gate, it does not set/clear interrupt flag. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "A trap gate", "an interrupt gate". Replace "/" by "or". In addition, specify when it does not set or clear the interrupt flag (i.e. automatically when dispatching the gate). |
||
|
||
==== Task Gate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see previous comment |
||
IMPORTANT: It is highly unadvised to use task gates and hardware task switching as a whole. Hardware task switching is very slow and is removed on x86_64 CPUs. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous comment. |
||
|
||
Task gate is used for hardware task switching and is specific to IA-32. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "A task gate" |
||
|
||
When processing a task gate interrupt, the CPU will perform a hardware task switch to the task specified by *Selector* field. The pointer to the interrupted task will be stored in the Link field of the new TSS. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no boldface for emphasis, only for introduction of important terms |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inconsistent capitalization