summaryrefslogtreecommitdiffstats
path: root/src/usr/pore/poreve/model/poreregister.H
blob: 21aa32985a7ec23338b14ee00c6601a7718a731e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*  IBM_PROLOG_BEGIN_TAG
 *  This is an automatically generated prolog.
 *
 *  $Source: src/usr/pore/poreve/model/poreregister.H $
 *
 *  IBM CONFIDENTIAL
 *
 *  COPYRIGHT International Business Machines Corp. 2012
 *
 *  p1
 *
 *  Object Code Only (OCO) source materials
 *  Licensed Internal Code Source Materials
 *  IBM HostBoot Licensed Internal Code
 *
 *  The source code for this program is not published or other-
 *  wise divested of its trade secrets, irrespective of what has
 *  been deposited with the U.S. Copyright Office.
 *
 *  Origin: 30
 *
 *  IBM_PROLOG_END_TAG
 */
#ifndef __VSBE_POREREGISTER_H
#define __VSBE_POREREGISTER_H

// $Id: poreregister.H,v 1.3 2012/06/15 12:34:39 bcbrock Exp $

/// \file poreregister.H
/// \brief The PoreRegister and PoreRegisterWritable classes
///
/// This header also includes selected register layout definitions

#include <stdint.h>

#include "poreconstants.H"

namespace vsbe {

    class PoreRegister;
    class PoreRegisterWritable;
    class PoreDataBuffer;
    class PoreInterface;
};


////////////////////////////////////////////////////////////////////////////
// PoreRegister
////////////////////////////////////////////////////////////////////////////

/// An abstract PORE programmer-visible register model
///
/// This class is introduced to provide abstract register models that are easy
/// to program for user code (e.g., hooks), by making the register appear to
/// be a data member of the PoreInterface, but leaving the implementation to
/// the underlying PoreModel.  This is necessary in part because there is not
/// always a direct map between the PORE hardware register and the
/// programmer-visible register (or abstract register like CIA).
///
/// Two types of register are supported here:
///
/// - True programmer-visible registers like D0, A0, P0, PC
/// - "Abstract" registers introduced to simplify hook programming like CIA
///
/// The register values manipulated by the PoreRegister associated with true
/// programmer visible registers are always the programmer-visible register
/// contents.  Reading the register always returns the value as if the
/// register were moved to a 64-bit data register inside the engine.  Writing
/// the register updates the underlying hardware model as if the register were
/// updated by a move from a 64-bit data register.
///
/// The PoreRegister defines a conversion operator to a uint64_t.  This allows
/// the register object to be used as if it were a uint64_t data member of the
/// PoreInterface. Note that for registers smaller than 64 bits the data will
/// be (for reads), or is expected to be (for writes), right justfied in the
/// 64 bit input or result.
///
/// When the PoreRegister instances are defined as data members of
/// PoreInterface, each instance is parameterized with the information
/// necessary to transform an access of the abstract register into the
/// register interface calls of the PoreModel. Note that in certain cases it
/// may not be possible to use the abstract register directly in an expression
/// because the usage is ambiguous to the compiler.  These problems can
/// be solved either by using temporary variables to disambiguate the usage,
/// or by explicitly using the read() methods of the PoreRegister
/// objects. 
///
/// All registers have read access and read() methods.  Most are actually
/// implemeted as the PoreRegisterWritable subclass that has write access and
/// a write method as well.

class 
vsbe::PoreRegister {

public:

    ////////////////////////////// Creators //////////////////////////////

    /// Create a PoreRegister
    ///
    /// \param[in] i_interface A pointer to the parent PoreInterface object that
    /// implements the underlying registerRead() and registerWrite() methods.
    ///
    /// \param[in] i_register A value from the enumeration
    /// PoreRegisterEncodingore identifying the register.
    PoreRegister(PoreInterface* i_interface, 
                 const PoreRegisterEncoding i_register);

    virtual ~PoreRegister();

    ///////////////////////////// Accessors //////////////////////////////

    /// Implement the PoreRegister register read
    ///
    /// Note that if the embedded call of PoreInterface::registerRead() fails
    /// it is considered a bug in the model.
    ///
    /// \retval value The current register value, right justified in the
    /// return value.
    virtual uint64_t read() const;

    /// Get the register value as a conversion (cast) using read().
    virtual operator uint64_t () const;


    ////////////////////////// Implementation ////////////////////////////

protected:

    /// The parent PoreInterface object
    PoreInterface* iv_interface;

    /// The PORE ISA encoding of register
    PoreRegisterEncoding iv_encoding;

    //////////////////////////    Safety      ////////////////////////////
    
private:

    PoreRegister(const PoreRegister& i_rhs);
    PoreRegister& operator=(PoreRegister& i_rhs);
};


////////////////////////////////////////////////////////////////////////////
// PoreRegisterWritable
////////////////////////////////////////////////////////////////////////////

/// A writable PoreRegister
///
/// This subclass extends the PoreRegister class by the addition of write
/// access and a write() method.

