small problem with hooking/returning from an interrupt

Hello everyone,



I'm trying to do a small TSR, but somehow it doesn't work and I don't see the problem, so if anyone could show me I'd be very, very thanksful (must be something with the stack...).





The TSR hooks onto interrupt 21h (that isn't a typo, it's the dos service interrupt, really)... puts a colored smiley in the right top of the screen, jumps to the "real" interrupt 21h and then it is supposed to jump back to my other piece of code, which removes

the colored block and replaces it with a space.. I know the whole things sounds a bit dumb, but I'm trying to get a better understanding

of how things work :)..



Now I've coded this small part:



(Please note, BackPtr is loaded with the offset of the Back LABEL in my installation routine as follows:



mov ax, offset cs:Back

mov word ptr cs:BackPtr, ax



================================================

THIS IS THE TSR

================================================





SMILEY EQU 1701h

SPACE EQU 7020h



OldDOSINT21 dd ?

VideoOrigin dw 0B800h

BackPtr dw ?





NewINT21:



push es

push word ptr cs:VideoOrigin

pop es



mov word ptr es:[009Eh], SMILEY

pop es





; Simulate an INT and put the return address

; of my code onto the stack.

; That is: FLAGS / SEGMENT / OFFSET



pushf

push cs

push word ptr cs:BackPtr



jmp cs:OldDOSINT21



Back: push es

push word ptr cs:VideoOrigin

pop es

mov word ptr es:[009Eh], SPACE

pop es



IRET



================================================



Now when an int 21h is generated my smiley is put on the screen and then it hangs. I'm not sure if the computer ever reaches INT 21h

successfull, because I can't check it. If anyone could tell me what is going wrong (I think it's something with the stack) I'd be

very grateful..



-robin



Note: OldDOSINT21 is loaded correctly (I'm very sure) with segment value at word ptr [OldDOSINT21+2] and offset into word ptr [OldDOSINT21]...








Comments

  • .model tiny

    .586

    SMILEY = 1701h

    SPACE = 7020h

    INTVECT=21h*4

    .code

    ORG 100h

    __main:

    xor ax, ax

    mov es, ax

    mov si, INTVECT

    mov eax, es:[si]

    mov cs:[oldintvect], eax

    mov ax, cs

    mov es:[si+2], ax

    mov ax, OFFSET MyInt

    mov es:[si], ax



    ;all that was was saving the old interrupt vector and patching it



    mov dx, OFFSET randomstr

    mov ah, 9

    int 21h



    ;just to use int 21h



    xor ax, ax

    mov es, ax

    mov si, INTVECT

    mov eax, cs:[oldintvect]

    mov es:[si], eax



    ;patching back the old (necessary unless you want to see a creative ;reboot)



    mov ax, 4C00h

    int 21h



    ;exit errorcode 0 blah blah blah etc etc



    MyInt:

    push es

    push ax

    mov ax, 0B800h

    mov es, ax

    mov WORD PTR es:[0], SMILEY

    xor ax, ax

    int 16h

    pop ax

    pop es

    pushf

    call DWORD PTR cs:[oldintvect]

    push es

    push ax

    mov ax, 0B800h

    mov es, ax

    mov WORD PTR es:[0], SPACE

    xor ax, ax

    int 16h ;BIOS call to getkey (just to make the changes show more)

    pop ax

    pop es

    iret



    ;your code with a few spruced up bits



    oldintvect dd ?

    randomstr db 'asdfasdfasdf$'



    ;room for the old interrupt vector and some random string



    END __main




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories