preprocessor: % as args to #defines
Marc Espie
espie@quatramaran.ens.fr
Sat Feb 14 14:59:00 GMT 2004
Let's talk real-life, then.
Is theere any kind of standard for intrinsices on, say, i386 ?
Speaking from personal experience, the OpenBSD kernel uses inline
assembler to:
- do IO
- establish bufspace barriers (not sure if that's applicable to i386)
- change interrupt blocking level.
The interrupt level hadnling roughly looks like this:
volatile int cpl; /* Current interrupt priority level. */
volatile int ipending; /* Interrupts pending. */
volatile int astpending;/* Asynchronous software traps (softints) pending. */
static __inline int
splraise(ncpl)
int ncpl;
{
int ocpl = cpl;
if (ncpl > ocpl)
cpl = ncpl;
__asm __volatile("":::"memory");
return (ocpl);
}
note the asm volatile.
software interrupt registration uses asm too.
static __inline void
softintr(mask)
int mask;
{
__asm __volatile("orl %1, %0" : "=m"(ipending) : "ir" (mask));
}
can I now do this kind of thing in C entirely ? this is not code I know
well, btw...
More information about the Gcc
mailing list