class 
vsbe::PoreRegisterWritable : public PoreRegister {

public:

    ////////////////////////////// Creators //////////////////////////////

    /// Create a PoreRegisterWritable
    ///
    /// \param[in] i_interface A pointer to the parent PoreInterface object that
    /// implements the underlying registerRead() and registerWrite() methods.
    ///
    /// \param[in] i_register A value from the enumeration
    /// PoreRegisterEncoding identifying the register.
    PoreRegisterWritable(PoreInterface* i_interface, 
                         const PoreRegisterEncoding i_register);

    virtual ~PoreRegisterWritable();


    //////////////////////////// Manipulators ////////////////////////////

    /// Implement the PoreRegister register write
    ///
    /// \param[in] i_data The data to be written to the register
    ///
    /// For registers smaller than 64 bits, the low-order bits of \a i_data
    /// are inserted into the hardware register.  Note that if the embedded
    /// call of PoreInterface::registerWritw() fails it is considered a bug in
    /// the model.
    ///
    /// \retval data This method returns its input \a data.
    virtual uint64_t write(const uint64_t i_data);

    /// Assign a value to a register using operator=().  See write().
    virtual uint64_t operator=(const uint64_t& i_data);


    //////////////////////////    Safety      ////////////////////////////
    
private:

    PoreRegisterWritable(const PoreRegisterWritable& i_rhs);
    PoreRegisterWritable& operator=(PoreRegisterWritable& i_rhs);
};


////////////////////////////////////////////////////////////////////////////
// PoreDataBuffer
////////////////////////////////////////////////////////////////////////////

/// A PoreRegister as an ecmdDataBuffer
///
/// This subclass extends the PoreRegisterWritable class by the addition of
/// selected methods of the ecmdDataBuffer, to provide a familiar and
/// convenient API for manipulating data in the PoreVe.  Only the 64-bit data
/// registers D0 and D1 are implemented using this class.  
///
/// Note that the eCmd-like methods are all implemented in functional form for
/// simplicty, and operate on uint64_t data values exclusively. There is no
/// error checking for bit positions, which are assumed to fall with the range
/// 0:63.

class 
vsbe::PoreDataBuffer : public PoreRegisterWritable {

public:

    ////////////////////////////// Creators //////////////////////////////

    /// Create a PoreDataBuffer
    ///
    /// \param[in] i_interface A pointer to the parent PoreInterface object that
    /// implements the underlying registerRead() and registerWrite() methods.
    ///
    /// \param[in] i_register A value from the enumeration
    /// PoreRegisterEncoding identifying the register.
    PoreDataBuffer(PoreInterface* i_interface,
                   const PoreRegisterEncoding i_register);

    virtual ~PoreDataBuffer();


    ////////////////////////////  Accessors   ////////////////////////////

    /// Return \a true if bit \a i_bit is set, otherwise \a false
    virtual bool isBitSet(const uint32_t i_bit);

    /// Return \a true if bit \a i_bit is clear, otherwise \a false
    virtual bool isBitClear(const uint32_t i_bit);

    /// Extract \a i_len bits from \a i_start and right justify into a uint64_t
    virtual uint64_t extractToRight(const uint32_t i_start,
                                    const uint32_t i_len);

    using PoreRegister::operator uint64_t;


    //////////////////////////// Manipulators ////////////////////////////

    /// Assign a value to a register using operator=().  See write().
    virtual uint64_t operator=(const uint64_t& i_data);

    /// Set bit \a i_bit and return the new 64-bit value
    virtual uint64_t setBit(const uint32_t i_bit);

    /// Clear bit \a i_bit and return the new 64-bit value
    virtual uint64_t clearBit(const uint32_t i_bit);

    /// Insert \a i_len low-order bits of \a i_data at \a i_start and return
    /// the new 64-bit value
    virtual uint64_t insertFromRight(const uint64_t i_data,
                                     const uint32_t i_start,
                                     const uint32_t i_len);


    //////////////////////////    Safety      ////////////////////////////
    
private:

    PoreDataBuffer(const PoreDataBuffer& i_rhs);
    PoreDataBuffer& operator=(PoreDataBuffer& i_rhs);
};


/// \bug These register layouts are defined in pore_model/ibuf/pore_regs.h,
/// however that header also includes a definition of a PoreAddress type that
/// conflicts with the type we define in PoreAddress.H.  If the conflict can
/// be removed from pore_regs.h then we can #include that file instead of
/// duplicating it here.

#include <endian.h>

typedef union {
        struct {
#if (__BYTE_ORDER == __BIG_ENDIAN)
                uint64_t i2c_engine_identifier : 4;
                uint64_t reserved0 : 1;
                uint64_t i2c_engine_address_range : 3;
                uint64_t reserved1 : 3;
                uint64_t i2c_engine_port : 5;
                uint64_t reserved2 : 1;
                uint64_t i2c_engine_device_id : 7;
                uint64_t reserved3 : 2;
                uint64_t i2c_engine_speed : 2;
                uint64_t i2c_done_max_polls : 4; /* I2C_E0_PARAM only */
                uint64_t reserved4 : 32;
#else
                uint64_t reserved4 : 32;
                uint64_t i2c_done_max_polls : 4; /* I2C_E0_PARAM only */
                uint64_t i2c_engine_speed : 2;
                uint64_t reserved3 : 2;
                uint64_t i2c_engine_device_id : 7;
                uint64_t reserved2 : 1;
                uint64_t i2c_engine_port : 5;
                uint64_t reserved1 : 3;
                uint64_t i2c_engine_address_range : 3;
                uint64_t reserved0 : 1;
                uint64_t i2c_engine_identifier : 4;
#endif
        };
        uint64_t val;
} pore_i2c_en_param_reg;


#endif  // __VSBE_POREREGISTER_H
OpenPOWER on IntegriCloud