architecture.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2020 Otto-von-Guericke-Universität Magdeburg
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
23 #include <stdint.h>
24 #include <inttypes.h>
25 #include <limits.h>
26 
27 #include "architecture_arch.h" /* IWYU pragma: export */
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
39 #ifndef ARCHITECTURE_BREAKPOINT
40 /* If no breakpoint instruction is defined, busy wait for debugger
41  * to attach and break to ease backtrace
42  */
43 #define ARCHITECTURE_BREAKPOINT(value) do {} while (1)
44 #endif
45 
46 /* Provide doxygen doc centrally, instead of in every architecture_arch.h */
47 #ifdef DOXYGEN
53 #define ARCHITECTURE_WORD_BITS <NUM>
59 #define ARCHITECTURE_WORD_BYTES <ARCHITECTURE_WORD_BITS / 8>
66 typedef uint<NUM>_t uword_t;
76 typedef int<NUM>_t sword_t;
80 #define SWORD_MAX <2^(ARCHITECTURE_WORD_BITS - 1) - 1>
84 #define SWORD_MIN <-2^(ARCHITECTURE_WORD_BITS - 1)>
88 #define UWORD_MAX <2^ARCHITECTURE_WORD_BITS - 1>
89 
90 /* end of ifdef DOXYGEN */
91 #elif (ARCHITECTURE_WORD_BITS == 8)
92 #define ARCHITECTURE_WORD_BYTES (1U)
93 typedef uint8_t uword_t;
94 typedef int8_t sword_t;
95 #define SWORD_MAX (INT8_MAX)
96 #define SWORD_MIN (INT8_MIN)
97 #define UWORD_MAX (UINT8_MAX)
98 #elif (ARCHITECTURE_WORD_BITS == 16)
99 #define ARCHITECTURE_WORD_BYTES (2U)
100 typedef uint16_t uword_t;
101 typedef int16_t sword_t;
102 #define SWORD_MAX (INT16_MAX)
103 #define SWORD_MIN (INT16_MIN)
104 #define UWORD_MAX (UINT16_MAX)
105 #elif (ARCHITECTURE_WORD_BITS == 32)
106 #define ARCHITECTURE_WORD_BYTES (4U)
107 typedef uint32_t uword_t;
108 typedef int32_t sword_t;
109 #define SWORD_MAX (INT32_MAX)
110 #define SWORD_MIN (INT32_MIN)
111 #define UWORD_MAX (UINT32_MAX)
112 #elif (ARCHITECTURE_WORD_BITS == 64)
113 #define ARCHITECTURE_WORD_BYTES (8U)
114 typedef uint64_t uword_t;
115 typedef int64_t sword_t;
116 #define SWORD_MAX (INT64_MAX)
117 #define SWORD_MIN (INT64_MIN)
118 #define UWORD_MAX (UINT64_MAX)
119 #else
120 #error "Unsupported word size (check ARCHITECTURE_WORD_BITS in architecture_arch.h)"
121 #endif
122 
126 #define UWORD_MIN (0U)
127 
128 #if !defined(ARCHITECTURE_LARGE_TXT_PTR) || DOXYGEN
132 typedef uintptr_t uinttxtptr_t;
133 
137 #define PRIxTXTPTR PRIxPTR
138 #endif
139 
140 #if DOXYGEN
144 #define PRI_SIZE_T_MODIFIER /* implementation defined */
145 #elif (UINT_MAX == SIZE_MAX)
146 #define PRI_SIZE_T_MODIFIER ""
147 #elif (ULONG_MAX == SIZE_MAX)
148 #define PRI_SIZE_T_MODIFIER "l"
149 #else
150 #error Unsupported size_t length
151 #endif
152 
157 #define PRIdSIZE PRI_SIZE_T_MODIFIER "d"
165 #define PRIiSIZE PRI_SIZE_T_MODIFIER "i"
170 #define PRIoSIZE PRI_SIZE_T_MODIFIER "o"
175 #define PRIuSIZE PRI_SIZE_T_MODIFIER "u"
183 #define PRIxSIZE PRI_SIZE_T_MODIFIER "x"
191 #define PRIXSIZE PRI_SIZE_T_MODIFIER "X"
192 
202 #define WORD_ALIGNED __attribute__((aligned(ARCHITECTURE_WORD_BYTES)))
203 
214 #define HAS_ALIGNMENT_OF(addr, alignment) (((uintptr_t)(addr) & ((alignment) - 1)) == 0)
215 
222 #define IS_WORD_ALIGNED(addr) HAS_ALIGNMENT_OF(addr, ARCHITECTURE_WORD_BYTES)
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 
uint< NUM > _t uword_t
Word sized unsigned integer.
Definition: architecture.h:66
int< NUM > _t sword_t
Word sized signed integer.
Definition: architecture.h:76
uintptr_t uinttxtptr_t
Pointer type to point anywhere in the .text section.
Definition: architecture.h:132
Adds include for missing inttype definitions.