Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inside a Bios interrupt
07-18-2010, 04:47 AM (This post was last modified: 07-18-2010 04:53 AM by dumb_terminal.)
Post: #1
Inside a Bios interrupt
What is segment... the noobs (and i am one) visualize it as a fixed size text container, and offset is the line
no starting from 0.
segment
+--------- +
| offset 0|
| offset 1|
| offset 2|
| offset 3|
| offset 4|
| offset 5|
+-----------+

well u get the idea...

Now where to begin ??
Some wise person heuristically searched the memories and found out in a certain position os keeps the IVT (that is the address tables of the interrupts function). It is stored in a segment, where offset 0 is offset no of that INT0 and offset 2 is segment no of that INT0, then offset 4 is offset of INT1 and offset 6 contains segment no of INT1....u get the idea.
The main thing is the addressing is expressed as an offset from a beginning of a segment. suppose the offset 0 cntains E044 and offset 2 contains FF08
then we will know there is a segment addressed FF08 and the code for the interupt is located at (from the begining of the seegment) E044 no adress. There are a lot of histories..why things are like this..if u are interested u can search the net, people like to vomit theory when it comes to assembly. Well today we will replace the code of a particular interrupt with our own code. There is a private BIOS dancer interrupt numbere 8 which calls a particular function 1CH, every 18 times a sec. Actually ur motherboards timer chip is activated 18 times a sec and calls INT8h. We will take this opportunity to make a watch, suitable as we can't just try to synchronize yet. The code is well commented....u can learn as u go.
Code:
; A simple watch to display time continously
; File Name: timer.asm

title timer_v_01

quit macro
    mov ah, 4ch
    int 21h
endm

.model small
.stack 100h
.data
    time_buf db "00:00:00$"
    cursor_pos dw ?
    new_int_code dw ?, ?
    old_int_code dw ?, ?

.code
main proc near
    ; adjusting the data segment remember
    mov ax, @data
    mov ds, ax
    
    ; get cursor pos
    ; int 10h func - 03h
    ; input - BX - page_no
    ; output - DH - row DL - col
    mov ah, 03h
    mov bh, 0
    int 10h

    ; storing the cursor position
    mov cursor_pos, dx
  
    ; moving the procedures offset and segment no
    ; to memory for replacing later -- c the 2 distance
    ; its coz a word size is 2 in bytes
    mov new_int_code, offset get_time
    mov new_int_code + 2, seg get_time
    
    ; preparing the index registers
    ; for further action related to old interrupt code
    ; and new interrupt code
    lea di, old_int_code
    lea si, new_int_code
    mov dl, 1ch
    
    ; the previous 3 lines prepare params for the next call
    call set_up_interrupt
    
    ; now wait for a key press
    ; int 16h func 0 - single char input from keyboard directly
    ; no echo
    mov ah, 0h
    int 16h
    
    
    ; we must reset the interrupt code as was
    ; we don't wanna mess up bios timer chip
    lea si, old_int_code
    lea di, new_int_code

    ; this is to reset    
    mov dl, 1ch
    call set_up_interrupt
  
    quit
main endp

get_time proc
    
    ; get current time
    ; int 21h, func no - 2ch
    ; output : ch - hour cl - min dh - sec dl - 1/100th sec
    
    push ds
    mov ax, @data
    mov ds, ax
    
    lea bx, time_buf
    mov ah, 2ch
    int 21h
    
    xor ax, ax
    mov al, ch
    ; we are gonna call it to make a multidigit no
    call convert
    mov [bx], ax
    xor ax, ax
    mov al, cl
    call convert
    mov [bx + 3], ax
    xor ax, ax
    mov al, dh
    call convert
    mov [bx + 6], ax
    
    mov ah, 09h
    lea dx, time_buf
    int 21h
    
    ; set cursor pos int 10h func - 02h
    ; bh - pageno dh - row dl = col
    mov ah, 02h
    mov bh, 0 ;
    mov dx, cursor_pos
    int 10h
    
    pop ds
    iret ; return from interrupt - our procedure has become
         ;a replacment of an interrupt.
get_time endp

set_up_interrupt proc near
    
    ; input - dl, si, di

    ; get the segment and offset of a interrupt code
    ; int 21h func 35h
    ; input al - the function no of which we want to recv address
    ; of code
    ; output ES - segment BX - Offset
    mov ah, 35h
    mov al, dl
    int 21h
    
    ; moving offset and the segment to the address stored in di and di + 2
    mov [di], bx
    mov [di + 2], es
    
    mov bl, dl
    push ds
    
    ; int 21h func 1ch
    ; task : set a functions new code offset and segment
    ; input al - func no which we want to misdirect
    ;       ds - segment of new code  dx - offset of new code
    ; output : NONE (passively sets it)
    ; note : we needed the data segment c thats why we pushed it earlier
    ; and gonna restore it later :D
    
    mov ah, 25h
    mov al, bl
    mov dx, [si]
    mov ds, [si + 2]
    int 21h
    

    pop ds
    ret  ; return from a procedure
set_up_interrupt endp



convert proc near
    push dx
    mov ah, 0
    mov dl, 10
    div dl
    ; quotient - al remainder - ah
    ; in4ming u earlier so u don't make confusion
    ; little endian -- if u don't know theres always google
    or ax, 3030h
    pop dx
    ret

    
convert endp
end main


Now what new things we learn here --
1.macro ( a shorthand)
2. procedures (really important u shuld have a good grasp of procedures and stack)
3. a basic vedio handling
4. two pseudo ops - offset - returns the params offset in current segment
seg - return the segment umbern.
2gather u can calculate the real address

Finally i have 2 apologize to u guys...that i can't contribute that much..u know can't find time these days. so plz 4give me.
and lastly if u have any confusion about assembly or finding it hard to grasp (most of u shuldn't have problem u guys r h4ck3rs), u can pm me or comment here, when i will get time (i think its in the mid of next month) i will try to write easy to understand 20 part crash course in assembly. Hats off, hope to be back soon, have a nice time guyz. Big Grin

My codes are not full of Bugs, they are full of Spiders.
Find all posts by this user
Quote this message in a reply
07-18-2010, 05:02 AM
Post: #2
RE: Inside a Bios interrupt
very useful information thanx for shareing i need this i was search around but didnt get
thanx again (Bios interrupt)

Isectech.net
Visit this user's website Find all posts by this user
Quote this message in a reply
07-18-2010, 05:09 AM
Post: #3
RE: Inside a Bios interrupt
hey always for the community bro. Big Grin

My codes are not full of Bugs, they are full of Spiders.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: