blob: 1b22c5825c45db804c54782aefbcfba22b4b1218 [file] [log] [blame]
Steve Raasch92638f92003-10-07 10:41:54 -04001/*
Steve Reinhardtad8b9632005-06-05 05:16:00 -04002 * Copyright (c) 2001-2005 The Regents of The University of Michigan
Steve Raasch92638f92003-10-07 10:41:54 -04003 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Ali Saidicb0cf2d2006-05-31 19:26:56 -040027 *
28 * Authors: Steve Reinhardt
29 * Nathan Binkert
Steve Raasch92638f92003-10-07 10:41:54 -040030 */
31
32/* @file
33 * User Console Definitions
34 */
35
36#ifndef __SIM_OBJECT_HH__
37#define __SIM_OBJECT_HH__
38
Steve Raasch92638f92003-10-07 10:41:54 -040039#include <iostream>
Gabe Black18c83be2008-06-21 14:23:58 -040040#include <list>
41#include <map>
42#include <string>
43#include <vector>
Steve Raasch92638f92003-10-07 10:41:54 -040044
Nathan Binkertabc76f22007-07-23 21:51:38 -070045#include "params/SimObject.hh"
Nathan Binkert8291d9d2008-10-09 04:58:23 -070046#include "sim/eventq.hh"
Steve Reinhardt25693e92003-10-10 11:09:00 -070047#include "sim/serialize.hh"
Steve Raasch92638f92003-10-07 10:41:54 -040048
Kevin Limf64c1752006-06-29 19:40:12 -040049class BaseCPU;
50class Event;
Ron Dreslinski5cfff7d2006-05-11 17:24:15 -040051
Steve Raasch92638f92003-10-07 10:41:54 -040052/*
53 * Abstract superclass for simulation objects. Represents things that
54 * correspond to physical components and can be specified via the
55 * config file (CPUs, caches, etc.).
56 */
Steve Reinhardt30ce6202010-07-05 21:39:38 -070057class SimObject : public EventManager, public Serializable
Steve Raasch92638f92003-10-07 10:41:54 -040058{
Nathan Binkert0f8067f2005-03-15 17:11:54 -050059 public:
Kevin Limf64c1752006-06-29 19:40:12 -040060 enum State {
Ali Saidi2bc92292006-07-12 20:22:07 -040061 Running,
Kevin Limd8fd09c2006-07-05 17:59:33 -040062 Draining,
Ali Saidi2bc92292006-07-12 20:22:07 -040063 Drained
Kevin Limf64c1752006-06-29 19:40:12 -040064 };
Lisa Hsu8acecfe2006-10-11 18:53:50 -040065
Ali Saidi2bc92292006-07-12 20:22:07 -040066 private:
67 State state;
Kevin Limf64c1752006-06-29 19:40:12 -040068
Andrew Schultz2ab51fb2003-10-31 17:32:04 -050069 protected:
Kevin Limf64c1752006-06-29 19:40:12 -040070 void changeState(State new_state) { state = new_state; }
Nathan Binkert0f8067f2005-03-15 17:11:54 -050071
72 public:
Kevin Limf64c1752006-06-29 19:40:12 -040073 State getState() { return state; }
Steve Raasch92638f92003-10-07 10:41:54 -040074
Kevin Limf64c1752006-06-29 19:40:12 -040075 private:
Steve Raasch92638f92003-10-07 10:41:54 -040076 typedef std::vector<SimObject *> SimObjectList;
77
78 // list of all instantiated simulation objects
79 static SimObjectList simObjectList;
80
Nathan Binkertabc76f22007-07-23 21:51:38 -070081 protected:
82 const SimObjectParams *_params;
Steve Raasch92638f92003-10-07 10:41:54 -040083
Nathan Binkertabc76f22007-07-23 21:51:38 -070084 public:
85 typedef SimObjectParams Params;
86 const Params *params() const { return _params; }
87 SimObject(const Params *_params);
Steve Raasch92638f92003-10-07 10:41:54 -040088 virtual ~SimObject() {}
89
Miles Kaufmann54cc0052007-08-30 15:16:59 -040090 public:
91
Nathan Binkert0f8067f2005-03-15 17:11:54 -050092 virtual const std::string name() const { return params()->name; }
Andrew Schultz2ab51fb2003-10-31 17:32:04 -050093
Nathan Binkert78ae8762004-11-03 11:47:55 -050094 // initialization pass of all objects.
95 // Gets invoked after construction, before unserialize.
Nathan Binkert5d7224c2004-01-14 02:00:20 -050096 virtual void init();
Nathan Binkert5d7224c2004-01-14 02:00:20 -050097
Steve Raasch92638f92003-10-07 10:41:54 -040098 // register statistics for this object
Steve Raasch92638f92003-10-07 10:41:54 -040099 virtual void regStats();
100 virtual void regFormulas();
Nathan Binkertb064b8a2003-11-05 18:21:18 -0500101 virtual void resetStats();
Steve Raasch92638f92003-10-07 10:41:54 -0400102
Steve Reinhardt30ce6202010-07-05 21:39:38 -0700103 // final initialization before simulation
104 // all state is unserialized so
105 virtual void startup();
Nathan Binkertb064b8a2003-11-05 18:21:18 -0500106
Steve Reinhardt777c1eb2003-12-11 00:16:46 -0800107 // static: call nameOut() & serialize() on all SimObjects
108 static void serializeAll(std::ostream &);
Kevin Limf64c1752006-06-29 19:40:12 -0400109 static void unserializeAll(Checkpoint *cp);
Nathan Binkert838273a2004-06-28 16:49:35 -0400110
Ron Dreslinski5cfff7d2006-05-11 17:24:15 -0400111 // Methods to drain objects in order to take checkpoints
112 // Or switch from timing -> atomic memory model
Ali Saidi2bc92292006-07-12 20:22:07 -0400113 // Drain returns 0 if the simobject can drain immediately or
114 // the number of times the drain_event's process function will be called
115 // before the object will be done draining. Normally this should be 1
116 virtual unsigned int drain(Event *drain_event);
Kevin Limf64c1752006-06-29 19:40:12 -0400117 virtual void resume();
118 virtual void setMemoryMode(State new_mode);
119 virtual void switchOut();
120 virtual void takeOverFrom(BaseCPU *cpu);
Ron Dreslinski5cfff7d2006-05-11 17:24:15 -0400121
Nathan Binkert3711ea72004-07-30 10:47:53 -0400122#ifdef DEBUG
123 public:
124 bool doDebugBreak;
125 static void debugObjectBreak(const std::string &objs);
126#endif
127
Steve Reinhardt3952e412008-01-02 12:20:15 -0800128 /**
129 * Find the SimObject with the given name and return a pointer to
Steve Reinhardtcde5a792008-01-02 13:46:22 -0800130 * it. Primarily used for interactive debugging. Argument is
Steve Reinhardt3952e412008-01-02 12:20:15 -0800131 * char* rather than std::string to make it callable from gdb.
132 */
133 static SimObject *find(const char *name);
Steve Raasch92638f92003-10-07 10:41:54 -0400134};
135
Steve Raasch92638f92003-10-07 10:41:54 -0400136#endif // __SIM_OBJECT_HH__