xref: /openbmc/qemu/include/user/abitypes.h (revision d0f0cd5b)
1 #ifndef USER_ABITYPES_H
2 #define USER_ABITYPES_H
3 
4 #ifndef CONFIG_USER_ONLY
5 #error Cannot include this header from system emulation
6 #endif
7 
8 #include "exec/cpu-defs.h"
9 #include "exec/tswap.h"
10 #include "user/tswap-target.h"
11 
12 #ifdef TARGET_ABI32
13 #define TARGET_ABI_BITS 32
14 #else
15 #define TARGET_ABI_BITS TARGET_LONG_BITS
16 #endif
17 
18 #ifdef TARGET_M68K
19 #define ABI_INT_ALIGNMENT 2
20 #define ABI_LONG_ALIGNMENT 2
21 #define ABI_LLONG_ALIGNMENT 2
22 #endif
23 
24 #if (defined(TARGET_I386) && !defined(TARGET_X86_64)) \
25     || defined(TARGET_SH4) \
26     || defined(TARGET_OPENRISC) \
27     || defined(TARGET_MICROBLAZE)
28 #define ABI_LLONG_ALIGNMENT 4
29 #endif
30 
31 #ifndef ABI_SHORT_ALIGNMENT
32 #define ABI_SHORT_ALIGNMENT 2
33 #endif
34 #ifndef ABI_INT_ALIGNMENT
35 #define ABI_INT_ALIGNMENT 4
36 #endif
37 #ifndef ABI_LONG_ALIGNMENT
38 #define ABI_LONG_ALIGNMENT (TARGET_ABI_BITS / 8)
39 #endif
40 #ifndef ABI_LLONG_ALIGNMENT
41 #define ABI_LLONG_ALIGNMENT 8
42 #endif
43 
44 typedef int16_t abi_short __attribute__ ((aligned(ABI_SHORT_ALIGNMENT)));
45 typedef uint16_t abi_ushort __attribute__((aligned(ABI_SHORT_ALIGNMENT)));
46 typedef int32_t abi_int __attribute__((aligned(ABI_INT_ALIGNMENT)));
47 typedef uint32_t abi_uint __attribute__((aligned(ABI_INT_ALIGNMENT)));
48 typedef int64_t abi_llong __attribute__((aligned(ABI_LLONG_ALIGNMENT)));
49 typedef uint64_t abi_ullong __attribute__((aligned(ABI_LLONG_ALIGNMENT)));
50 
51 #ifdef TARGET_ABI32
52 typedef uint32_t abi_ulong __attribute__((aligned(ABI_LONG_ALIGNMENT)));
53 typedef int32_t abi_long __attribute__((aligned(ABI_LONG_ALIGNMENT)));
54 #define TARGET_ABI_FMT_lx "%08x"
55 #define TARGET_ABI_FMT_ld "%d"
56 #define TARGET_ABI_FMT_lu "%u"
57 
58 static inline abi_ulong tswapal(abi_ulong v)
59 {
60     return tswap32(v);
61 }
62 
63 #else
64 typedef target_ulong abi_ulong __attribute__((aligned(ABI_LONG_ALIGNMENT)));
65 typedef target_long abi_long __attribute__((aligned(ABI_LONG_ALIGNMENT)));
66 #define TARGET_ABI_FMT_lx TARGET_FMT_lx
67 #define TARGET_ABI_FMT_ld TARGET_FMT_ld
68 #define TARGET_ABI_FMT_lu TARGET_FMT_lu
69 /* for consistency, define ABI32 too */
70 #if TARGET_ABI_BITS == 32
71 #define TARGET_ABI32 1
72 #endif
73 
74 static inline abi_ulong tswapal(abi_ulong v)
75 {
76     return tswapl(v);
77 }
78 
79 #endif
80 #endif
81