Code: Select all
typedef void *va_list;
#define va_rounded_size(T) \
(((sizeof(T)+sizeof(int)-1)/sizeof(int))*sizeof(int))
#define va_start(ap,lastarg) \
( ap=(va_list)((char *)&(lastarg)+va_rounded_size(lastarg)) )
#define va_arg(ap, T) \
(ap = (va_list) ((char *) (ap)+va_rounded_size(T)), \
*((T *) (void *) ((char *) (ap)-va_rounded_size(T))))
Code: Select all
void testf(char *msg, ...)
{
va_list ap;
int d;
va_start(ap,msg);
kprintf("\nmsg=0x%X ap=0x%x",&msg,ap);
d=va_arg(ap,int);
kprintf("\n%d @ %X",d,ap);
}
void kmain(void)
{
setbgcolor(BLACK,FALSE);
loadIDT();
testf("Hello",10,20,30,40,50,60,70,80,90);
}
Code: Select all
msg=0x104FF4 ap=0x104ff8
33095686 @ 104FFC
I can't figure out what is wrong here, I hope someone here will be able to spot what I've done wrong, this has been bugging me for a while now.