blob: e28dc6663a67b670536057c490724d7c7c24b481 [file] [log] [blame]
Peter Maydell878a7352014-02-05 17:27:27 +00001// Copyright 2013, ARM Limited
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are met:
6//
7// * Redistributions of source code must retain the above copyright notice,
8// this list of conditions and the following disclaimer.
9// * Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12// * Neither the name of ARM Limited nor the names of its contributors may be
13// used to endorse or promote products derived from this software without
14// specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
17// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27#ifndef VIXL_GLOBALS_H
28#define VIXL_GLOBALS_H
29
Peter Maydell09319b32014-05-13 16:09:35 +010030// Get standard C99 macros for integer types.
31#ifndef __STDC_CONSTANT_MACROS
32#define __STDC_CONSTANT_MACROS
33#endif
34
35#ifndef __STDC_LIMIT_MACROS
36#define __STDC_LIMIT_MACROS
37#endif
38
39#ifndef __STDC_FORMAT_MACROS
Peter Maydell878a7352014-02-05 17:27:27 +000040#define __STDC_FORMAT_MACROS
Peter Maydell09319b32014-05-13 16:09:35 +010041#endif
42
43#include <stdint.h>
Peter Maydell878a7352014-02-05 17:27:27 +000044#include <inttypes.h>
45
46#include <assert.h>
47#include <stdarg.h>
48#include <stdio.h>
49#include <stdint.h>
50#include <stdlib.h>
51#include <stddef.h>
52#include "platform.h"
53
54
55typedef uint8_t byte;
56
57const int KBytes = 1024;
58const int MBytes = 1024 * KBytes;
Peter Maydell878a7352014-02-05 17:27:27 +000059
Peter Maydell09319b32014-05-13 16:09:35 +010060#define VIXL_ABORT() printf("in %s, line %i", __FILE__, __LINE__); abort()
Peter Maydell878a7352014-02-05 17:27:27 +000061#ifdef DEBUG
Peter Maydell09319b32014-05-13 16:09:35 +010062 #define VIXL_ASSERT(condition) assert(condition)
63 #define VIXL_CHECK(condition) VIXL_ASSERT(condition)
64 #define VIXL_UNIMPLEMENTED() printf("UNIMPLEMENTED\t"); VIXL_ABORT()
65 #define VIXL_UNREACHABLE() printf("UNREACHABLE\t"); VIXL_ABORT()
Peter Maydell878a7352014-02-05 17:27:27 +000066#else
Peter Maydell09319b32014-05-13 16:09:35 +010067 #define VIXL_ASSERT(condition) ((void) 0)
68 #define VIXL_CHECK(condition) assert(condition)
69 #define VIXL_UNIMPLEMENTED() ((void) 0)
70 #define VIXL_UNREACHABLE() ((void) 0)
Peter Maydell878a7352014-02-05 17:27:27 +000071#endif
Peter Maydell09319b32014-05-13 16:09:35 +010072// This is not as powerful as template based assertions, but it is simple.
73// It assumes that the descriptions are unique. If this starts being a problem,
74// we can switch to a different implemention.
75#define VIXL_CONCAT(a, b) a##b
76#define VIXL_STATIC_ASSERT_LINE(line, condition) \
77 typedef char VIXL_CONCAT(STATIC_ASSERT_LINE_, line)[(condition) ? 1 : -1] \
78 __attribute__((unused))
79#define VIXL_STATIC_ASSERT(condition) VIXL_STATIC_ASSERT_LINE(__LINE__, condition) //NOLINT
Peter Maydell878a7352014-02-05 17:27:27 +000080
81template <typename T> inline void USE(T) {}
82
Peter Maydell09319b32014-05-13 16:09:35 +010083#define VIXL_ALIGNMENT_EXCEPTION() printf("ALIGNMENT EXCEPTION\t"); VIXL_ABORT()
Peter Maydell878a7352014-02-05 17:27:27 +000084
85#endif // VIXL_GLOBALS_H