Page 1 of 1

about call eax

Posted: Wed Jan 25, 2006 3:00 am
by rootel77
can anyone tell me what is the diff between the tow codes below

form1

Code: Select all

mov eax, int_handler
call eax
and form2

Code: Select all

call int_handler
and why the first form is encountered in all samples i've read about interrupt handlers (written in asm and calling a c handler)?

Re:about call eax

Posted: Wed Jan 25, 2006 3:20 am
by Pype.Clicker
beside the fact that form1 is more complex for the pipeline, i don't see any difference. I guess that's just because people copy-and-paste IRQ stubs without completely getting what's going on. Clicker do

Code: Select all

   ; ...
   and eax,byte 0x7f
        push eax                   ; IRQ number
        call _processIrqList    ; call list processing
        add esp,4
    ; ...
and it works just fine :P

Re:about call eax

Posted: Wed Jan 25, 2006 3:21 am
by Candy
rootel77 wrote: can anyone tell me what is the diff between the tow codes below

form1

Code: Select all

mov eax, int_handler
call eax
and form2

Code: Select all

call int_handler
and why the first form is encountered in all samples i've read about interrupt handlers (written in asm and calling a c handler)?
IIRC, the first makes it an absolute indirect call, while the second would make it a relative direct call.

I'm not sure why you would make it an absolute indirect call, but I assume there's some pointer to the location in the mov that loads the address. If so, you can replace that instantly without any significant delay. You can't just replace a relative call, and some compilers optimize relative calls to nearby code to a shorter opcode. If they do that, the code is smaller and you get unpredictable crashes.

Re:about call eax

Posted: Wed Jan 25, 2006 3:51 am
by rootel77
I assume there's some pointer to the location in the mov that loads the address. If so, you can replace that instantly without any significant delay. You can't just replace a relative call, and some compilers optimize relative calls to nearby code to a shorter opcode. If they do that, the code is smaller and you get unpredictable crashes.

it seems to be the only valid reason, this is a commentary in the irq stub from the OSD (http://my.execpc.com/~geezer/osd/)

Code: Select all

; setvect() changes the operand of the CALL instruction at run-time,
; so we need its location = 27 bytes from start of stub. We also want
; the CALL to use absolute addressing instead of EIP-relative, so:
         mov eax,fault   ; (26)
         call eax   ; (31)