Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.

Interrupt Descriptors Table #26

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions pages/idt.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---
title: Interrupt descriptor table
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsistent capitalization

tags: x86, x64
category: Interrupts
description: IDT specification
---
:source-language: c
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No heading for the entire article, that is done automatically.
Upgrade all section headings by a level.


// 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.
Copy link
Member

Choose a reason for hiding this comment

The 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.
Copy link
Member

Choose a reason for hiding this comment

The 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).
Copy link
Member

Choose a reason for hiding this comment

The 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]
Copy link
Member

Choose a reason for hiding this comment

The 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.
Copy link
Member

Choose a reason for hiding this comment

The 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"offset" definitely lower case
comma between "entry" and "the"

Copy link
Author

Choose a reason for hiding this comment

The 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.
Copy link
Member

Choose a reason for hiding this comment

The 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.
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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

| `0xF`
| 32-bit trap gate
|===

==== Interrupt Gate
Copy link
Member

Choose a reason for hiding this comment

The 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).
Copy link
Member

Choose a reason for hiding this comment

The 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There probably should be a comma between "stack" and "and".
In addition, what is an "assembly interrupt call"? As opposed to a "C interrupt call"?
Also replace "the ISR by specified index in the IDT" by "the ISR specified by the IDT entry corresponding to the interrupt vector"


IMPORTANT: Usage of 16-bit gates is highly unadvised, as the CPU cannot properly return to 32-bit mode using `iret`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"unadvised" means taking a decision rashly, without advice
you probably mean "inadvisable"


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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"protected mode is lower case"
also, this does not take compatibility mode into account


==== Trap Gate
Copy link
Member

Choose a reason for hiding this comment

The 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.
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment.
Also, I think it is better to use "was removed", rather than "is removed", because the act of removing was a decision made in the past.


Task gate is used for hardware task switching and is specific to IA-32.
Copy link
Member

Choose a reason for hiding this comment

The 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no boldface for emphasis, only for introduction of important terms