problems extending BIOS ISR handler.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
inderpreetb

problems extending BIOS ISR handler.

Post by inderpreetb »

Hi all

people i don'nt know if this belongs here or not but i am having some problem developing an ISR which will actually extends the BIOS routines.

It's a 16 bit ISR which is trying to extend int 13h services.

Code: Select all

ISR Code

; /* This is the new Interrupt handler to be
;  * replace with the old interrupt handler.
;  */
_new_int13:

???jmp near start_isr

 ; /* saved GP registers.  */
 oldax dd 0
 oldbx dd 0
 oldcx dd 0
 olddx dd 0

 ; /* saved index registers.  */
 oldsi dd 0
 olddi dd 0

 ; /* saved segment registers.  */
 oldes dw 0
 oldfs dw 0
 oldss dw 0
 oldds dw 0
 oldsp dw 0
 offs  dw 0

 oldflags dw 0


_old_int13:
???dw 0
???dw 0


start_isr:

???push ds
???pushf
???push cs
???pop ds
???mov dword [oldax], eax

???; save the flag registers
???
???pop ax
???mov word [oldflags], ax

???; save DS register
???pop ax
???push ax
???mov word [oldds], ax
???
???; save other registers. 
???mov eax, dword [oldax]
???mov dword [oldbx], ebx
???mov dword [oldcx], ecx
???mov dword [olddx], edx
???mov dword [oldsi], esi
???mov dword [olddi], edi

???mov word [oldsp], sp
???mov word [oldss], ss
???mov word [oldes], es
???
???; /* setup our own stack.  */
???cli
???mov ax, ds
???mov ss, ax
???mov sp, stack_top
???mov eax, dword [oldax]
???sti

???cmp byte ah, 42h
???jz lbamode
???
???cmp byte ah, 43h
???jz lbamode

???cmp byte ah, 02h
???jz chsmode

???cmp byte ah, 03h
???jz chsmode
???

jmp_to_org:

???; /* Just jump to the default handler.  */
???mov eax, dword [oldax]
???mov ebx, dword [oldbx]
???mov ecx, dword [oldcx]
???mov edx, dword [olddx]
???mov esi, dword [oldsi]
???mov edi, dword [olddi]
???
???cli
???mov ss, word [oldss]
???mov sp, word [oldsp]
???sti

???; /* restore the flags.  */
???push word [oldflags]
???popf

???pop ds
???jmp far [cs:_old_int13]


; /* CHS mode is used here.  */???
chsmode:
lbamode:
???
???; /* check the disk number.  */
 ???; cmp byte dl, 80h
???; jnz jmp_to_org
???
    
???mov eax, dword [oldax]
???mov ebx, dword [oldbx]
???mov ecx, dword [oldcx]
???mov edx, dword [olddx]
???mov esi, dword [oldsi]
???mov edi, dword [olddi]
???
???cli
???mov ss, word [oldss]
???mov sp, word [oldsp]
???sti

???; restore the flags. 
???push word [oldflags]
???popf

???pop ds

???push word 0
???call far [cs:_old_int13]
???pushf
???jb error

???; /* do extra processing here. */???

???
error:
???popf
retf 2
the problem is that this code works fine in bochs, but in qemu it says "Replace disk and press any key to continue" and on the actual system the whole system just hangs.

I am not able to understand what the problem could be. :(

Any help will be appretiated.

Inder.

[edit by candy] please do use code tags for your code[/edit]
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:problems extending BIOS ISR handler.

Post by Pype.Clicker »

questions are:
- when do you put those extensions ?
- what code do call your functions ?

I would be tempted to say that BOCHS might not attempt to use extended functions of the BIOS (either because BOCHS's BIOS doesn't report them available or because the disks BOCHS mimmics makes other software think that it's useless to use extended functions) while real hardware/qemu make use of functions that are not properly implemented/relayed by your code.

Oh, and a propos, you don't need all those vars to save the old register state: you can just have them push'd on the stack: that will make the whole code _way_ easier to read ...
inderpreetb

Re:problems extending BIOS ISR handler.

Post by inderpreetb »

I have developed an MBR which actually installs all the required hooks and copies the ISR into the required location.

Then i read the boot sector of the active partition and transfer control to it and i am trying to boot up DOS through it.

I can send you the full source if you want.

As far as bochs is concerned i am using extended read/write in bochs and they are working fine. ???


Inder.
AR

Re:problems extending BIOS ISR handler.

Post by AR »

Code: Select all

push word 0
   call far [cs:_old_int13]
   pushf

...

retf
It's been a while since I messed with this sort of stuff, but shouldn't that be an IRET since the handler is an interrupt not a far call, and by the same token the "old" INT13 will IRET not RETF meaning a far call will not push FLAGS so the IRET will pop a random value into the FLAGS register which will probably break it.
inderpreetb

Re:problems extending BIOS ISR handler.

Post by inderpreetb »

Here goes what i know about interrupts

When an interrupt call is issued via an INT instruction, two things
occur, in this order:

1) The flags are pushed onto the stack.
2) A far call is issued to the segment:offset located in the interrupt table.

To return from an interrupt, an iret instruction is used. The iret instruction reverses the order of the int call. It performs a retf followed by a popf.

So what i am actually trying to do here is that i am calling the old_int handler with flags set to all zero and when the interrupt calls iret it will actually pop the flags which will indicate the status. (CF set or cleared) and registers returning values.

So now when i have to return this status to the origanal caller
i do a
[shadow=red,left] retf 2[/shadow]
which actually does a return far and adjusts the stack by 2 bytes so that now whatever flags are currently set in my handler are returned to the caller.

did i miss something ;D
Post Reply