Page 1 of 1

how to do dynamic far calls in nasm(32 bit)

Posted: Mon Jul 17, 2006 12:32 am
by earlz
hi I'm trying to make a FarCall function for C in asm and I've tried just about everything but have yet to make something without errors so how do you do a far call like this:
"call eax:ebx"

Re:how to do dynamic far calls in nasm(32 bit)

Posted: Mon Jul 17, 2006 1:04 am
by kernel64
The Intel manuals: http://developer.intel.com. Indispensable! ;D Look up "CALL - Call Procedure" or something (from memory, look in the table of contents for the first and third volumes). Also check the NASM manual for the assembler syntax used. It's not "call eax:ebx" for example.

Good luck!

Re:how to do dynamic far calls in nasm(32 bit)

Posted: Mon Jul 17, 2006 5:23 am
by Pyr0Mathic
lo,

assuming you are in Real mode and if after a lot of trying you would nt be able to get call CS:EIP (call 16-bit segment reg:32bit offset)

you still could use the command RETF, then you simple first push it on the stack, and after that you pop it whit the RETF command

something like this, for Call simply first push current CS:IP:

Code: Select all

push ax         ; <--- segment selector
push bx         ; <--- IP, offset
                   ; might need to be done the other way arround...
RETF            ; <--- 16-bit JMP AX:BX command
this above i used for my jump into protected mode. since i also had problems whit the nasm-syntax on that point. It aint perfect but it does the job.

in protected mode you will also be able to do that, just its a bit more complicated due to Task-switching etc.

Hope this helps.

i would look at Intel manuel, 2.. CALL/RET/RETF/JMP commands..

Regards
PyroMathic

Re:how to do dynamic far calls in nasm(32 bit)

Posted: Mon Jul 17, 2006 10:30 am
by blip
I suck at C and interfacing it with ASM but here's my best shot:

Code: Select all

_FarCall:   ; void FarCall ( int32 offs, int16 seg );
call pword [esp+4]   ; NASM may need FAR instead of PWORD, I use FASM btw
ret
The function assumes your compiler uses a near call to call it in 32-bit mode, I'm sure that's the case. Also I think C pushes parameters in reverse order, if not then simply swap them.

Re:how to do dynamic far calls in nasm(32 bit)

Posted: Sun Aug 06, 2006 5:04 am
by Pype.Clicker
yes, iirc, you cannot do something like "call eax" for a far call. You have to write down segment and offset into some memory location and then use call far [memory_reference].

E.g., from Clicker's core/control.asm

Code: Select all

; "far" call, including call of another TASK
; protocole: void _farCall(offset, segment).
Cglobal farCall
farCall:
        push ebp
        mov ebp,esp
        call far [ebp+8]
        pop ebp
        ret
that's pmode far call, though.