Interrupt Vector Table Article

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
Post Reply
U238
Posts: 5
Joined: Fri Jan 14, 2011 8:13 pm

Interrupt Vector Table Article

Post by U238 »

Hi,

I noticed that the Interrupt Vector Table page in the wiki lacks a piece of information vital to the reading and modification of the IVT: It does not mention that the memory addresses stored in the interrupt vectors are in reverse.

For example, modifying the interrupt vector of interrupt 0x21 to point to 0x7650:0x7B4F:

According to the article, once the interrupt vector is written, it should look like this:

Code: Select all

0x76 0x50 0x7B 0x4F
A simple, but probably not the most efficient way to do this in x86 (NASM) assembly, would be:

Code: Select all

mov ax, 0x7650
mov es, ax
mov WORD [es:0x0000], 0x7B4F  ; Put the offset of INT 0x00 in the IVT
mov WORD [es:0x0002], ax        ; Put the segment of INT 0x00 in the IVT
But I ran into a problem when doing this, and I discovered that when I invoked my interrupt, the CPU would jump somewhere seemingly arbitrary. After careful debugging and research, I discovered that the memory addresses stored in the interrupt vectors were in reverse.

Therefore, once the interrupt vector is written, it should look like this:

Code: Select all

0x4F 0x7B 0x50 0x76
A simple, but probably not the most efficient way to do this in x86 (NASM) assembly, would be:

Code: Select all

mov ax, 0x7650
mov es, ax

mov ax, 0x7B4F

mov BYTE [es:0x0000], al          ; Put the offset of INT 0x00 in the IVT
mov BYTE [es:0x0001], ah         ; Put the offset of INT 0x00 in the IVT

mov ax, 0x7650

mov BYTE [es:0x0002], al          ; Put the segment of INT 0x00 in the IVT
mov BYTE [es:0x0003], ah         ; Put the segment of INT 0x00 in the IVT
I would be grateful if someone could please add this information to the wiki, as it would save people like me a few hours of (unnecessary) debugging. I didn't attempt to add this information to the wiki myself because I wasn't sure of any standards and if it was even worth adding to the wiki.

Thanks,

-U238
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Interrupt Vector Table Article

Post by Combuster »

You're making a mistake yourself:

Code: Select all

mov ax, 0x7B4F
mov BYTE [es:0x0000], al          ; Put the offset of INT 0x00 in the IVT
mov BYTE [es:0x0001], ah         ; Put the offset of INT 0x00 in the IVT
is exactly equivalent to

Code: Select all

mov WORD [es:0x0000], 0x7B4F  ; Put the offset of INT 0x00 in the IVT
and thus does not make any difference. If you disagree, read up on byteorders.


Perhaps there is something else wrong?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Interrupt Vector Table Article

Post by qw »

U238 wrote:But I ran into a problem when doing this, and I discovered that when I invoked my interrupt, the CPU would jump somewhere seemingly arbitrary. After careful debugging and research, I discovered that the memory addresses stored in the interrupt vectors were in reverse.
Well, the x86 architecture is little-endian, but that is not the problem here. The problem is that you are not writing the IVT at all. The IVT is not located at 76500H but at 00000H.

Code: Select all

mov ax, 0x7650
mov es, ax
mov WORD [es:0x0000], ...
Post Reply