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
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(6 intermediate revisions by 3 users not shown)
Line 11: Line 11:
My style of handler goes like this:
My style of handler goes like this:


<syntaxhighlight lang="asm">
inthandler:
inthandler:
cmp ah,0
cmp ah,0
Line 31: Line 32:
; Do whatever needed here
; Do whatever needed here
iret
iret
</syntaxhighlight>


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!
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!
Line 46: Line 48:
# Restore your original ES and you're done!
# Restore your original ES and you're done!


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

Latest revision as of 04:48, 9 June 2024

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