summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/framework/register/prdfResetOperators.H
blob: bd4dc07af457e4d097601dda1518f7a087cb42d2 (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
320
321
322
323
324
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/framework/register/prdfResetOperators.H $ */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2005,2013              */
/*                                                                        */
/* 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 otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

/**
 * @file prdfResetOperators.H
 * Operator classes for enacting different reset and mask policies on a
 * register set.
 *
 * Defines RegisterResetOperator base class and a number of derived types.
 */

#ifndef __PRDFRESETOPERATORS_H
#define __PRDFRESETOPERATORS_H

#include <prdfBitKey.H>
#include <iipscr.h>
#include <iipconst.h>

namespace PRDF
{

/**
 * @class RegisterResetOperator
 * Interface class for reset operators.  (pure virtual)
 *
 * Provides a single interface, the reset "operator".  These operators are used
 * to enact specific reset or mask policies onto a register read/write pair.
 */
class RegisterResetOperator
{
    public:
        virtual ~RegisterResetOperator() { }  // zs01

        /**
         * Reset Operator
         *
         * @param bl : Bit list of registers to reset.
         * @param sdc : The current STEP_CODE information.
         * @param readReg : The ScanCOMM register to read bits from.
         * @param writeReg : The ScanCOMM register to update with reset/mask.
         */
        virtual
        int32_t Reset(const BIT_LIST_CLASS & bl,
                      STEP_CODE_DATA_STRUCT & sdc,
                      SCAN_COMM_REGISTER_CLASS * readReg,
                      SCAN_COMM_REGISTER_CLASS * writeReg) const = 0;
};

/**
 * @enum ResetOperatorBehaviors
 * Useful enum for defining operator templates which behave only slightly
 * different between masking and reseting.
 *
 * By using these enum types as parameters to the template (a bool) it makes
 * the template instantiation more understandable.
 */
enum ResetOperatorBehaviors
    {
        RESETOPERATOR_MASK = true,
        RESETOPERATOR_RESET = false
    };

/**
 * @fn getStaticResetOperator
 * Returns a pointer to a static reset operator of requested type.
 *
 * Example usage:
 *         getStaticResetOperator<OrOperator<RESETOPERATOR_MASK> >() will return
 *         a pointer to an Or-type operator which does masking (sets bits).
 */
template <class T>
T * getStaticResetOperator() { static T l_op; return &l_op; };

/**
 * @class OrOperator
 * Implements the 'or' behavior of a reset/mask operator.
 *
 * Template parameter determines if reset or mask.
 *
 * Behavior:
 *         Reset -
 *                 Read old bits.
 *                 Remove "reset" bits.
 *                 Write result.
 *         Mask -
 *                 Write "mask" bits.
 */
template <bool> class OrOperator;
// Typedefs for easier instantiation.
typedef OrOperator<RESETOPERATOR_MASK> OrMaskOperator;
typedef OrOperator<RESETOPERATOR_RESET> OrResetOperator;

// Class definition
template <bool Type>
class OrOperator : public RegisterResetOperator
{
    int32_t Reset(const BIT_LIST_CLASS & bl,
                      STEP_CODE_DATA_STRUCT & sdc,
                      SCAN_COMM_REGISTER_CLASS * readReg,
                      SCAN_COMM_REGISTER_CLASS * writeReg) const
    {
        int32_t rc = SUCCESS;

        uint32_t bl_length = bl.size();

        if(bl_length != 0) // Check for bits to reset
        {
            writeReg->clearAllBits();

            if (RESETOPERATOR_RESET == Type)
            {
                // Make sure this register was read.  (TODO: is this needed?)
                readReg->Read();

                if(readReg != writeReg)  // read different than write, move bits.
                {
                    writeReg->SetBitString(readReg->GetBitString());
                }
            }
            uint32_t i;
            for(i = 0; i < bl_length; ++i)  // Turn off all bits specified
            {
                if (RESETOPERATOR_MASK == Type)
                    writeReg->SetBit(bl.getListValue(i));
                else
                    writeReg->ClearBit(bl.getListValue(i));
            }
            rc = writeReg->Write();    // Write hardware
        }
        return rc;
    }
};

/**
 * @class AndOperator
 * Implements the 'and' behavior of a reset/mask operator.
 *
 * Template parameter determines if reset or mask.
 *
 * Behavior:
 *         Reset -
 *                Write not of bits.
 *         Mask -
 *                 Read mask register.
 *                 Set bits.
 *                 Write mask register.
 */
template <bool> class AndOperator;
// Typedefs for easier instantiation.
typedef AndOperator<RESETOPERATOR_MASK> AndMaskOperator;
typedef AndOperator<RESETOPERATOR_RESET> AndResetOperator;

// Class definition
template <bool Type>
class AndOperator : public RegisterResetOperator
{
    int32_t Reset(const BIT_LIST_CLASS & bl,
                      STEP_CODE_DATA_STRUCT & sdc,
                      SCAN_COMM_REGISTER_CLASS * readReg,
                      SCAN_COMM_REGISTER_CLASS * writeReg) const
    {
        int32_t rc = SUCCESS;
        uint32_t bl_length = bl.size();

        if (RESETOPERATOR_RESET == Type)
        {
            if(bl_length != 0) // Check for bits to reset
            {
                BIT_STRING_BUFFER_CLASS bs(writeReg->GetBitLength());
                bs.Pattern(0xffffffff, 32); // set all to 1's.

                uint32_t i;
                for(i = 0; i < bl_length; ++i)  // Turn off all bits specified
                {
                    bs.Clear(bl.getListValue(i));
                }
                writeReg->SetBitString(&bs); // Copy bit-string to register.
                rc = writeReg->Write();    // Write hardware
            }
        }
        else // RESETOPERATOR_MASK
        {
            // Make sure this register was read.  (TODO: is this needed?)
            readReg->Read();

            if(readReg != writeReg)  // read different than write, move bits.
            {
                writeReg->SetBitString(readReg->GetBitString());
            }
            for(uint32_t i = 0; i < bl_length; ++i)
            {
                writeReg->SetBit(bl.getListValue(i));
            }

            rc = writeReg->Write();
        }
        return rc;
    }
};


/**
 * @class XorOperator
 * Implements the 'xor' behavior of a reset/mask operator.
 *
 * Template parameter determines if reset or mask.
 *
 * Behavior:
 *         Reset - Write bit.
 *         Mask -  Clear bit.
 */
template <bool> class XorOperator;
// Typedefs for easier instantiation.
typedef XorOperator<RESETOPERATOR_MASK> XorMaskOperator;
typedef XorOperator<RESETOPERATOR_RESET> XorResetOperator;

// Class definition
template <bool Type>
class XorOperator : public RegisterResetOperator
{
    int32_t Reset(const BIT_LIST_CLASS & bl,
                      STEP_CODE_DATA_STRUCT & sdc,
                      SCAN_COMM_REGISTER_CLASS * readReg,
                      SCAN_COMM_REGISTER_CLASS * writeReg) const
    {
        int32_t rc = SUCCESS;
        uint32_t bl_length = bl.size();

        if (RESETOPERATOR_RESET == Type)
        {
            writeReg->clearAllBits();

            for (uint32_t i = 0; i < bl_length; ++i)
                writeReg->SetBit(bl.getListValue(i));

            rc = writeReg->Write();
        }
        else // RESETOPERATOR_MASK
        {
            // Make sure this register was read.  (TODO: is this needed?)
            readReg->Read();

            if(readReg != writeReg)  // read different than write, move bits.
            {
                writeReg->SetBitString(readReg->GetBitString());
            }
            for(uint32_t i = 0; i < bl_length; ++i)
            {
                writeReg->ClearBit(bl.getListValue(i));
            }

            rc = writeReg->Write();

        }
        return rc;
    }
};

/**
 * @class NotOperator
 * Implements the 'not' behavior of a reset/mask operator.
 *
 * Template parameter determines if reset or mask.
 *
 * Behavior:
 *         Reset - Clears all bits.
 *         Mask  - Sets all bits.
 */
template <bool> class NotOperator;
// Typedefs for easier instantiation.
typedef NotOperator<RESETOPERATOR_MASK> NotMaskOperator;
typedef NotOperator<RESETOPERATOR_RESET> NotResetOperator;

// Class definition
template <bool Type>
class NotOperator : public RegisterResetOperator
{
    int32_t Reset(const BIT_LIST_CLASS & bl,
                      STEP_CODE_DATA_STRUCT & sdc,
                      SCAN_COMM_REGISTER_CLASS * readReg,
                      SCAN_COMM_REGISTER_CLASS * writeReg) const
    {
        int32_t rc = SUCCESS;

        if (RESETOPERATOR_RESET == Type)
        {
            writeReg->clearAllBits();
            rc = writeReg->Write();    // Write hardware
        }
        else // RESETOPERATOR_MASK
        {
            BIT_STRING_BUFFER_CLASS bs(writeReg->GetBitLength());
            bs.Pattern(0xffffffff, 32); // set all to 1's.
            writeReg->SetBitString(&bs); // Copy bit-string to register.
            rc = writeReg->Write();    // Write hardware
        }
        return rc;
    }
};

} // end namespace PRDF

#endif

OpenPOWER on IntegriCloud