Fog Creek Software
Discussion Board




Calling real mode FAR call from protected mode

Scenario:
------------
The protected mode is Causeway 32Bit DOS-Extended environment. There is call _go32_dpmi_simulate_fcall which helps to execute real mode FAR calls from protected mode.

Sample code:
----------------

@example
_go32_dpmi_registers r;
r.x.ax = 47;
r.x.cs = some_segment;
r.x.ip = some_offset;
r.x.ss = r.x.sp = 0;
_go32_dpmi_simulate_fcall(&r);
printf("returns %d\n", r.x.ax);
@end example

CS and IP indicates address of the call. The CPU registers are loaded from the structure located by 'r'.

The Problem:
----------------
What we have to do if we need to pass parameters for the FAR call ( which is given in CS:IP ) ?

A solution for this will be well appreciated.

References:
---------------
http://www.devoresoftware.com/cwwman/page_48.htm
http://eprom.myetang.com/intr/rb-5800.htm

Thanks!

Cherian Nair
Saturday, April 10, 2004

Normally when you "pass parameters" you pass them on the stack. These ...

  r.x.ss = r.x.sp = 0;

... imply to me that you have no control over what's on the stack of the function you are calling.

If you have a small number of parameters to pass, you could try passing them in registers (e.g. r.x.bx, r.x.cx, r.x.dx, r.x.di, r.x.si).

Another possibility might be to write your parameter values into a global variable: a structure at some address in real-mode memory.

Disclaimer: I don't know _go32_dpmi_simulate_fcall and I didn't understand the References you gave.

Christopher Wells
Saturday, April 10, 2004

By reading up on the DPMI stuff you supplied, you could try the following:

Use GetMemDos to allocate a number of paragraphs you need; paragraphs are 16 byte chunks if memory serves correctly.

Here are the docs for that call

AX = FF21h
BX = number of paragraphs to allocate
Return:CF clear if successful
AX = real-mode segment of allocated block
DX = initial selector for block
CF set on error

If you set up say 64 paragraphs (1K) of conventional memory to be used as your real-mode call stack and pass that in as SS:SP of the DPMI real mode call structure.

By setting the SP to 0, DPMI allocates a stack; but try to pass your own allocated memory in the SS:SP struct.

Patrik
Saturday, April 10, 2004

I dont know how much parameter data you need to send, your post doesn't say. However by moving the parameter data to the real mode memory and set SP accordingly, you should get a usable stack frame.

I think SP gets decremented; it works in a top down fashion if Im not misstaken, so you have to move your parameter data in the correct order and set SP to the highest address for POP to work correctly in your real mode routine.

Patrik
Saturday, April 10, 2004

Sorry...

It should read...*set SP to the lowest address*

Who said assembly programming is hard? :)

Patrik
Saturday, April 10, 2004

Thanks a lot for the responses. I got something to try.

Cherian Nair
Sunday, April 11, 2004

Number of arguements varies.

Cherian Nair
Sunday, April 11, 2004

*  Recent Topics

*  Fog Creek Home