flat assembler
Message board for the users of flat assembler.

Index > DOS > Int handler install problem. Help!

Author
Thread Post new topic Reply to topic
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher
Hi, all!
I set the int 13h handler, but it doesn't work.
File has a .bin type.
Currently I trying to understand, the reason(s, may be) by which my code is stopped in the call of the SetInterrupt.
The code is as below:
Code:
        org 7E00h
        use16
main:
        ;Move itself to other place (memory in this place is empty).
        cli
        mov     ax,  09000h              ;We have an intention to move our 
                                                  ;code into segment 9000h
        mov     ss,  ax
        mov     sp,  main             ;ss:sp=9000:7E00
        mov     es,  ax                 ;es=9000
        mov     si,  sp                  ;si=7E00
        mov     di,  sp                  ;di=7E00
        mov     cx,  main_length    ;Full length.
        rep     movsb                    ;Copy from 0000:7E00 to 9000:7E00.
        sti

        ;In order to prolongs, we jump to the label of 'load_further'
        ;in this  copy.
        jmp     far 9000h:load_further
load_further:
        ;Address preparation (0000:7C00h). We will load a copy of the MBR.
        xor  ax, ax
        mov  es, ax
        mov  bx, 7C00h
        ;Load with this address.
        mov  ax, 0201h
        mov  cx, 5   ;The 5th sector of zero cylinder.
        mov  dl, 80h
        mov  dh, 0   ;Head 0.
        int  13h

;Interrupt handler installation.
        call SetInterrupt              ;<<<<< Stop in this place... Sad(
        ;Jump to the original MBR.
        jmp 0000:7C00h

;***********************************
; Sets the new interruption vector.
;***********************************
SetInterrupt:
        pusha
        push es
        mov  ax, 0
        mov  es, ax

        cli
        ;Saves old vector.
        mov  ax, [es:13h*4]
        mov  [OldInt13Offset], ax
        mov  ax, [es:13h*4 + 2]
        mov  [OldInt13Segment], ax
        ;Sets new one.
        mov  word [es:13h*4], Handler_13
        mov  word [es:13h*4 + 2], 09000h
        sti

        pop es
        popa
        ret

;************************************
; Int 13h handler.
;************************************
Handler_13:
        sti
        ;If request is addressed to disk 0.
        cmp dl, 80h
        ;In this case we go to the label to_hdd0.
        jz .to_hdd0
        ;Not - to the original int 13.
        call Original_13
        jmp .Handler_end
.to_hdd0:
        ;If read request.
        cmp  ah, 02h
        ;In this case go to the label to_read.
        jz  .to_read
        ;Not - to the original int 13.
        call Original_13
        jmp .Handler_end
.to_read:
        ;call ShowSector ; Print content of the current sector onto the screen.
.Handler_end:

        iret

;************************************************
; An original int 13h
;************************************************
Original_13:
        cli
        pusha
        mov  ax, [OldInt13Offset]
        mov  [.Old13O], ax
        mov  ax, [OldInt13Segment]
        mov  [.Old13S], ax
        popa
        sti

        pushf
         db      9Ah     ; call far
.Old13O  dw      0h
.Old13S  dw      0h

        ret

; Common data
        OldInt13Offset  rw 1
        OldInt13Segment rw 1

main_length = $ - main    


Help me to understand in this occasion... And how correctly I must set the handler in this case?
Post 28 May 2008, 11:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17274
Location: In your JS exploiting you and your system
revolution
I don't see where you initialise the DS segment register?
Post 28 May 2008, 11:12
View user's profile Send private message Visit poster's website Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher
The ds initialisation I just passed...
I make it on this manaer:

Code:
        ...
        mov     ss,  ax 
        mov     sp,  main             ;ss:sp=9000:7E00 
        mov     es,  ax                 ;es=9000 
        mov     si,  sp                  ;si=7E00 
        mov     di,  sp                  ;di=7E00 
        mov     cx,  main_length    ;Full length. 
        rep     movsb                    ;Copy from 0000:7E00 to 9000:7E00. 
        sti 

        cli
        mov     ax,  09000h
        mov     ds,  ax                  ;ds=9000
        push    ds
        sti    
Post 28 May 2008, 11:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17274
Location: In your JS exploiting you and your system
revolution
You may need to initialise DS for the copy routine also just to make sure you are not too dependant on old and possibly unknown values.
Post 28 May 2008, 11:33
View user's profile Send private message Visit poster's website Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher
Hmm... In other words You propouse the something like about this:
Code:
        ;Move itself to other place
        cli
        push cs
        pop  ds
        mov     ax,  09000h 
        mov     ss,  ax
        mov     sp,  main                ;ss:sp=9000:7E00
        mov     es,  ax                  ;es=9000
        mov     si,  sp                  ;si=7E00
        mov     di,  sp                  ;di=7E00
        mov     cx,  main_length         ;Full length.
        rep     movsb                    ;Copy from 0000:7E00 to 9000:7E00.
        sti

        ;Sets the cs and ds.
        cli
        push cs
        pop ds
        sti
    

I understand you correctly?
But the SetInerrupt routine itself does not have your doubts?
Post 28 May 2008, 11:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17274
Location: In your JS exploiting you and your system
revolution
SetInterrupt routine is using DS to store the old and new int13 values, but you didn't properly define DS. Presumably you want DS to be 0x9000 during the execution of anything accessing the int13 stuff.

You need to go through all of your code line by line and determine what value of DS you need at that point. Then make sure that you have set DS to the required value somewhere beforehand. Standard procedure with 16bit code.

The code above is not correct. You set DS twice but the second time it is the same value again so is useless. One assumes you want DS=0x9000 after the rep movsb. BTW: You don't need to disable interrupts when changing DS.
Post 28 May 2008, 12:12
View user's profile Send private message Visit poster's website Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Code:
;Interrupt handler installation. 
        call SetInterrupt              ;<<<<< Stop in this place... ( 
        ;Jump to the original MBR. 
        jmp 0000:7C00h 
    

Did you mean
Code:
;Interrupt handler installation. 
         push 9000H
         pop   ds
        call SetInterrupt              ;<<<<< Stop in this place... ( 
        ;Jump to the original MBR. 
        jmp 0000:7C00h 
    

Code:
Original_13: 
        cli 
        pusha 
        mov  ax, [OldInt13Offset] 
        mov  [.Old13O], ax 
        mov  ax, [OldInt13Segment] 
        mov  [.Old13S], ax 
        popa 
        ;sti                 ; when processor switch to any INT clear INT FLAG

        pushf 
         db      9Ah     ; call far 
.Old13O  dw      0h 
.Old13S  dw      0h 

        ret 
    

_________________
Nil Volentibus Arduum Razz
Post 28 May 2008, 12:26
View user's profile Send private message Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher
Ok, cli/sti don't need for ds.
Yes, I want ds=9000h and set it value directly.
Then why an initial code
Code:
        cli
        mov     ax,  09000h
        mov     ds,  ax                  ;ds=9000
        push    ds
        sti
    

is incorrect?
Identical value of the segment I use in the SetInterrupt directly too.
???
Post 28 May 2008, 12:31
View user's profile Send private message Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher
Did you mean
Code:
;Interrupt handler installation. 
         push 9000H
         pop   ds
        call SetInterrupt              ;<<<<< Stop in this place... ( 
        ;Jump to the original MBR. 
        jmp 0000:7C00h 
    

Yes.
Post 28 May 2008, 13:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.