www.delorie.com/djgpp/v2faq/faq18_3.html   search  
Node:Zero SP, Next:, Previous:Pointer segment, Up:Low-level

18.3 How to call real-mode functions

Q: My program crashes/doesn't do what it should when I call __dpmi_simulate_real_mode_procedure_retf.

A: You should zero out some of the members of the __dpmi_regs structure before you call the DPMI function that invoke real-mode procedures. Random values in these members can cause your program to behave erratically. The members in point are .x.ss, .x.sp, and .x.flags. When .x.ss and .x.sp are zeroed, the DPMI host will provide a stack for the call. This stack is usually large enough, but sometimes you'll need to use your own, larger stack, e.g., if you expect interrupts to nest deeply, or if your handler needs a lot of stack space31. In these cases you should point .x.ss and .x.sp to a larger buffer which is in conventional memory (possibly part of the transfer buffer).

If SS:SP isn't zero, it will be used as the address of the stack for the interrupt handler, so if it points to a random location, your program will most certainly crash. A non-zero FLAGS member can also make the processor do all kinds of weird things (e.g., imagine that the single-step or the debug bit is set!).



  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2001   by Eli Zaretskii     Updated Apr 2001