summaryrefslogtreecommitdiffstats
path: root/src/usr/pore/poreve/model/poreinterface.H
blob: 86e3fef1004e6dac068217526553f8dedb834179 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/pore/poreve/model/poreinterface.H $                   */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,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                                                     */
#ifndef __VSBE_POREINTERFACE_H
#define __VSBE_POREINTERFACE_H

// $Id: poreinterface.H,v 1.11 2012/06/18 13:56:57 bcbrock Exp $

/// \file poreinterface.H
/// \brief The PORE hardware interface class

#include <stddef.h>
#include <stdint.h>

#include "bebits.H"
#include "modelerror.H"
#include "poreaddress.H"
#include "transaction.H"
#include "poreconstants.H"
#include "poreregister.H"
#include "porestate.H"

// This is required for debugging prints only
#if 1
#include <stdio.h>
#endif

namespace vsbe {

    class PoreAddress;
    class PoreInterface;
    class PoreModel;
    class PoreState;
}


////////////////////////////////////////////////////////////////////////////
// PoreInterface
////////////////////////////////////////////////////////////////////////////


/// Abstract base class for the PORE hardware engine virtual environment
///
/// PoreInterface is an abstract class that specifies the interfaces that a
/// virtual environment must implement on behalf of the abstract PoreModel,
/// and provides the control interfaces into the PoreModel. Applications will
/// never operate on the PoreModel directly, but instead will operate
/// exclusively on classes derived from PoreInterface.

