Real mode assembly IV: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
mNo edit summary
Line 47: Line 47:


[[Category:Real mode assembly]]
[[Category:Real mode assembly]]
<- [[Real mode assembly III]] | none ->
<- [[Real mode assembly III]] | [[Real mode assembly appendix A]] ->

Revision as of 23:53, 18 February 2009

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.

  1. First, null out ES.
  2. Set AL=interrupt number, and BL=4h.
  3. Multiply AL by BL, and then put the result (AX) in BX.
  4. Move the word that is the address of the start of your interrupt handler into [es:bx].
  5. Add 2 to BX.
  6. Move your handler's segment into [es:bx].
  7. Restore your original ES and you're done!
<- Real mode assembly III  |  Real mode assembly appendix A ->