views:

172

answers:

1

Is there any restriction on using #define'd functions/inline functions inside Assembly files.

I referred bsd kernel in which two different implementations are defined. One is macro and other is a normal function ( both are for same function)

In the c file splx is defined asfunction, http://ftp.hu.freebsd.org/pub/netbsd/NetBSD-release-4-0/src/sys/arch/arm/omap/omap_intr.c

Whereas in h header file splx is defined as macro, http://ftp.hu.freebsd.org/pub/netbsd/NetBSD-release-4-0/src/sys/arch/arm/omap/omap_intr.h

My understanding is c file definition is used in assembly files whereas macro definition is used in all other functions where the header file is included.

I think I m not clear why assembly is coming into picture here. Basically there are two definitions , one in the c file and another in h file for splx. When I just comment out splx definition in C fle, I get some errors in the compilation of Assembly files.(cpu.S) Thatz why I thought function definition is used(as in c file) while compiling assembly file, whereas macro definition is used for all other files include the h file.

Now my question is , why can't assembly file too cannot use the macro definition by including the header file.

Kindly clarify. Thanks

A: 

In the header file, splx is defined as

void splx(int)
void _setsoftintr(int);

#if !defined(EVBARM_SPL_NOINLINE)
#define splx(new) omap_splx(new)
#define _spllower(ipl) omap_spllower(ipl)
#define _setsoftintr(si) omap_setsoftintr(si)
#endif /* !EVBARM_SPL_NOINTR */ 

I'm not sure why you're referring to assembly files when this language is clearly C, but I see nothing wrong with these declarations - splx is a function, but if EVBARM_SPL_NOINLINE is defined then the macro is used to remap all uses of splx to splx_omap. This is a valid use of the preprocessor, and is not redefining splx - rather using some trickery to modify code to use splx_omap.

This works because the preprocessor runs before the compiler, so any occurence of splx will be replaced by splx_omap before compilation takes place. Some people would find this disturbing but it's one of the capabilities of the preprocessor and is quite useful (when proper precautions are observed).

Sam Post
hi Sam,Thanks !I think I m not clear why assembly is coming into picture here.Basically there are two definitions , one in the c file and another here for splx.When I just comment out splx definition in C fle, I get some errors in the compilation of Assembly files.(cpu.S)Thatz why I thought function definition is used(as in c file) while compiling assembly file, whereas macro definition is used for all other files include the h file.Now my question is , why can't assembly file too cannot use the macro definition by including the header file.
kumar
The macro definition is only used to force all callers of splx to use splx_omap instead, if EVBARM_SPL_NOINLINE is defined. The compilation of cpu.S probably doesn't define EVBARM_SPL_NOINLINE which is why you get errors when splx is commented out in C file. If you want cpu.S to use splx_omap then define EVBARM_SPL_NOINLINE or update all callers of splx to use splx_omap by editing all files. Does that help?
Sam Post