summaryrefslogtreecommitdiff
path: root/gcc_arm/ginclude/va-d10v.h
blob: 8fca15de5289f9385c4cd0493a4ab93e4b7993d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* GNU C stdarg/varargs support for the D10V */

/* Define __gnuc_va_list.  */
#ifndef __GNUC_VA_LIST
#define __GNUC_VA_LIST
typedef struct __va_list_tag {
  short *__va_reg_base;		/* start of the register save area */
  short __va_reg_num;		/* argument number */
  char *__va_stack;
} __va_list[1], __gnuc_va_list[1];

#endif /* not __GNUC_VA_LIST */

/* If this is for internal libc use, don't define anything but
   __gnuc_va_list.  */
#if defined (_STDARG_H) || defined (_VARARGS_H)

/* Common code for va_start for both varargs and stdarg.  This depends
   on the format of the CUMULATIVE_ARGS type.  On the d10v, we use just
   a single word that is the argument number.  */

#define __va_start_common(AP)						\
__extension__ ({							\
   (AP)->__va_reg_base = (short *) __builtin_saveregs ();		\
   (AP)->__va_reg_num = __builtin_args_info (0);			\
   (AP)->__va_stack							\
     = (char *)((AP)->__va_reg_base + __builtin_args_info (1));		\
   (void)0;								\
})

#ifdef _STDARG_H /* stdarg.h support */

/* Calling __builtin_next_arg gives the proper error message if LASTARG is
   not indeed the last argument.  */
#define va_start(AP,LASTARG) \
  (__builtin_next_arg (LASTARG), __va_start_common (AP))

#else /* varargs.h support */

#define va_start(AP) __va_start_common (AP)
#define va_alist __builtin_va_alist
#define va_dcl register int va_alist; ...

#endif /* _STDARG_H */

/* Nothing needs to be done to end varargs/stdarg processing */
#define va_end(AP) ((void)0)

#define va_arg(AP,TYPE)							\
__extension__ (*({							\
  register TYPE *__ptr;							\
									\
  int __va_reg_now = (AP)->__va_reg_num, __va_reg_new;			\
									\
  if (sizeof (TYPE) >= 4 && (__va_reg_now & 1) != 0)			\
    __va_reg_now++;							\
  __va_reg_new = __va_reg_now + (sizeof (TYPE) + 1) / 2;		\
  if (__va_reg_new <= 4)						\
    {									\
      (AP)->__va_reg_num = __va_reg_new;				\
      __ptr = (TYPE *)(((char *)(void *)				\
			((AP)->__va_reg_base + __va_reg_now))		\
		       + (sizeof (TYPE) < 2));				\
    }									\
  else									\
    {									\
      /* ??? According to PARM_BOUNDARY, there should be no extra	\
	 alignment here - but there is, see testcase execute/va-arg-6.c.\
	 That seems to be a backend bug */				\
      if (sizeof (TYPE) >= 4						\
	  && (((AP)->__va_stack - (char *)(AP)->__va_reg_base) & 2) != 0)\
									\
	(AP)->__va_stack += 2;						\
      __ptr = (TYPE *)((AP)->__va_stack	+ (sizeof (TYPE) < 2));		\
      (AP)->__va_stack += (sizeof (TYPE) + 1) & ~1;			\
    }									\
									\
  __ptr;								\
}))

#endif /* defined (_STDARG_H) || defined (_VARARGS_H) */