2 * Copyright (c) 2014-2015 ARM Limited
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * Authors: Andreas Sandberg
20 #ifndef _LIBNOMALIMODEL_TYPES_HH
21 #define _LIBNOMALIMODEL_TYPES_HH
33 * @name Register handling utilities
37 * Register address wrapper
39 * This class wraps a register address. Unlike a simple typedef, this
40 * provides safety from automatic type conversions from other integer
41 * types since the constructor must be called explicitly.
44 explicit RegAddr(uint32_t v)
51 operator<(const RegAddr &lhs, const RegAddr &rhs) {
52 return lhs.value < rhs.value;
56 operator>(const RegAddr &lhs, const RegAddr &rhs) {
57 return lhs.value > rhs.value;
61 operator<=(const RegAddr &lhs, const RegAddr &rhs) {
62 return lhs.value <= rhs.value;
66 operator>=(const RegAddr &lhs, const RegAddr &rhs) {
67 return lhs.value >= rhs.value;
71 operator==(const RegAddr &lhs, const RegAddr &rhs) {
72 return lhs.value == rhs.value;
76 operator!=(const RegAddr &lhs, const RegAddr &rhs) {
77 return lhs.value != rhs.value;
81 operator+(const RegAddr &lhs, const RegAddr &rhs) {
82 return RegAddr(lhs.value + rhs.value);
86 operator-(const RegAddr &lhs, const RegAddr &rhs) {
88 return RegAddr(lhs.value - rhs.value);
92 * Class for register storage
94 * This class wraps a std::vector and implements a subset of its
95 * functionality. Specifically, it is constant size and prevents
96 * indexing with anything other than RegAddr instances.
101 typedef std::vector<uint32_t> vector_t;
104 typedef vector_t::iterator iterator;
105 typedef vector_t::const_iterator const_iterator;
106 typedef vector_t::size_type size_type;
109 RegVector(size_type size)
114 * Helper function to get a 64-bit register.
116 * @param addr Address to the low part of the register.
117 * @return 64-bit value representing the concatenation of the HI
118 * and LO parts of the register.
120 const uint32_t get64(const RegAddr &addr) const {
121 const unsigned idx_lo = index(addr);
122 const unsigned idx_hi = idx_lo + 1;
123 return (((uint64_t)vector[idx_hi]) << 32) | vector[idx_lo];
127 * Helper function to set a 64-bit register.
129 * @param addr Address to the low part of the register.
130 * @param value Value to write into the 64-bit register.
132 void set64(const RegAddr &addr, uint64_t value) {
133 const unsigned idx_lo = index(addr);
134 const unsigned idx_hi = idx_lo + 1;
135 vector[idx_lo] = value & 0xFFFFFFFF;
136 vector[idx_hi] = (value >> 32) & 0xFFFFFFFF;
139 const uint32_t &operator[](const RegAddr &addr) const {
140 return vector[index(addr)];
143 uint32_t &operator[](const RegAddr &addr) {
144 return vector[index(addr)];
148 iterator begin() noexcept { return vector.begin(); }
149 const_iterator begin() const noexcept { return vector.begin(); }
150 const_iterator cbegin() const noexcept { return vector.cbegin(); }
152 iterator end() noexcept { return vector.end(); }
153 const_iterator end() const noexcept { return vector.end(); }
154 const_iterator cend() const noexcept { return vector.cend(); }
156 const size_type size() const noexcept { return vector.size(); }
159 // Disable default constructor
162 static uint32_t index(const RegAddr &addr) {
163 assert((addr.value & 0x3) == 0);
164 return addr.value >> 2;
173 * Class representing the status codes in the Midgard architecture.
177 * Class representing the subsystem a status code originates from.
186 typedef uint8_t Code;
187 typedef uint8_t SubCode;
189 Status(StatusClass cls, Code code, SubCode subcode)
190 : value((cls << 6) | (code << 3) | subcode) {
191 assert((cls & ~0x3) == 0);
192 assert((code & ~0x7) == 0);
193 assert((subcode & ~0x7) == 0);
196 explicit Status(uint8_t v)
199 StatusClass statusClass() const {
200 return (StatusClass)((value >> 6) & 0x3);
204 return (value >> 3) & 0x7;
207 SubCode subCode() const {