Real mode assembly IV

From OSDev.wiki
Revision as of 05:03, 9 January 2009 by osdev>Troy martin (New page: {{Rating|2}} ''In this fourth chapter of the Real mode assembly bare bones series, we're going to program the Interrupt Vector Table to create a system call interrupt for our use....)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Difficulty level

Medium

In this fourth chapter of the Real mode assembly bare bones series, we're going to program the Interrupt Vector Table to create a system call interrupt for our use.

The IVT, in all it's Glory

The IVT is an array of 1024 bytes, arranged in 16-bit words. The address of the interrupt handler is stored with the offset word first, segment second. Thing's couldn't be easier.

Adding a BIOS INT Style Handler

My style of handler goes like this:

inthandler:
  cmp ah,0
  je .ahzero

  cmp ah,1
  je .ahone

  cmp ah,2
  je .ahtwo

  ; ......

  mov si,msgBadAH
  call print_string
  cli
  hlt

.ahzero:
  ; Do whatever needed here
  iret

But that's just an outline, you'd need to do it up however you need to use your calls. The FLAGS register is restored in an iret so you need to set it on the stack again depending on how it's set before the iret is done!

Adding the Handler to the IVT

This is fairly simple. First, null out ES. Set AL=interrupt number, and BL=4h. Multiple AL by BL, and then put the result (AX) in BX. Move the word that is the address of the start of your interrupt handler into [es:bx], add 2 to BX, and then move your handler's segment into [es:bx]. There you go, your interrupt is done.

<- Real mode assembly III  |  none ->