summaryrefslogtreecommitdiffstats
path: root/src/usr/pore/poreve/model/poreregister.C
blob: 7be840b4c93d9579cd860b0f1334a2b702751769 (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
//  IBM_PROLOG_BEGIN_TAG
//  This is an automatically generated prolog.
//
//  $Source: src/usr/pore/poreve/model/poreregister.C $
//
//  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
// $Id: poreregister.C,v 1.5 2011/08/03 17:59:00 bcbrock Exp $

/// \file poreregister.C
/// \brief The PoreRegister and PoreRegisterWritable classes

#include "poreinterface.H"

using namespace vsbe;


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

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

PoreRegister::PoreRegister(PoreInterface* i_interface, 
                           const PoreRegisterEncoding i_encoding) :
    iv_interface(i_interface),
    iv_encoding(i_encoding)
{
}


PoreRegister::~PoreRegister()
{
}


uint64_t 
PoreRegister::read() const
{
    uint64_t data;
    ModelError me;
    PoreRegisterOffset offset = PORE_REGISTER_MAP[iv_encoding];

    switch (iv_encoding) {

    case PORE_D0:
    case PORE_D1:
    case PORE_A0:
    case PORE_A1:
    case PORE_EMR:
    case PORE_ETR:
    case PORE_IFR:

        // These are read as 64-bit registers in the model

        me = iv_interface->registerRead(offset, data);
        break;

    case PORE_P0:
    case PORE_P1:
    case PORE_CTR:
    case PORE_SPRG0:

        // These registers are <= 32 bits and stored right-justified in the
        // high-order 32 bits of the 64-bit registers.  In every case the
        // hardware specification specifies that unused bits on the left read
        // as 0.

        me = iv_interface->registerRead(offset, data);
        data >>= 32;
        break;

    case PORE_PC:

        // The PC is read as the low-order 48 bits of the status register.

        me = iv_interface->registerRead(offset, data);
        data &= 0xffffffffffffull;
        break;

    case PORE_CIA:

        // The CIA is obtained from the high-order 48 bits of the DBG1
        // register. 

        me = iv_interface->registerRead(offset, data);
        data >>= 16;
        break;

    default:
        me = ME_BUG;
        break;
    }
    if (me != 0) {
        iv_interface->modelError(me);
    }
    return data;
}


PoreRegister::operator uint64_t () const
{
    return read();
}


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

PoreRegisterWritable::
PoreRegisterWritable(PoreInterface* i_interface, 
                     const PoreRegisterEncoding i_encoding) :
    PoreRegister(i_interface, i_encoding)
{
}


PoreRegisterWritable::~PoreRegisterWritable()
{
}


uint64_t    
PoreRegisterWritable::write(const uint64_t i_data)
{
    ModelError me;
    PoreRegisterOffset offset = PORE_REGISTER_MAP[iv_encoding];

    switch (iv_encoding) {

    case PORE_D0:
    case PORE_D1:

        // These are written as 64-bit registers in the model

        me = iv_interface->registerWrite(offset, i_data);
        break;

    case PORE_A0:
    case PORE_A1:

        // The programmer-writable portion of A0 and A1 are the low-order
        // 46 bits.

        me = iv_interface->registerWrite(offset, i_data & 0x3fffffffffffull);
        break;

    case PORE_P0:
    case PORE_P1:

        // The programmer-visible portion is bits 25:31, the remainder is
        // undefined.

        me = iv_interface->registerWrite(offset, (i_data & 0x7f) << 32);
        break;

    case PORE_CTR:

        // The programmer-visible portion is bits 8:31, the remainder is
        // undefined. 

        me = iv_interface->registerWrite(offset, (i_data & 0xffffff) << 32);
        break;

    case PORE_EMR:

        // The programmer-visible portion is bits 0:20

        me = iv_interface->registerWrite(offset,
                                         i_data & 0xfffff80000000000ull);
        break;

    case PORE_SPRG0:

        // These register moves the low-order 32 bits of the data to the
        // high-order bits of the target.

        me = iv_interface->registerWrite(offset, (i_data & 0xffffffff) << 32);
        break;

    case PORE_IFR:

        // Only bits 48:55 of the IFR (the ALU flags) are writable.

        me = iv_interface->registerWrite(offset, i_data & 0xff00ull);
        break;

    case PORE_ETR:

        // Only the low-order 32 bits are writable
        
        me = iv_interface->registerWrite(PORE_EXE_TRIGGER_HI, i_data, 4);
        break;

    default:
        me = ME_BUG;
        break;
    }
    if (me != 0) {
        iv_interface->modelError(me);
    }
    return i_data;
}


uint64_t 
PoreRegisterWritable::operator=(const uint64_t& i_data)
{
    return write(i_data);
}


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

PoreDataBuffer::PoreDataBuffer(PoreInterface* i_interface, 
                               const PoreRegisterEncoding i_encoding) :
    PoreRegisterWritable(i_interface, i_encoding)
{
}


PoreDataBuffer::~PoreDataBuffer()
{
}


bool
PoreDataBuffer::isBitSet(const uint32_t i_bit)
{
    return (read() & BE64_BIT(i_bit)) != 0;
}


bool
PoreDataBuffer::isBitClear(const uint32_t i_bit)
{
    return (read() & BE64_BIT(i_bit)) == 0;
}


uint64_t 
PoreDataBuffer::extractToRight(const uint32_t i_start,
                               const uint32_t i_len)
{
    return BE64_GET_FIELD(read(), i_start, (i_start + i_len - 1));
}


// This needs to be replicated here for obscure C++ reasons
uint64_t 
PoreDataBuffer::operator=(const uint64_t& i_data)
{
    return write(i_data);
}


uint64_t 
PoreDataBuffer::setBit(const uint32_t i_bit)
{
    return write(read() | BE64_BIT(i_bit));
}


uint64_t 
PoreDataBuffer::clearBit(const uint32_t i_bit)
{
    return write(read() & ~BE64_BIT(i_bit));
}
    
uint64_t 
PoreDataBuffer::insertFromRight(const uint64_t i_data,
                                const uint32_t i_start,
                                const uint32_t i_len)
{
    return write(BE64_SET_FIELD(read(), i_start, (i_start + i_len - 1), 
                                i_data));
}
OpenPOWER on IntegriCloud