[U-Boot-Users] [PATCH] Functions added to extern for stand alone programs
Jeffrey Mann
mannj at embeddedplanet.com
Wed May 23 22:48:02 CEST 2007
> >
> > > #define cond_extern(name) asm(".weak\t" #name "\n\t.set\t" #name ",
> > > unimpl_extern")
> >
> > I do not understand what this does. Does it work?
>
> Yes, it does. See file: gcc.info, node: Function Attributes,
> section: 5.24 Declaring Attributes of Functions
>
> > > static int unimpl_extern(void)
> > > {
> > > return -ENOSYS; /* or something more appropriate */
> > > }
> >
> > How is this different that using the dummy function?
>
> The main difference is that with "normal" functions you must make
> sure that the dummy function does not get compiled / linked when you
> implement a real function. "Weak" are simply overwritten if any user
> provides another (real) function with the same name. No #ifdef mess
> any more :-)
So in practice, it would look something like this?:
void jumptable_init (void)
{
int i;
gd->jt = (void **) malloc (XF_MAX * sizeof (void *));
for (i = 0; i < XF_MAX; i++)
gd->jt[i] = (void *) dummy;
#define EXPORT_FUNC(name) asm(".weak\t" #name "\n\t.set\t" #name ", dummy");
#include <_exports.h>
#undef EXPORT_FUNC
gd->jt[XF_get_version] = (void *) get_version;
gd->jt[XF_malloc] = (void *) malloc;
gd->jt[XF_free] = (void *) free;
gd->jt[XF_getenv] = (void *) getenv;
gd->jt[XF_setenv] = (void *) setenv;
gd->jt[XF_get_timer] = (void *) get_timer;
gd->jt[XF_simple_strtoul] = (void *) simple_strtoul;
gd->jt[XF_udelay] = (void *) udelay;
gd->jt[XF_install_hdlr] = (void *) irq_install_handler;
gd->jt[XF_free_hdlr] = (void *) irq_free_handler;
gd->jt[XF_i2c_write] = (void *) i2c_write;
gd->jt[XF_i2c_read] = (void *) i2c_read;
........
}
it could't really be that simple, could it? I bet my sintax is wrong,
and I still do not compleatly understand how the compiler intreprets
"weak" and "set". But I can see how this would work.
-Jeff
More information about the U-Boot
mailing list