Operating system/Traps and Interrupts

This is a lesson in in the course, Operating system, which is a part of The School of Computer Science

Overview
In OS development, interrupts are signals that suspends operation the computer is executing and jumps to an interrupt handler, or also known as an Interrupt Service Routine. The interrupt handler executes some code and finally does an interrupt return, which gives back control to whatever code was executing before the interrupt was triggered the interrupt.

Interrupt Vector Table
The interrupt vector table, or IVT for short, contains 256 possible interrupts in real mode. The position of the IVT is located at position 0000h:0000h. Each interrupt entry is the size of a dword (four bytes). The first word (two bytes) in the entry contains the address of the interrupt handler. The second word (two bytes) contains the segment of the interrupt handler. Since you can only have a maximum of a 20-bit address in real mode, interrupt handlers must remain within conventional memory (the first 640 kibibytes).

An easy way to setup up your own IVT is to:


 * 1) Boot into real mode. This is the default boot mode on all x86 computers.
 * 2) Null out a segment register.
 * 3) Set the index register (BX) to the value of the interrupt multiplied by four. (For example, lets create a MS-DOS interrupt handler. We would set our register with 21h * 4 = 84h).
 * 4) Now your segment register and index register points to your interrupt's entry, in this case int 21h. You can put your interrupt handler's address here.
 * 5) Next, simply increase the index register by 2.
 * 6) Now you can put the interrupt handler's segment of the  into the interrupt's entry.
 * 7) congratulations, you now have a working int 21h.

Assignments



 * Previous Lesson
 * Next Lesson
 * Course Home Page