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 
30 #include "architecture_arch.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /* Provide doxygen doc centrally, instead of in every architecture_arch.h */
37 #ifdef DOXYGEN
43 #define ARCHITECTURE_WORD_BITS <NUM>
49 #define ARCHITECTURE_WORD_BYTES <NUM>
56 typedef uint<num>_t uword_t;
66 typedef int<num>_t sword_t;
67 #elif (ARCHITECTURE_WORD_BITS == 8)
68 #define ARCHITECTURE_WORD_BYTES (1U)
69 typedef uint8_t uword_t;
70 typedef int8_t sword_t;
71 #elif (ARCHITECTURE_WORD_BITS == 16)
72 #define ARCHITECTURE_WORD_BYTES (2U)
73 typedef uint16_t uword_t;
74 typedef int16_t sword_t;
75 #elif (ARCHITECTURE_WORD_BITS == 32)
76 #define ARCHITECTURE_WORD_BYTES (4U)
77 typedef uint32_t uword_t;
78 typedef int32_t sword_t;
79 #else
80 #error "Unsupported word size (check ARCHITECTURE_WORD_BITS in architecture_arch.h)"
81 #endif
82 
83 #if !defined(ARCHITECTURE_LARGE_TXT_PTR) || DOXYGEN
87 typedef uintptr_t uinttxtptr_t;
88 
92 #define PRIxTXTPTR PRIxPTR
93 #endif
94 
104 #define WORD_ALIGNED __attribute__((aligned(ARCHITECTURE_WORD_BYTES)))
105 
116 #define HAS_ALIGNMENT_OF(addr, alignment) (((uintptr_t)(addr) & ((alignment) - 1)) == 0)
117 
124 #define IS_WORD_ALIGNED(addr) HAS_ALIGNMENT_OF(addr, ARCHITECTURE_WORD_BYTES)
125 
129 #define UWORD_MIN 0
130 
134 #define UWORD_MAX ((1ULL << ARCHITECTURE_WORD_BITS) - 1)
135 
139 #define SWORD_MIN (-(1LL << (ARCHITECTURE_WORD_BITS - 1)))
140 
144 #define SWORD_MAX ((1LL << (ARCHITECTURE_WORD_BITS - 1)) - 1)
145 
146 #ifdef __cplusplus
147 }
148 #endif
149 
150 #endif /* ARCHITECTURE_H */
int< num > _t sword_t
Word sized signed integer.
Definition: architecture.h:66
uint< num > _t uword_t
Word sized unsigned integer.
Definition: architecture.h:56
uintptr_t uinttxtptr_t
Pointer type to point anywhere in the .text section.
Definition: architecture.h:87
Adds include for missing inttype definitions.