Loading...
Searching...
No Matches
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
24#ifndef ARCHITECTURE_H
25#define ARCHITECTURE_H
26
27#include <stdint.h>
28#include <inttypes.h>
29#include <limits.h>
30
31#include "architecture_arch.h" /* IWYU pragma: export */
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
43#ifndef ARCHITECTURE_BREAKPOINT
44/* If no breakpoint instruction is defined, busy wait for debugger
45 * to attach and break to ease backtrace
46 */
47#define ARCHITECTURE_BREAKPOINT(value) do {} while (1)
48#endif
49
50/* Provide doxygen doc centrally, instead of in every architecture_arch.h */
51#ifdef DOXYGEN
57#define ARCHITECTURE_WORD_BITS <NUM>
63#define ARCHITECTURE_WORD_BYTES <ARCHITECTURE_WORD_BITS / 8>
70typedef uint<NUM>_t uword_t;
80typedef int<NUM>_t sword_t;
84#define SWORD_MAX <2^(ARCHITECTURE_WORD_BITS - 1) - 1>
88#define SWORD_MIN <-2^(ARCHITECTURE_WORD_BITS - 1)>
92#define UWORD_MAX <2^ARCHITECTURE_WORD_BITS - 1>
93
94/* end of ifdef DOXYGEN */
95#elif (ARCHITECTURE_WORD_BITS == 8)
96#define ARCHITECTURE_WORD_BYTES (1U)
97typedef uint8_t uword_t;
98typedef int8_t sword_t;
99#define SWORD_MAX (INT8_MAX)
100#define SWORD_MIN (INT8_MIN)
101#define UWORD_MAX (UINT8_MAX)
102#elif (ARCHITECTURE_WORD_BITS == 16)
103#define ARCHITECTURE_WORD_BYTES (2U)
104typedef uint16_t uword_t;
105typedef int16_t sword_t;
106#define SWORD_MAX (INT16_MAX)
107#define SWORD_MIN (INT16_MIN)
108#define UWORD_MAX (UINT16_MAX)
109#elif (ARCHITECTURE_WORD_BITS == 32)
110#define ARCHITECTURE_WORD_BYTES (4U)
111typedef uint32_t uword_t;
112typedef int32_t sword_t;
113#define SWORD_MAX (INT32_MAX)
114#define SWORD_MIN (INT32_MIN)
115#define UWORD_MAX (UINT32_MAX)
116#elif (ARCHITECTURE_WORD_BITS == 64)
117#define ARCHITECTURE_WORD_BYTES (8U)
118typedef uint64_t uword_t;
119typedef int64_t sword_t;
120#define SWORD_MAX (INT64_MAX)
121#define SWORD_MIN (INT64_MIN)
122#define UWORD_MAX (UINT64_MAX)
123#else
124#error "Unsupported word size (check ARCHITECTURE_WORD_BITS in architecture_arch.h)"
125#endif
126
130#define UWORD_MIN (0U)
131
132#if !defined(ARCHITECTURE_LARGE_TXT_PTR) || DOXYGEN
136typedef uintptr_t uinttxtptr_t;
137
141#define PRIxTXTPTR PRIxPTR
142#endif
143
144#if DOXYGEN
148#define PRI_SIZE_T_MODIFIER /* implementation defined */
149#elif (UINT_MAX == SIZE_MAX)
150#define PRI_SIZE_T_MODIFIER ""
151#elif (ULONG_MAX == SIZE_MAX)
152#define PRI_SIZE_T_MODIFIER "l"
153#else
154#error Unsupported size_t length
155#endif
156
161#define PRIdSIZE PRI_SIZE_T_MODIFIER "d"
169#define PRIiSIZE PRI_SIZE_T_MODIFIER "i"
174#define PRIoSIZE PRI_SIZE_T_MODIFIER "o"
179#define PRIuSIZE PRI_SIZE_T_MODIFIER "u"
187#define PRIxSIZE PRI_SIZE_T_MODIFIER "x"
195#define PRIXSIZE PRI_SIZE_T_MODIFIER "X"
196
206#define WORD_ALIGNED __attribute__((aligned(ARCHITECTURE_WORD_BYTES)))
207
218#define HAS_ALIGNMENT_OF(addr, alignment) (((uintptr_t)(addr) & ((alignment) - 1)) == 0)
219
226#define IS_WORD_ALIGNED(addr) HAS_ALIGNMENT_OF(addr, ARCHITECTURE_WORD_BYTES)
227
228#ifdef __cplusplus
229}
230#endif
231
232#endif /* ARCHITECTURE_H */
uint< NUM > _t uword_t
Word sized unsigned integer.
int< NUM > _t sword_t
Word sized signed integer.
uintptr_t uinttxtptr_t
Pointer type to point anywhere in the .text section.
Adds include for missing inttype definitions.