Page 1 of 1

Interrupt Vector Table Article

Posted: Wed Apr 06, 2011 6:48 am
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

Re: Interrupt Vector Table Article

Posted: Wed Apr 06, 2011 7:08 am
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?

Re: Interrupt Vector Table Article

Posted: Wed Apr 06, 2011 7:14 am
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], ...