class 
vsbe::PoreInterface {

public:

    ///////////////////////// Control Interface  /////////////////////////

    /// See PoreModel::restart()
    virtual int 
    restart();

    /// See PoreModel::run()
    virtual int 
    run(const uint64_t i_instructions, uint64_t& o_ran);
    
    /// See PoreModel::stop()
    virtual ModelError
    stop(const int i_stopCode);

    /// See PoreModel::modelError()
    virtual ModelError 
    modelError(const ModelError i_modelError);

    /// See PoreModel::clearModelError()
    virtual void
    clearModelError();

    /// See PoreModel::clearHardwareErrors()
    virtual ModelError
    clearHardwareErrors();

    /// See PoreModel::registerRead()
    virtual ModelError
    registerRead(const PoreRegisterOffset i_offset, 
                 uint64_t& o_data, 
                 const size_t i_size = 8);

    /// See PoreModel::registerWrite()
    virtual ModelError
    registerWrite(const PoreRegisterOffset i_offset, 
                  const uint64_t i_data, 
                  const size_t i_size = 8);

    /// See PoreModel::registerReadRaw()
    virtual ModelError
    registerReadRaw(const PoreRegisterOffset i_offset, 
                    uint64_t& o_data, 
                    const size_t i_size = 8);

    /// See PoreModel::registerWriteRaw()
    virtual ModelError
    registerWriteRaw(const PoreRegisterOffset i_offset, 
                     const uint64_t i_data, 
                     const size_t i_size = 8);

    /// See PoreModel::enableHookInstruction()
    virtual void
    enableHookInstruction(bool i_enable);

    /// See PoreModel::enableAddressHooks()
    virtual void
    enableAddressHooks(bool i_enable);

    /// See PoreModel::extractState()
    virtual ModelError
    extractState(PoreState& o_state);

    /// See PoreModel::installState()
    virtual ModelError
    installState(const PoreState& i_state);

    /// See PoreModel::forceBranch()
    virtual ModelError
    forceBranch(const PoreAddress& i_address);

    /// See PoreModel::setPc()
    virtual ModelError
    setPc(const PoreAddress& I_pc);

    /// See PoreModel::setBreakpoint()
    virtual ModelError
    setBreakpoint(const PoreAddress& i_address);

    /// Effectively disable the PORE address breakpoint
    ///
    /// \retval 0 Success
    ///
    /// \retval non-0 Any ModelError returned by underlying hardware
    /// operations. 
    virtual ModelError
    disableBreakpoint();

    /// See PoreModel::enableTrap()
    virtual ModelError
    enableTrap(const bool i_enable);

    /// See PoreModel::getStatus()
    virtual int
    getStatus();

    /// See PoreModel::getModelError()
    virtual ModelError
    getModelError();

    /// See PoreModel::getInstructions()
    virtual uint64_t 
    getInstructions();

    /// See PoreModel::getStopCode()
    virtual int
    getStopCode();

    /// See PoreModel::getmemInteger()
    virtual ModelError
    getmemInteger(const PoreAddress i_address,
                  uint64_t& o_data,
                  const size_t i_size);

    /// See PoreModel::putmemInteger()
    virtual ModelError
    putmemInteger(const PoreAddress i_address,
                  uint64_t i_data,
                  const size_t i_size);


    ////////////////////  Abstract Interface  /////////////////////////

    /// See PoreModel::pibMaster()
    virtual void
    pibMaster(PibTransaction& io_transaction) = 0;

    /// See PoreModel::ociMaster()
    virtual void
    ociMaster(OciTransaction& io_transaction) = 0;

    /// See PoreModel::wait()
    virtual void
    wait(const uint32_t i_count) = 0;

    /// See PoreModel::hookInstruction()
    virtual void
    hookInstruction(const PoreAddress& i_address, 
                    const uint32_t i_hook,
                    const uint64_t i_parameter) = 0;

    /// See PoreModel::hookRead()
    virtual void
    hookRead(const PoreAddress& i_address) = 0;

    /// See PoreModel::hookWrite()
    virtual void
    hookWrite(const PoreAddress& i_address) = 0;

    /// See PoreModel::hookFetch()
    virtual void
    hookFetch(const PoreAddress& i_address) = 0;

    /// See PoreModel::errorIntr()
    virtual void
    errorIntr(void) = 0;

    /// See PoreModel::fatalErrorIntr()
    virtual void
    fatalErrorIntr(void) = 0;


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

    /// Create the PoreInterface 
    ///
    /// \param[in] i_id The IBUF ID (PORE engine type) of the PORE model to
    /// create.
    PoreInterface(PoreIbufId i_id);

    virtual ~PoreInterface();


    ///////////////////// Register Interface  ////////////////////////////

    /// \defgroup pore_register_access PORE Register Access
    ///
    /// These data members of PoreInterface provide easy access to
    /// programmer-visible and abstract registers for use by procedures and
    /// hooks. Unless otherwise indicated in the brief comment the register is
    /// both readable and writable. Data registers, address registers, the
    /// counter register and some control register values are right justfied,
    /// and only the indicated number of bits are writable. Other hardware
    /// control registers have unique layouts. See the detailed comments for
    /// each register and the comments for the PoreRegister class for more
    /// information.
    ///
    /// @{

    /// 64-bit data register D0
    PoreDataBuffer d0;
    /// 64-bit data register D1
    PoreDataBuffer d1;
    /// 32-bit address register A0
    PoreRegisterWritable a0;
    /// 32-bit address register A1
    PoreRegisterWritable a1;
    /// 7-bit pervasive chiplet register P0
    PoreRegisterWritable p0;
    /// 7-bit pervasive chiplet register P1
    PoreRegisterWritable p1;
    /// 24-bit counter CTR
    PoreRegisterWritable ctr;
    /// 21-bit error mask register
    ///
    /// The EMR is implemented as a 64-bit registers, however only the
    /// high-order 21 bits contain information.
    PoreRegisterWritable emr;
    /// 64-bit EXE-Trigger Register - Partially writable
    ///
    /// The low-order 32 bits of the EXE-Trigger register are writable from a
    /// PORE program.  The register is fully writable externally, however this
    /// has the major side effect of kicking off a new PORE program if the
    /// high-order 32-bits are written.  The write implementation here only
    /// writes the low-order 32 bits; to write the entire register call
    /// registerWrite() directly.
    PoreRegisterWritable etr;
    /// 32-bit Special-Purpose General Register 0
    PoreRegisterWritable sprg0;
    /// PC - Read-only
    /// 
    /// The 48-bit PC is read-only using the PoreRegister interface.  Setting
    /// the PC requires using the setPc() procedure on the PoreInterface.
    /// It's likely that a hook programmer should actually be using the
    /// abstract \c CIA register.
    PoreRegister pc;
    /// ID-Flags Register - Partial read-only
    ///
    /// Note that from inside a PORE program this register is read-only.
    /// Externally the ALU flags fields of the register are writable, so this
    /// behavior is supported.  The writable portion (the flags) are bits
    /// 48:55. 
    PoreRegisterWritable ifr;
    /// Current instruction address - Read-Only
    ///
    /// This is an abstract register. If the PORE engine is running or stopped
    /// at a breakpoint or trap then reading the CIA returns the address of
    /// the currently executing instruction.  If the PORE engine is stopped in
    /// a wait state then reading the CIA returns the address of the last
    /// instruction executed.
    ///
    /// This register is read-only.  If the intention is to force a branch
    /// then the forceBranch() or setPc() methods of the PoreInterface should
    /// be used.
    PoreRegister cia;

    /// @}

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

protected:

    /// Create a new underlying model
    ///
    /// \param[in] i_id The IBUF ID (PORE engine type) of the PORE model to
    /// create.
    ///
    /// This method creates and installs an instance of the PoreModel with a
    /// specific PoreIbufId.  This method is provided separately from the
    /// constructor to support use of the PoreInterface in the Simics
    /// environment.  In Simics, the type of the engine (GPE0, SLW, etc.) is
    /// not known until after model construction, but before actual simulation
    /// begins.  In Simics models are created with a default type, then later
    /// recreated using newModel() once the actual type is known.
    virtual void
    newModel(PoreIbufId i_id);

    /// The IBUF ID (engine type) of the PORE being modeled
    PoreIbufId iv_ibufId;
    
private:

    /// The associated PoreModel
    ///
    /// This object is created and destroyed by the PoreInterface.
    PoreModel* iv_model;

    ///////////////////////////// Safety //////////////////////////////////

private:
    PoreInterface(const PoreInterface& rhs);
    PoreInterface& operator=(const PoreInterface& rhs);
};


#endif  // __VSBE_POREINTERFACE_H
OpenPOWER on IntegriCloud