summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/ifcompiler/initScom.H
blob: cd556c239656d99baa620f4b62e3d5e3bf37cf39 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/ifcompiler/initScom.H $                          */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2010,2014              */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#if !defined(INITSPY_H)
#define INITSPY_H

// Change Log *************************************************************************************
//
//  Flag Track     Userid   Date     Description
//  ----- -------- -------- -------- -------------------------------------------------------------
//         D754106 dgilbert 06/14/10 Create
//  dg002 SW039868 dgilbert 10/15/10 Add support to filter unneeded inits by EC
//  dg003 SW047506 dgilbert 12/09/10 More filtering enhancements
//                 andrewg  05/24/11 Port over for VPL/PgP
//                 andrewg  09/19/11 Updates based on review
//                 mjjones  11/17/11 Output attribute listing
//                 camvanng 12/12/11 Support multiple address ranges within a SCOM address
//                                   Use strtoull vs strtoul for 32-bit platforms
//                 camvanng 12/15/11 Support for multiple duplicate addresses setting different bits
//                 camvanng 01/20/12 Support for using a range of indexes for array attributes
//                 camvanng 02/14/12 Support binary and hex scom addresses
//                 camvanng 04/16/12 Support defines for SCOM address
//                                   Support defines for bits, scom_data and attribute columns
//                                   Delete obsolete code for defines support 
//                 camvanng 06/27/12 Improve error and debug tracing
// End Change Log *********************************************************************************

/**
 * @file initSpy.H
 * @brief Declairation of the initSpy Class. Represents the information parsed from an initfile spy
 *        statement.
 */

#include <stdint.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <initRpn.H>
#include <initSymbols.H>


using namespace std;

namespace init
{
    typedef vector<string> SCOM_ADDR;
    typedef vector<Rpn> RPN_LIST;
    typedef vector<RPN_LIST> COL_LIST;
    typedef vector<uint32_t> VAR_LIST;
    typedef pair<uint32_t,uint32_t> RANGE;
    typedef vector<RANGE> RANGE_LIST;

    enum SCOM_WHEN
    {
        NONE                = 0x00000000,

        // WHEN= types
        LONG_SCAN           = 0x00000001,
        SCOM                = 0x00000002,
        DRAMINIT            = 0x00000003,
        CFAMINIT            = 0x00000004,
        LAST_WHEN_TYPE      = CFAMINIT,
        WHEN_MASK           = 0x000000FF,

        // WHEN= sub types
        SUBTYPE_MASK        = 0x0000F000,
        HOT_ADD_NODE        = 0x00004000,
        AFTER_HOT_ADD_NODE  = 0x00006000,
        HOT_ADD_GX          = 0x00008000,
        HOT_ADD_GX0         = 0x00007000,
        HOT_ADD_GX1         = 0x00005000,
        AFTER_HOT_ADD_GX    = 0x0000A000,
        AFTER_HOT_ADD_GX0   = 0x00003000,
        AFTER_HOT_ADD_GX1   = 0x00002000,
    };

    const char when_char[] = { '@','L','S','D','C' };

    class Scom
    {
        public:

            enum SPY_TYPE
            {
                NOTYPE,
                ISPY,
                ESPY,
                ARRAY
            };


            Scom(Symbols * i_symbols,uint32_t i_line = 0) :
                iv_symbols(i_symbols),
                iv_line(i_line),
                iv_scom_length(0),
                iv_scom_offset(0),
                iv_when(NONE)        {}

            // Build from binary sequence
            Scom(BINSEQ::const_iterator & bli, Symbols * i_symbols);

            bool compare(Scom & that);
            uint32_t get_when(void)              { return(iv_when); }
            void set_when(SCOM_WHEN i_when)              { iv_when |= (uint32_t)i_when; }
            void set_when(const string * when_str);
            bool do_when(SCOM_WHEN i_when)      { return ((uint32_t)i_when == (WHEN_MASK & iv_when)); }
            void set_sub_when(SCOM_WHEN i_when)          { iv_when |= i_when; }
            void set_when_rpn(const Rpn * i_rpn)        { iv_when_rpn = *i_rpn; delete i_rpn; }
            uint32_t get_line() { return iv_line; }
            void add_scom_rpn(const Rpn * i_rpn)        { iv_scom_rpn.push_back(*i_rpn); delete i_rpn; }



            /**
             * Is when statement valid for this spy
             * @param stats: ostream to print debug information
             * @param ec restriction - true if valid for this ec, 0xffffffff means ANY ec
             * @return false if Rpn for when statement resolves to false, otherwise true
             */
            bool valid_when(ostream & stats, uint32_t i_ec = 0xffffffff);

            void add_col(const string & i_colname);

            /**
             * Add a row rpn to the current column
             * @param pointer to Rpn object
             * @pre add_col()
             */
            void add_row_rpn(Rpn * i_rpn);

            void add_bit_range(uint32_t start, uint32_t end);
            void add_target_range(uint32_t r1, uint32_t r2);
            void make_target(const char * i_symbol);


            uint64_t get_address(void) {return(strtoull(iv_scom_addr[0].c_str(),NULL,16));}

            /**
             * @brief Get the SCOM address
             * @return iv_scom_addr_hex  the SCOM address
             */
            uint64_t get_address_hex(void) {return iv_scom_addr_hex;}

