Add Freescale Nexus decoder implementation
[babeltrace.git] / converter / nexus / SizedAddress.h
1 /*
2 * Copyright (C) 2013 Freescale Semiconductor, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
21 */
22
23 #ifndef SIZEDADDRESS_H
24 #define SIZEDADDRESS_H
25
26 #include <inttypes.h>
27 #include <string>
28
29 using std::string;
30
31 /*!
32 Class to handle 32 or 64bit (sized) Address data
33 */
34 class SizedAddress
35 {
36 public:
37 /*!
38 @Constructor
39 */
40 SizedAddress() :
41 valid_(false), pc64_(false), pc_hi_(0), pc_lo_(0)
42 {
43 }
44 virtual ~SizedAddress()
45 {
46 }
47
48 // Default copy and assignment operators are OK
49
50 // Comparison operation
51 bool operator==(const SizedAddress &rhs) const;
52 bool operator!=(const SizedAddress &rhs) const;
53
54 // XOR compound operation
55 SizedAddress& operator^=(const SizedAddress &rhs);
56
57 // XOR operation
58 const SizedAddress operator^(const SizedAddress &rhs);
59
60 /*!
61 @Returns the validity of the address value
62 @return true if the value is valid
63 */
64 bool isValid() const
65 {
66 return valid_;
67 }
68 /*!
69 @Returns the address value
70 @return the address value
71 */
72 uint32_t address32() const
73 {
74 return pc_lo_;
75 }
76
77 /*!
78 @Returns the address value
79 @return the address value
80 */
81 uint64_t address64() const
82 {
83 return ((uint64_t) pc_hi_ << 32) | (uint64_t) pc_lo_;
84 }
85
86 /*!
87 @Returns the upper 32bits of the address
88 @return the upper 32bits of the address
89 */
90 uint32_t upper32() const
91 {
92 return pc_hi_;
93 }
94
95 /*!
96 @Returns the lower 32bits of the address
97 @return the lower 32bits of the address
98 */
99 uint32_t lower32() const
100 {
101 return pc_lo_;
102 }
103
104 /*!
105 @Tests if the address is 64 bit wide
106 @return if the address is 64 bits wide
107 */
108 bool is64bits() const
109 {
110 return pc64_;
111 }
112
113 /*!
114 @abstract Return the Address as a string
115 @return a string representing the Nexus Address
116 */
117 string asString() const;
118
119 /*!
120 @Sets the upper 32bits of the address
121 */
122 void upper32(uint32_t val)
123 {
124 pc_hi_ = val;
125 pc64_ = true;
126 valid_ = true;
127 }
128
129 /*!
130 @Sets the lower 32bits of the address
131 */
132 void lower32(uint32_t val)
133 {
134 pc_lo_ = val;
135 valid_ = true;
136 }
137
138 private:
139
140 /*! @var valid_ true if represents an initialized value */
141 bool valid_;
142
143 /*! @var pc64_ determines if the received address is 64bits wide */
144 bool pc64_;
145
146 /*! @var pc_hi_ the upper 32bits of the Nexus address */
147 uint32_t pc_hi_;
148
149 /*! @var pc_lo_ the lower 32bits of the Nexus address */
150 uint32_t pc_lo_;
151 };
152
153 #endif // SIZEDADDRESS_H
This page took 0.033317 seconds and 4 git commands to generate.