flat assembler
Message board for the users of flat assembler.

Index > DOS > Again about the int handler moving. Remains unresolved.

Author
Thread Post new topic Reply to topic
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher 29 May 2008, 13:27
In spite of your help my problem has been remained unresolved. Sad Sad
(Reminder: I set the int 13 handler and then move it onto segment 9000h. This segment is assuredly free).
However, it does not work. As previously the execution stops on the call SetInterrupt.
I don't have a possibility to use debugger in order to understand an issues of this problem.
Help me, please, GURU!

This is the full code:
Code:
        org 7E00h
        use16
main:
        ;Move itself to other place
        cli
        mov     ax,  9000h              ;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).
        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.
        mov  ax,  9000h
        mov  ds,  ax

        call SetInterrupt
        ;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  [Original_13.Old13O], ax
        mov  ax, [es:13h*4 + 2]
        mov  [Original_13.Old13S], ax
        ;Sets new one.
        mov  word [es:13h*4], Handler_13
        mov  word [es:13h*4 + 2], 9000h
        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. It was excluded.
.Handler_end:

        iret

;************************************************
; An original int 13h
;************************************************
Original_13:
        cli

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

        ret

        main_length = $ - main

    
[/code]
Post 29 May 2008, 13:27
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 29 May 2008, 13:39
Code:
        org 7E00h 
        use16 
main: 
        ;Move itself to other place 
        cli 
        push 0
        pop ds
        mov     ax,  9000h              ;We have an intention to move our code into segment 9000h 
        mov     ss,  ax 
        mov     sp,  7E00h                ;ss:sp=9000:7E00 
        mov     es,  ax                  ;es=9000 
        mov     si,  7E00h                  ;si=7E00 
        mov     di,  7E00h                  ;di=7E00 
        mov     cx,  main_length         ;Full length. 
        rep     movsb                    ;Copy from 0000:7E00 to 9000:7E00. 
        sti 
     
    

it's not all code , post boot code and The 5th sector of zero cylinder.
You Boot From Floppy ?
Hard disk ?
All code please
and explain what do you make it . Question

_________________
Nil Volentibus Arduum Razz
Post 29 May 2008, 13:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20526
Location: In your JS exploiting you and your system
revolution 29 May 2008, 14:18
Even though you don't have a debugger, you still have options for debugging.

Use the screen. Output single characters to the screen to show at what point your code has got to. A simple sequence of A-B-C-D-... would be enough. It is one of the oldest ever "debuggers", and often still the most effective in certain situations (like a boot loader).

Use a VM: QEMU, Virtual PC, Bochs, ... Some of them have debugging modes.
Post 29 May 2008, 14:18
View user's profile Send private message Visit poster's website Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher 29 May 2008, 14:31
The 5th sector contains the copy of the original MBR.
The code from the first sector simply reads the code given above to es:bx.
I boot from the hard disk 0.
First sector code:
Code:
           org     7C00h
           use16
bootcode:
           cli
           xor  ax, ax
           mov  ss, ax
           mov  sp, 7C00h
           push cs
           pop  ds
           push ax
           pop  es
           sti

           mov  bx, end_offset ;
           mov  ah, 02h
           mov  al, 10  ; Count of sectors
           mov  ch, 0
           mov  cl, 6    ;Start sector (code above)
           mov  dh, 0
           mov  dl, 80h ; HDD0
           int  13h

           jmp 0000:7E00h

;-------------------------------------------------------------
                 rb 7C00h + 512 - 2 -$  ;Fill with zero the rest of the sector.
                 db 055h,0AAh            
    end_offset = $
    
Post 29 May 2008, 14:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20526
Location: In your JS exploiting you and your system
revolution 29 May 2008, 14:43
What are you expecting to see? Your int13 handler blocks all read attempts and then "Print content of the current sector onto the screen."

But here is probably where the problem is: "It was excluded". I suggest that your problem is in the code you excluded. We can't help you if you hide information, we have to guess that "you know what you are doing" but that can be very dangerous for us to guess. If you exclude something then we will naturally think that your problems lies there because we can't see it.

Have a look at this thread, and read all of it from start to finish. Then you will see why you must show all your code. You, and me, cannot assume that your excluded part is not where the problem lies. If we assume then we make an ASS out of U and ME. Wink
Post 29 May 2008, 14:43
View user's profile Send private message Visit poster's website Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher 29 May 2008, 14:56
You too distrust.
I hide nothing.
This code REALLY full.
I execute THIS code, without any other routines.
Concretely this code does not work.


Last edited by FASMresearcher on 29 May 2008, 15:04; edited 1 time in total
Post 29 May 2008, 14:56
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20526
Location: In your JS exploiting you and your system
revolution 29 May 2008, 15:01
FASMresearcher wrote:
You too distrust.
I hide nothing.
This code REALLY full.
In that case the problem is solved.
Code:
...
        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. It was excluded.
.Handler_end:
        iret    
You never allow "read" (AH=2) to proceed, then the MBR can never run properly.

Case closed, right?
Post 29 May 2008, 15:01
View user's profile Send private message Visit poster's website Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher 29 May 2008, 15:14
Hmmmmm.... I suspected something of this kind…
It seems to me you are right.
I try my code for checking this line tomorrow. Thank you for help!
Post 29 May 2008, 15:14
View user's profile Send private message Reply with quote
FASMresearcher



Joined: 28 May 2008
Posts: 24
FASMresearcher 30 May 2008, 14:22
revolution wrote:
You never allow "read" (AH=2) to proceed, then the MBR can never run properly.

Case closed, right?

Yeeessss!!! Of course!!!
Thanks a lot!
I have changed the similar expressions and code became workable.
I appreciate for your help! Very Happy
Post 30 May 2008, 14:22
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.