xref: /openbmc/qemu/include/user/abitypes.h (revision ee48fef0)
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 #ifdef TARGET_CRIS
25 #define ABI_SHORT_ALIGNMENT 1
26 #define ABI_INT_ALIGNMENT 1
27 #define ABI_LONG_ALIGNMENT 1
28 #define ABI_LLONG_ALIGNMENT 1
29 #endif
30 
31 #if (defined(TARGET_I386) && !defined(TARGET_X86_64)) \
32     || defined(TARGET_SH4) \
33     || defined(TARGET_OPENRISC) \
34     || defined(TARGET_MICROBLAZE)
35 #define ABI_LLONG_ALIGNMENT 4
36 #endif
37 
38 #ifndef ABI_SHORT_ALIGNMENT
39 #define ABI_SHORT_ALIGNMENT 2
40 #endif
41 #ifndef ABI_INT_ALIGNMENT
42 #define ABI_INT_ALIGNMENT 4
43 #endif
44 #ifndef ABI_LONG_ALIGNMENT
45 #define ABI_LONG_ALIGNMENT (TARGET_ABI_BITS / 8)
46 #endif
47 #ifndef ABI_LLONG_ALIGNMENT
48 #define ABI_LLONG_ALIGNMENT 8
49 #endif
50 
51 typedef int16_t abi_short __attribute__ ((aligned(ABI_SHORT_ALIGNMENT)));
52 typedef uint16_t abi_ushort __attribute__((aligned(ABI_SHORT_ALIGNMENT)));
53 typedef int32_t abi_int __attribute__((aligned(ABI_INT_ALIGNMENT)));
54 typedef uint32_t abi_uint __attribute__((aligned(ABI_INT_ALIGNMENT)));
55 typedef int64_t abi_llong __attribute__((aligned(ABI_LLONG_ALIGNMENT)));
56 typedef uint64_t abi_ullong __attribute__((aligned(ABI_LLONG_ALIGNMENT)));
57 
58 #ifdef TARGET_ABI32
59 typedef uint32_t abi_ulong __attribute__((aligned(ABI_LONG_ALIGNMENT)));
60 typedef int32_t abi_long __attribute__((aligned(ABI_LONG_ALIGNMENT)));
61 #define TARGET_ABI_FMT_lx "%08x"
62 #define TARGET_ABI_FMT_ld "%d"
63 #define TARGET_ABI_FMT_lu "%u"
64 
65 static inline abi_ulong tswapal(abi_ulong v)
66 {
67     return tswap32(v);
68 }
69 
70 #else
71 typedef target_ulong abi_ulong __attribute__((aligned(ABI_LONG_ALIGNMENT)));
72 typedef target_long abi_long __attribute__((aligned(ABI_LONG_ALIGNMENT)));
73 #define TARGET_ABI_FMT_lx TARGET_FMT_lx
74 #define TARGET_ABI_FMT_ld TARGET_FMT_ld
75 #define TARGET_ABI_FMT_lu TARGET_FMT_lu
76 /* for consistency, define ABI32 too */
77 #if TARGET_ABI_BITS == 32
78 #define TARGET_ABI32 1
79 #endif
80 
81 static inline abi_ulong tswapal(abi_ulong v)
82 {
83     return tswapl(v);
84 }
85 
86 #endif
87 #endif
88