1 /**
2 * Copyright (c) 2019, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #ifndef AEEVALIST_H
31 #define AEEVALIST_H
32
33 #if !defined(__clang__) && (defined(__ARMCC_VERSION) || (defined(__GNUC__) && defined(__arm__)))
34
35
36
37 #if (defined(__ARMCC_VERSION) && __ARMCC_VERSION >= 200000 && !defined(__APCS_ADSABI)) || \
38 (defined(__GNUC__) && defined(__arm__) && defined(__ARM_EABI__))
39
40 # define __AEEVA_ATPCS 0
41
42 #else
43
44 # define __AEEVA_ATPCS 1
45
46 #endif
47
48 typedef void* AEEVaList;
49
50 #define __AEEVA_ARGALIGN(t) (((char*)(&((struct{char c;t x;}*)1)->x))-((char*)1))
51 #define __AEEVA_ARGSIZE(t) ((sizeof(t)+sizeof(int)-1) & ~(sizeof(int)-1))
52
__cpy(char * d,const char * s,int len)53 static __inline void __cpy(char*d, const char*s, int len)
54 {
55 while (len-- > 0) *d++ = *s++;
56 }
57
__AEEVa_Arg(AEEVaList args,void * pv,int nVSize,int nArgSize,int nArgAlign)58 static __inline AEEVaList __AEEVa_Arg(AEEVaList args, void* pv, int nVSize,
59 int nArgSize, int nArgAlign)
60 {
61 int nArgs = (int)args & ~1;
62 char* pcArgs = (char*)args;
63 int bATPCS = (int)args & 1;
64 int nArgsOffset = 0;
65 int nVOffset = 0;
66
67 if (!bATPCS) { /* caller was compiled with AAPCS */
68
69 if (nArgAlign > (int)sizeof(int)) {
70 nArgAlign--; /* make a mask */
71 pcArgs += ((nArgs + nArgAlign) & (int)~(unsigned)nArgAlign) - nArgs;
72 /* move pv to next alignment */
73 }
74 }
75
76 #if defined(AEE_BIGENDIAN)
77 if (nArgSize < (int)sizeof(int)) {
78 nArgsOffset = (int)sizeof(int) - nArgSize;
79 }
80 nVOffset = nVSize - nArgSize;
81 #else
82 (void)nVSize;
83 #endif /* AEE_BIGENDIAN */
84
85 __cpy((char*)pv + nVOffset, (pcArgs - bATPCS) + nArgsOffset, nArgSize);
86
87 /* round up */
88 nArgSize = (nArgSize+(int)sizeof(int)-1) & ~((int)sizeof(int)-1);
89
90 return pcArgs + nArgSize; /* increment va */
91 }
92
93 #define AEEVA_START(va,v) ((va) = (char*)&(v) + __AEEVA_ARGSIZE(v) + __AEEVA_ATPCS)
94 #define AEEVA_ARG(va,v,t) ((void)((va) = __AEEVa_Arg(va,&v,sizeof(v),sizeof(t),__AEEVA_ARGALIGN(t))))
95 #define AEEVA_END(va) ((va) = (AEEVaList)0)
96 #define AEEVA_COPY(dest, src) ((void)((dest) = (src)))
97
98 #else /* !defined(__clang__) && (defined(__ARMCC_VERSION) || (defined(__GNUC__) && defined(__arm__))) */
99
100 #include <stdarg.h>
101
102 typedef va_list AEEVaList;
103
104 #define AEEVA_START(va,v) (va_start((va), (v)))
105 #define AEEVA_ARG(va,v,t) ((v) = va_arg((va),t))
106 #define AEEVA_END(va) (va_end((va)))
107 #define AEEVA_COPY(dest, src) (va_copy((dest),(src)))
108
109 #endif/* !defined(__clang__) && (defined(__ARMCC_VERSION) || (defined(__GNUC__) && defined(__arm__))) */
110
111 #endif /* #ifndef AEEVALIST_H */
112
113