>Wolfgang Draxinger <wd********@dar kstargames.dewr ites:
>Sure, it's not implemented purely in C ...
Significant pieces are not in C at all :-)
In article <ln************ @nuthaus.mib.or g>
Keith Thompson <ks***@mib.orgw rote:
>I don't believe it's possible to do what avcall does in entirely
portable C. ...
Indeed not. (But if what it does do, non-portably, is good enough
for what you want done, that is obviously sufficient. The time to
worry is when you need it to do more, or to work on another machine.
It should always be possible to make it work there, but it may take
some effort, and possibly modifications to whatever code you have
that uses avcall as well as to avcall itself.)
Here is an example of part of the code (I do not know why it
has its own private offsetof when the <stdlib.hversio n should
work here):
#include "avcall.h.i n"
#define RETURN(TYPE,VAL ) (*(TYPE*)l->raddr = (TYPE)(VAL))
#define OFFSETOF(struct ,member) ((int)&(((struc t*)0)->member))
register void* callee __asm__("%g2"); /* any global or local register */
register __avword o0 __asm__("%o0");
register __avword o1 __asm__("%o1");
register __avword o2 __asm__("%o2");
register __avword o3 __asm__("%o3");
register __avword o4 __asm__("%o4");
register __avword o5 __asm__("%o5");
int
__builtin_avcal l(av_alist* l)
{
register __avword* sp __asm__("%sp"); /* C names for registers */
register float fret __asm__("%f0"); /* %f0 */
register double dret __asm__("%f0"); /* %f0,%f1 */
__avword trampoline[6]; /* room for a trampoline */
__avword space[__AV_ALIST_WORD S]; /* space for callee's stack frame */
__avword *argframe = sp + 17; /* stack offset for argument list */
int arglen = l->aptr - l->args;
__avword i;
if (l->farg_mask) {
/* push leading float args */
if (l->farg_mask & (1<<0))
__asm__("ld %1(%0),%%f1" : : "p" (l), "i" OFFSETOF(av_ali st,args[0]));
[rest snipped]
This is not only gcc-specific, it also does not compile on your%
machine, even if you have gcc. :-) It is not really C code at
all, but rather assembly code with a C skeleton.
(Of course, there is a different version for your% machine.)
[% By "your" I mean "you, the person reading this news article".
There may be a few rare readers -- perhaps Eric Sosman, for instance
-- for whom this statement is untrue, though.]
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out)
http://web.torek.net/torek/index.html