architecture.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Otto-von-Guericke-Universität Magdeburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
9 #pragma once
10 
26 #include <stdint.h>
27 #include <inttypes.h>
28 #include <limits.h>
29 
30 #include "architecture_arch.h" /* IWYU pragma: export */
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
42 #ifndef ARCHITECTURE_BREAKPOINT
43 /* If no breakpoint instruction is defined, busy wait for debugger
44  * to attach and break to ease backtrace
45  */
46 #define ARCHITECTURE_BREAKPOINT(value) do {} while (1)
47 #endif
48 
49 /* Provide doxygen doc centrally, instead of in every architecture_arch.h */
50 #ifdef DOXYGEN
56 #define ARCHITECTURE_WORD_BITS <NUM>
62 #define ARCHITECTURE_WORD_BYTES <ARCHITECTURE_WORD_BITS / 8>
69 typedef uint<NUM>_t uword_t;
79 typedef int<NUM>_t sword_t;
83 #define SWORD_MAX <2^(ARCHITECTURE_WORD_BITS - 1) - 1>
87 #define SWORD_MIN <-2^(ARCHITECTURE_WORD_BITS - 1)>
91 #define UWORD_MAX <2^ARCHITECTURE_WORD_BITS - 1>
92 
93 /* end of ifdef DOXYGEN */
94 #elif (ARCHITECTURE_WORD_BITS == 8)
95 #define ARCHITECTURE_WORD_BYTES (1U)
96 typedef uint8_t uword_t;
97 typedef int8_t sword_t;
98 #define SWORD_MAX (INT8_MAX)
99 #define SWORD_MIN (INT8_MIN)
100 #define UWORD_MAX (UINT8_MAX)
101 #elif (ARCHITECTURE_WORD_BITS == 16)
102 #define ARCHITECTURE_WORD_BYTES (2U)
103 typedef uint16_t uword_t;
104 typedef int16_t sword_t;
105 #define SWORD_MAX (INT16_MAX)
106 #define SWORD_MIN (INT16_MIN)
107 #define UWORD_MAX (UINT16_MAX)
108 #elif (ARCHITECTURE_WORD_BITS == 32)
109 #define ARCHITECTURE_WORD_BYTES (4U)
110 typedef uint32_t uword_t;
111 typedef int32_t sword_t;
112 #define SWORD_MAX (INT32_MAX)
113 #define SWORD_MIN (INT32_MIN)
114 #define UWORD_MAX (UINT32_MAX)
115 #elif (ARCHITECTURE_WORD_BITS == 64)
116 #define ARCHITECTURE_WORD_BYTES (8U)
117 typedef uint64_t uword_t;
118 typedef int64_t sword_t;
119 #define SWORD_MAX (INT64_MAX)
120 #define SWORD_MIN (INT64_MIN)
121 #define UWORD_MAX (UINT64_MAX)
122 #else
123 #error "Unsupported word size (check ARCHITECTURE_WORD_BITS in architecture_arch.h)"
124 #endif
125 
129 #define UWORD_MIN (0U)
130 
131 #if !defined(ARCHITECTURE_LARGE_TXT_PTR) || DOXYGEN
135 typedef uintptr_t uinttxtptr_t;
136 
140 #define PRIxTXTPTR PRIxPTR
141 #endif
142 
143 #if DOXYGEN
147 #define PRI_SIZE_T_MODIFIER /* implementation defined */
148 #elif (UINT_MAX == SIZE_MAX)
149 #define PRI_SIZE_T_MODIFIER ""
150 #elif (ULONG_MAX == SIZE_MAX)
151 #define PRI_SIZE_T_MODIFIER "l"
152 #else
153 #error Unsupported size_t length
154 #endif
155 
160 #define PRIdSIZE PRI_SIZE_T_MODIFIER "d"
168 #define PRIiSIZE PRI_SIZE_T_MODIFIER "i"
173 #define PRIoSIZE PRI_SIZE_T_MODIFIER "o"
178 #define PRIuSIZE PRI_SIZE_T_MODIFIER "u"
186 #define PRIxSIZE PRI_SIZE_T_MODIFIER "x"
194 #define PRIXSIZE PRI_SIZE_T_MODIFIER "X"
195 
205 #define WORD_ALIGNED __attribute__((aligned(ARCHITECTURE_WORD_BYTES)))
206 
217 #define HAS_ALIGNMENT_OF(addr, alignment) (((uintptr_t)(addr) & ((alignment) - 1)) == 0)
218 
225 #define IS_WORD_ALIGNED(addr) HAS_ALIGNMENT_OF(addr, ARCHITECTURE_WORD_BYTES)
226 
227 #ifdef __cplusplus
228 }
229 #endif
230 
uint< NUM > _t uword_t
Word sized unsigned integer.
Definition: architecture.h:69
int< NUM > _t sword_t
Word sized signed integer.
Definition: architecture.h:79
uintptr_t uinttxtptr_t
Pointer type to point anywhere in the .text section.
Definition: architecture.h:135
Adds include for missing inttype definitions.