summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/framework/rule/prdrLoadChip.C
blob: dd76a62345328a53f52be87b7fd22e1b3080dbb7 (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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/framework/rule/prdrLoadChip.C $      */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2004,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 otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#include <string.h>                // for memcmp
#include <prdrCommon.H>

#include <prdrLoadChip.H>
#include <errlentry.H>
#include <utilstream.H>
#include <UtilFunct.H>

#include <prdf_service_codes.H>
#include <prdfThresholdResolutions.H>
#include <iipglobl.h>
#include <UtilHash.H> // for Util::hashString

#include <algorithm> // for std::generate_n

namespace Prdr
{

void prdrReadExpr(UtilStream & i_stream, PrdrExpr & o_expr);

// NOTE: caller must call delete[] to release the buffer
void prdrReadString(UtilStream & i_stream, char *& o_string)
{
    char  l_pBuf[100];
    memset(l_pBuf,'\0',100);
    char* l_pCursor = l_pBuf;

    char l_tmp;

    do
    {
        i_stream >> l_tmp;
        if ('\0' != l_tmp)
        {
            *l_pCursor = l_tmp;
            l_pCursor++;
        }
    } while ('\0' != l_tmp);

    o_string = new char[strlen(l_pBuf) + 1];
    strcpy(o_string, l_pBuf);
}

/**
 * @brief read bit string data out from the stream
 */
void prdrReadBitString(UtilStream & i_stream, std::vector<uint64_t> & o_vector)
{
    uint64_t l_tmp64;
    uint8_t l_tmp8;
    i_stream >> l_tmp8;

    int length = (l_tmp8 / 8) + ((l_tmp8 % 8) != 0 ? 1 : 0);

    for (int i = 0; i < (length/8); i++)
    {
        i_stream >> l_tmp64;
        o_vector.push_back(l_tmp64);
    }
}

errlHndl_t prdrLoadChip(UtilStream & i_stream, PrdrChip & o_chip)
{
    errlHndl_t l_errl = NULL;

    do
    {
        char l_temp[8];

        // read header.
        i_stream >> l_temp;
        if (0 != memcmp(l_temp, "PRDRCHIP", 8))
        {
            PRDF_ERR("prdrLoadChip() bad chip file - l_temp: %s ", l_temp);
            // Bad chip file.
            /*@
             * @errortype
             * @refcode         LIC_REFCODE
             * @subsys                 EPUB_FIRMWARE_SP
             * @reasoncode         PRDF_CODE_FAIL
             *
             * @moduleid           PRDF_PRDRLOADCHIP
             * @userdata1          0x50524452 ("PRDR")
             * @userdata2          0x43484950 ("CHIP")
             * @devdesc                Attempted to load chip rule file that lacked
             *                         the proper header "PRDRCHIP".
             */
            PRDF_CREATE_ERRL(l_errl,
                             ERRL_SEV_UNRECOVERABLE,
                             ERRL_ETYPE_NOT_APPLICABLE,
                             SRCI_ERR_INFO,
                             SRCI_NO_ATTR,
                             PRDF_PRDRLOADCHIP,
                             LIC_REFCODE,
                             PRDF_CODE_FAIL,
                             0x50524452, // PRDR
                             0x43484950, // CHIP
                             0, 0);
            break;
        }

        // read chip info.
        i_stream >> o_chip.cv_chipId;
        i_stream >> o_chip.cv_targetType;
        i_stream >> o_chip.cv_signatureOffset;
        i_stream >> o_chip.cv_dumpType;        //@ecdf
        i_stream >> o_chip.cv_scomLen;

        // read registers.
        i_stream >> o_chip.cv_regCount;

        if (o_chip.cv_regCount != 0)
        {
            o_chip.cv_registers = new PrdrRegister[o_chip.cv_regCount];
            for (uint32_t i = 0; i < o_chip.cv_regCount; i++)
            {
                i_stream >> o_chip.cv_registers[i].cv_name;
                i_stream >> o_chip.cv_registers[i].cv_flags;
                i_stream >> o_chip.cv_registers[i].cv_scomAddr;

                if (o_chip.cv_registers[i].cv_flags &
                        Prdr::PRDR_REGISTER_SCOMLEN)
                {
                    i_stream >> o_chip.cv_registers[i].cv_scomLen;
                }
                else
                {
                    o_chip.cv_registers[i].cv_scomLen = o_chip.cv_scomLen;
                }

                if (o_chip.cv_registers[i].cv_flags &
                        Prdr::PRDR_REGISTER_RESETS)
                {
                    // Read 'n' from stream.  Read that many reset structs out
                    // of the stream, insert into cv_resets for register.
                    std::generate_n(
                            std::back_inserter(
                                o_chip.cv_registers[i].cv_resets
                                ),
                            Util::unary_input<uint16_t, UtilStream>(i_stream)(),
                            Util::unary_input<PrdrRegister::ResetOrMaskStruct,
                                              UtilStream> (i_stream)
                            );

                }

                if (o_chip.cv_registers[i].cv_flags &
                        Prdr::PRDR_REGISTER_MASKS)
                {
                    // Read 'n' from stream.  Read that many mask structs out
                    // of the stream, insert into cv_masks for register.
                    std::generate_n(
                            std::back_inserter(
                                o_chip.cv_registers[i].cv_masks
                                ),
                            Util::unary_input<uint16_t, UtilStream>(i_stream)(),
                            Util::unary_input<PrdrRegister::ResetOrMaskStruct,
                                              UtilStream> (i_stream)
                            );

                }

                if (o_chip.cv_registers[i].cv_flags &
                        Prdr::PRDR_REGISTER_CAPTURE)
                {
                    // Read 'n' from stream.  Read that many mask structs out
                    // of the stream, insert into cv_masks for register.
                    std::generate_n(
                            std::back_inserter(
                                o_chip.cv_registers[i].cv_captures
                                ),
                            Util::unary_input<uint16_t, UtilStream>(i_stream)(),
                            Util::unary_input<PrdrRegister::CaptureInfoStruct,
                                              UtilStream> (i_stream)
                            );
                }
            }
        }

        // read rules.
        i_stream >> o_chip.cv_ruleCount;
        if (o_chip.cv_ruleCount != 0)
        {
            o_chip.cv_rules = new PrdrExpr[o_chip.cv_ruleCount];
            for (uint32_t i = 0; i < o_chip.cv_ruleCount; i++)
            {
                i_stream >> l_temp[0]; // should be 'R'
                prdrReadExpr(i_stream, o_chip.cv_rules[i]);
            }
        }

        // read groups.
        i_stream >> o_chip.cv_groupCount;
        for (int i = 0; i < NUM_GROUP_ATTN; i++) // @jl02 JL Added this enum type for the number of Attention types.
            i_stream >> o_chip.cv_groupAttn[i];
        if (o_chip.cv_groupCount != 0)
        {
            o_chip.cv_groups = new PrdrExpr * [o_chip.cv_groupCount];
            o_chip.cv_groupSize = new uint16_t[o_chip.cv_groupCount];
            o_chip.cv_groupFlags = new uint8_t[o_chip.cv_groupCount];
            o_chip.cv_groupPriorityBits = new PrdrExpr * [o_chip.cv_groupCount];
            for (uint32_t i = 0; i < o_chip.cv_groupCount; i++)
            {
                i_stream >> l_temp[0]; // should be 'G'
                i_stream >> o_chip.cv_groupSize[i];
                i_stream >> o_chip.cv_groupFlags[i];
                if (Prdr::PRDR_GROUP_FILTER_PRIORITY & o_chip.cv_groupFlags[i])
                {
                    o_chip.cv_groupPriorityBits[i] = new PrdrExpr();
                    prdrReadExpr(i_stream, *o_chip.cv_groupPriorityBits[i]);
                }
                else
                {
                    o_chip.cv_groupPriorityBits[i] = NULL;
                }
                if (0 != o_chip.cv_groupSize[i])
                {
                    o_chip.cv_groups[i] = new PrdrExpr[o_chip.cv_groupSize[i]];
                    for (uint32_t j = 0; j < o_chip.cv_groupSize[i]; j++)
                    {
                        prdrReadExpr(i_stream, o_chip.cv_groups[i][j]);
                        if (Prdr::REF_RULE == o_chip.cv_groups[i][j].cv_op)
                        {
                            for (int k = 1; k <= 2; k++)
                            {
                                o_chip.cv_groups[i][j].cv_value[k].p =
                                        new PrdrExpr();
                                o_chip.cv_groups[i][j].cv_deletePtr[k] = true;

                                prdrReadExpr(i_stream,
                                        *o_chip.cv_groups[i][j].cv_value[k].p);
                            }
                        }
                    }
                }
                else
                {
                    o_chip.cv_groups[i] = new PrdrExpr[0]; /*accessing beyond memory*/
                                                          // False error BEAM.
                };
            }
        }

        // read actions.
        i_stream >> o_chip.cv_actionCount;
        if (o_chip.cv_actionCount != 0)
        {
            o_chip.cv_actions = new PrdrExpr * [o_chip.cv_actionCount];
            o_chip.cv_actionSize = new uint16_t[o_chip.cv_actionCount];
            for (uint32_t i = 0; i < o_chip.cv_actionCount; i++)
            {
                i_stream >> l_temp[0]; // should be 'A'
                i_stream >> o_chip.cv_actionSize[i];
                if (0 != o_chip.cv_actionSize[i])
                {
                    o_chip.cv_actions[i] =
                            new PrdrExpr[o_chip.cv_actionSize[i]];
                    for (uint32_t j = 0; j < o_chip.cv_actionSize[i]; j++)
                    {
                        prdrReadExpr(i_stream, o_chip.cv_actions[i][j]);
                    }
                }
                else //@pw01
                {
                    o_chip.cv_actions[i] = NULL;
                }
            }
        }

    } while (false);

    if (NULL == l_errl)
        l_errl = i_stream.getLastError();

    return l_errl;
}

void prdrReadExpr(UtilStream & i_stream, PrdrExpr & o_expr)
{
    unsigned char l_tmpChar;
    uint32_t l_tmp32;
    uint16_t l_tmp16;
    uint8_t l_tmp8;
    bool l_tmpBool;

    i_stream >> o_expr.cv_op;

    switch(o_expr.cv_op)
    {
        case Prdr::AND:
        case Prdr::OR:
        case Prdr::XOR:
        case Prdr::LSHIFT:
        case Prdr::RSHIFT:
        case Prdr::ACT_TRY:
            o_expr.cv_value[0].p = new PrdrExpr();
            o_expr.cv_deletePtr[0] = true;
            prdrReadExpr(i_stream, *o_expr.cv_value[0].p);

            o_expr.cv_value[1].p = new PrdrExpr();
            o_expr.cv_deletePtr[1] = true;
            prdrReadExpr(i_stream, *o_expr.cv_value[1].p);
            break;

        case Prdr::NOT:
            o_expr.cv_value[0].p = new PrdrExpr();
            o_expr.cv_deletePtr[0] = true;
            prdrReadExpr(i_stream, *o_expr.cv_value[0].p);
            break;

        case Prdr::INTEGER:
        case Prdr::ACT_GARD:
        case Prdr::ACT_FLAG:
            i_stream >> o_expr.cv_value[0].i;
            break;

        case Prdr::REF_RULE:
        case Prdr::REF_REG:
        case Prdr::REF_GRP:
        case Prdr::REF_ACT:
        case Prdr::INT_SHORT:
            i_stream >> l_tmp16;
            o_expr.cv_value[0].i = l_tmp16;
            break;

        case Prdr::BIT_STR:
            o_expr.cv_bitStrVect.clear();
            prdrReadBitString(i_stream, o_expr.cv_bitStrVect);
            break;

        case Prdr::ACT_THRES:
            o_expr.cv_value[0].i = ThresholdResolution::cv_fieldDefault.interval;
            o_expr.cv_value[1].i = ThresholdResolution::cv_fieldDefault.threshold;
            o_expr.cv_value[2].i = ThresholdResolution::cv_mnfgDefault.interval;
            o_expr.cv_value[3].i = ThresholdResolution::cv_mnfgDefault.threshold;
            //The syntax of thresholds in rule file is
            // op field_threshold field_intervale
            //optional fields (mnfg_threshold, mnfg_interval } | mnfg_ilr_threshold | maskid
            i_stream >> l_tmpChar;
            l_tmpBool = (0x40 == (0x40 & l_tmpChar));
            l_tmpChar &= (~0x40);
            o_expr.cv_value[4].i = (0x20 == (0x20 & l_tmpChar));
            l_tmpChar &= (~0x20);
            // The values which different parameter will have
            // cv_value[0,1] error frequency and time in sec for field threshold
            //cv_value[4] true if mnfg threshols needs to be picked up from mnfg file, false otherwise
            // cv_value [2, 3]: error frequency and time in sec for mnfg threshold if cv_value[4] is false
            // otherwise cv_value[3] tells which threshold needs to pick up from mnfg file
            // cv_value[5] maski id if shared threshold
            if (0 != l_tmpChar)
                for (uint8_t i = 0; i < l_tmpChar; i++)
                {
                    if ( (1 != i) || (0 == o_expr.cv_value[4].i) )
                    {
                        //entry has errorFrequency
                        i_stream >> l_tmp8;
                        o_expr.cv_value[2*i].i = l_tmp8;
                    }
                    i_stream >> o_expr.cv_value[2*i + 1].i;
                }
            if (l_tmpBool)
                i_stream >> o_expr.cv_value[5];
            break;

        case Prdr::ACT_ANALY:
            i_stream >> o_expr.cv_value[0].i;
            i_stream >> o_expr.cv_value[1].i;
            break;

        case Prdr::ACT_FUNC:
            o_expr.cv_actFunc = NULL;
            prdrReadString(i_stream, o_expr.cv_actFunc);

            i_stream >> o_expr.cv_value[1].i;
            break;

        case Prdr::ACT_CALL:
            i_stream >> l_tmpChar;
            o_expr.cv_value[0].i = l_tmpChar;
            i_stream >> o_expr.cv_value[1].i;
            if ('s' != o_expr.cv_value[0].i)
            {
                i_stream >> o_expr.cv_value[2].i;
                i_stream >> o_expr.cv_value[3].i;

                // Read ALT bool.
                i_stream >> l_tmpChar;
                if (0 != l_tmpChar)
                {
                    o_expr.cv_value[4].p = new PrdrExpr();
                    o_expr.cv_deletePtr[4] = true;
                    prdrReadExpr(i_stream, *o_expr.cv_value[4].p);
                }
                else
                    o_expr.cv_value[4].p = NULL;
            }
            break;

        case Prdr::ACT_DUMP: //@ecdf
            i_stream >> o_expr.cv_value[0].i;
            break;

        case Prdr::ATTNLINK:
            i_stream >> l_tmpChar; // get count
            l_tmp32 = l_tmpChar;
            for (size_t i = 0; i < l_tmp32; i++)
            {
                i_stream >> l_tmpChar; // get index
                o_expr.cv_value[l_tmpChar].p = new PrdrExpr();
                o_expr.cv_deletePtr[l_tmpChar] = true;
                prdrReadExpr(i_stream, *o_expr.cv_value[l_tmpChar].p);
            }
            break;

        case Prdr::ACT_CAPT:
            i_stream >> o_expr.cv_value[0].i;

        default:
            break;
    }
}

PrdrRegister::PrdrRegister() : cv_name(0)
{}

PrdrRegister::~PrdrRegister()
{
    for(std::vector<CaptureInfoStruct>::iterator
        j = cv_captures.begin();
        j != cv_captures.end();
        ++j)
    {
        if (NULL != (*j).func)
        {
            delete[] (*j).func;
            (*j).func = NULL;
        }
    }
}

PrdrExpr::PrdrExpr()
{
    cv_op = 0;
    cv_actFunc = NULL;
    // Clear out the pointers and 'delete' settings.
    for (uint32_t i = 0; i < MAX_VALUES; i++)
    {
        cv_deletePtr[i] = false;
        cv_value[i].p = NULL;
    }
}

PrdrExpr::~PrdrExpr()
{
    // Special things for certain operator types...
    switch (cv_op)
    {
        // On function call operator and bit string,
        // cv_value[0].p points to a string.
        case Prdr::ACT_FUNC:
            if(NULL != cv_actFunc)
            {
                delete[] cv_actFunc;
                cv_actFunc = NULL;
            }
            break;
        case Prdr::BIT_STR:
            cv_bitStrVect.clear();
            break;

        // No other special cases yet.
        default:
            break;
    }

    // Delete all pointers.
    for (uint32_t i = 0; i < MAX_VALUES; i++)
        if (cv_deletePtr[i])
            delete (cv_value[i].p);
};

} // end namespace.
OpenPOWER on IntegriCloud