Novell is now a part of Micro Focus

I have some code I would like to...

Articles and Tips: qna

01 Jun 2002


Q.

I have some code I would like to port to NetWare, but I can't find any details in the Novell NDK regarding the use of asm (assembly language programming) on the NetWare platform?

All I need is some details regarding register use and the passing of parameters between C functions and ASM.

A.

The ASM NDK was dropped from the supported NDKs because it's technically outdated. Novell makes the ASM NDK available for those developers that still want the functionality. However, the NDK will not be updated. Likewise, the Developer Support newsgroup that supports the ASM NDK is user supported and not Novell supported.

Since the most popular compilers for development to Novell technologies are Metrowerks CodeWarrior (CW) and the dated Watcom compiler, I will give a brief discussion here. For your information, I understand that the call interface stack handling for Watcom and CW are significantly different. Exported APIs should probably always protect all CPU states not used in the interface (although no NLM compilers that I'm aware of allow this to be enforced in source).

It should be possible to achieve this with auxiliary pragmas in Watcom C/C++ and with __declspec(naked) in CodeWarrior Professional Development Kit (PDK) for NetWare, but protecting all CPU states will not make exported APIs absolutely compatible with all imaginable compilers. I suspect that the only way to achieve true compatibility is to agree on a standard and follow it.

In my debugging efforts, I did see some assembler in the debugger today that depended on called export functions preserving state in EBX and EDI although the documentation reported in this thread don't claim EBX should be preserved. I have also seen Watcom generate code to preserve EBX, ECX, and EDX.

Below is an excerpt from "Watcom C/C++ User's Guide:"

"All used 80x86 registers must be saved on entry and restored on exit except those used to pass arguments and return values." So apparently Watcom wants you to be on the safe side and save everything before calling your routine.

So yes, Watcom can generate code that preserves EBX and even EAX registers, but it does this only for the register-based calling convention that cannot be used for NLMs; they use the stack-based calling convention instead, and it does not require that EBX must be saved. By the way, some versions of NLM SDK (issued approx. 10 years ago) contained header file CDECL.H that allowed developers to use the register-based convention for NLMs. It explicitly declared all functions as __cdecl and consisted of hundreds of declarations similar to these:

...
#pragma aux (cdecl) fmod;
#pragma aux (cdecl) fopen;
#pragma aux (cdecl) fprintf;
#pragma aux (cdecl) fputc;
...

So in summary, save all of the CPU state that you need to, and then some, before calling your assembly routine. If you are not sure what needs to be saved, save it all.

(Taken from the ASM DeveloperNet Newsgroup.)

* Originally published in Novell AppNotes


Disclaimer

The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.

© Copyright Micro Focus or one of its affiliates