            /**
             * @brief Get the bit offset to start writing the SCOM data
             * @return iv_scom_offset  the starting bit within the SCOM to write the data
             */
            uint32_t get_scom_offset(void) {return iv_scom_offset;}

            /**
             * @brief Get the total number of bits to write
             * @return iv_scom_length  the number of bits to write
             */
            uint32_t get_scom_length(void) {return iv_scom_length;}

            // string name();
            string listing();

            /**
             * Append binary listing of this Spy
             * @param when [init::LONG_SCAN | init::SCOM]
             * @param BINSEQ binary listing to append
             * @returns uint32_t number of spies added
             */
            uint32_t bin_listing(BINSEQ & blist);

            void set_scom_address(const string & i_scom_addr);
            void dup_scom_address(const string & i_scom_addr);
            void copy_dup_scom_address();
            void set_scom_suffix(const string & i_scom_addr);

            /**
             * @brief Set the binary SCOM address
             * @param i_scom_addr  binary address string
             */
            void set_scom_address_bin(const string & i_scom_addr);
            
            /**
             * @brief Create duplicate binary SCOM addresses and append input address string
             * @param i_scom_addr  binary address string
             */
            void dup_scom_address_bin(const string & i_scom_addr);

            /**
             * @brief Copy duplicate binary SCOM addresses to main binary address vector
             */
            void copy_dup_scom_address_bin();

            /**
             * @brief Append the input binary address string to the binary address
             * @param i_scom_addr  binary address string
             */
            void set_scom_suffix_bin(const string & i_scom_addr);

            /**
             * @brief Append the binary address to the hex address
             */
            void append_scom_address_bin();

            /**
             * @brief Convert decimal to hex string
             * @param i_num  decimal number
             * @param i_str_size   string size
             */
            string dec2hexString(uint64_t i_num, size_t i_str_size);

            /**
             * @brief Convert decimal to bin string
             * @param i_num  decimal number
             * @param i_str_size   string size
             */
            string dec2binString(uint64_t i_num, size_t i_str_size);

            /**
             * @brief Return scom address strings
             */
            string addr_listing();

        private:  // functions

            string list_one(RANGE range);
            void bin_list_one(BINSEQ & blist,uint64_t i_addr, uint32_t i_addr_num, RANGE range);

            /**
             * Optimize the row RPNs
             * @note Remove any rows that resolve to unconditionally false.
             */
            void row_optimize();

        private:  // data

          typedef map<string,SCOM_WHEN> WHEN_SUBTYPE_MAP;

            SCOM_ADDR   iv_scom_addr;
            SCOM_ADDR   iv_dup_scom_addr;      ///< contains the duplicate scom addresses
            uint64_t    iv_scom_addr_hex;
            SCOM_ADDR   iv_scom_addr_bin;      ///< temp storage for binary scom addresses
            SCOM_ADDR   iv_dup_scom_addr_bin;  ///< contains the duplicate binary scom addresses
            uint32_t    iv_scom_length;
            uint32_t    iv_scom_offset;
            RPN_LIST    iv_scom_rpn;            ///< spyv - for each row
            RPN_LIST    iv_col_vars;            ///< RPNs of column name for each column
            COL_LIST    iv_cols_rpn;            ///< A list of row rpn segments one rpn list for each column
            RPN_LIST    iv_row_rpn;             ///< row rpns for current column being parsed.
            RANGE_LIST  iv_range_list;          ///< bit range list
            RANGE_LIST  iv_target_ranges;       ///< target range for current target begin parsed.
            Symbols   * iv_symbols;
            uint32_t    iv_line;                ///< line # in the initfile
            uint32_t    iv_when;
            Rpn         iv_when_rpn;


            static WHEN_SUBTYPE_MAP  cv_when_subtypes;

    };


    //=================================================================================================
    //  SpyList Class declarations
    //=================================================================================================
    // Container to track scoms
    typedef multimap<uint64_t, init::Scom *> SCOM_LIST;

    class ScomList
    {
        public:
            ScomList(const string & initfile, FILELIST & defines, ostream & stats, uint32_t i_ec = 0xFFFFFFFF);
            ~ScomList();
            //size_t size() { return iv_spy_list.size(); }
            //SPY_LIST::iterator begin() { return iv_spy_list.begin(); }
            //SPY_LIST::iterator end() { return iv_spy_list.end(); }
            void clear();
            void insert(Scom * i_scom);

            void compile(BINSEQ & bin_seq);

            void listing(BINSEQ & bin_seq, ostream & out);
            void attr_listing(BINSEQ & bin_seq, ostream & out);

            /**
             * Compare two spylists for equivalance
             * @returns true if equal
             * @note Both spylists should have been built from a binary sequence
             *    not directly from an initfile
             */
            bool compare(ScomList & that);



            void set_cvs_versions(const string * s) { iv_cvs_versions = *s; }
            void set_syntax_version(uint32_t v);
            size_t get_syntax_version() { return iv_syntax_version; }

            Symbols * get_symbols() { return iv_symbols; }

        private: // functions

            string fmt8(uint32_t val);

        private:

              SCOM_LIST iv_scom_list;
              string iv_cvs_versions;
              uint32_t iv_syntax_version;
              Symbols * iv_symbols;
              ostream & iv_stats;
              uint32_t iv_ec;
    };
};
#endif
OpenPOWER on IntegriCloud