Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 1 | /* |
Steve Reinhardt | ad8b963 | 2005-06-05 05:16:00 -0400 | [diff] [blame] | 2 | * Copyright (c) 2001-2005 The Regents of The University of Michigan |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 3 | * 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 Saidi | cb0cf2d | 2006-05-31 19:26:56 -0400 | [diff] [blame] | 27 | * |
| 28 | * Authors: Steve Reinhardt |
| 29 | * Nathan Binkert |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | /* @file |
| 33 | * User Console Definitions |
| 34 | */ |
| 35 | |
| 36 | #ifndef __SIM_OBJECT_HH__ |
| 37 | #define __SIM_OBJECT_HH__ |
| 38 | |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 39 | #include <iostream> |
Gabe Black | 18c83be | 2008-06-21 14:23:58 -0400 | [diff] [blame] | 40 | #include <list> |
| 41 | #include <map> |
| 42 | #include <string> |
| 43 | #include <vector> |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 44 | |
Nathan Binkert | abc76f2 | 2007-07-23 21:51:38 -0700 | [diff] [blame] | 45 | #include "params/SimObject.hh" |
Nathan Binkert | 8291d9d | 2008-10-09 04:58:23 -0700 | [diff] [blame] | 46 | #include "sim/eventq.hh" |
Steve Reinhardt | 25693e9 | 2003-10-10 11:09:00 -0700 | [diff] [blame] | 47 | #include "sim/serialize.hh" |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 48 | |
Kevin Lim | f64c175 | 2006-06-29 19:40:12 -0400 | [diff] [blame] | 49 | class BaseCPU; |
| 50 | class Event; |
Ron Dreslinski | 5cfff7d | 2006-05-11 17:24:15 -0400 | [diff] [blame] | 51 | |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 52 | /* |
| 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 Reinhardt | 30ce620 | 2010-07-05 21:39:38 -0700 | [diff] [blame] | 57 | class SimObject : public EventManager, public Serializable |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 58 | { |
Nathan Binkert | 0f8067f | 2005-03-15 17:11:54 -0500 | [diff] [blame] | 59 | public: |
Kevin Lim | f64c175 | 2006-06-29 19:40:12 -0400 | [diff] [blame] | 60 | enum State { |
Ali Saidi | 2bc9229 | 2006-07-12 20:22:07 -0400 | [diff] [blame] | 61 | Running, |
Kevin Lim | d8fd09c | 2006-07-05 17:59:33 -0400 | [diff] [blame] | 62 | Draining, |
Ali Saidi | 2bc9229 | 2006-07-12 20:22:07 -0400 | [diff] [blame] | 63 | Drained |
Kevin Lim | f64c175 | 2006-06-29 19:40:12 -0400 | [diff] [blame] | 64 | }; |
Lisa Hsu | 8acecfe | 2006-10-11 18:53:50 -0400 | [diff] [blame] | 65 | |
Ali Saidi | 2bc9229 | 2006-07-12 20:22:07 -0400 | [diff] [blame] | 66 | private: |
| 67 | State state; |
Kevin Lim | f64c175 | 2006-06-29 19:40:12 -0400 | [diff] [blame] | 68 | |
Andrew Schultz | 2ab51fb | 2003-10-31 17:32:04 -0500 | [diff] [blame] | 69 | protected: |
Kevin Lim | f64c175 | 2006-06-29 19:40:12 -0400 | [diff] [blame] | 70 | void changeState(State new_state) { state = new_state; } |
Nathan Binkert | 0f8067f | 2005-03-15 17:11:54 -0500 | [diff] [blame] | 71 | |
| 72 | public: |
Kevin Lim | f64c175 | 2006-06-29 19:40:12 -0400 | [diff] [blame] | 73 | State getState() { return state; } |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 74 | |
Kevin Lim | f64c175 | 2006-06-29 19:40:12 -0400 | [diff] [blame] | 75 | private: |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 76 | typedef std::vector<SimObject *> SimObjectList; |
| 77 | |
| 78 | // list of all instantiated simulation objects |
| 79 | static SimObjectList simObjectList; |
| 80 | |
Nathan Binkert | abc76f2 | 2007-07-23 21:51:38 -0700 | [diff] [blame] | 81 | protected: |
| 82 | const SimObjectParams *_params; |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 83 | |
Nathan Binkert | abc76f2 | 2007-07-23 21:51:38 -0700 | [diff] [blame] | 84 | public: |
| 85 | typedef SimObjectParams Params; |
| 86 | const Params *params() const { return _params; } |
| 87 | SimObject(const Params *_params); |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 88 | virtual ~SimObject() {} |
| 89 | |
Miles Kaufmann | 54cc005 | 2007-08-30 15:16:59 -0400 | [diff] [blame] | 90 | public: |
| 91 | |
Nathan Binkert | 0f8067f | 2005-03-15 17:11:54 -0500 | [diff] [blame] | 92 | virtual const std::string name() const { return params()->name; } |
Andrew Schultz | 2ab51fb | 2003-10-31 17:32:04 -0500 | [diff] [blame] | 93 | |
Nathan Binkert | 78ae876 | 2004-11-03 11:47:55 -0500 | [diff] [blame] | 94 | // initialization pass of all objects. |
| 95 | // Gets invoked after construction, before unserialize. |
Nathan Binkert | 5d7224c | 2004-01-14 02:00:20 -0500 | [diff] [blame] | 96 | virtual void init(); |
Nathan Binkert | 5d7224c | 2004-01-14 02:00:20 -0500 | [diff] [blame] | 97 | |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 98 | // register statistics for this object |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 99 | virtual void regStats(); |
| 100 | virtual void regFormulas(); |
Nathan Binkert | b064b8a | 2003-11-05 18:21:18 -0500 | [diff] [blame] | 101 | virtual void resetStats(); |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 102 | |
Steve Reinhardt | 30ce620 | 2010-07-05 21:39:38 -0700 | [diff] [blame] | 103 | // final initialization before simulation |
| 104 | // all state is unserialized so |
| 105 | virtual void startup(); |
Nathan Binkert | b064b8a | 2003-11-05 18:21:18 -0500 | [diff] [blame] | 106 | |
Steve Reinhardt | 777c1eb | 2003-12-11 00:16:46 -0800 | [diff] [blame] | 107 | // static: call nameOut() & serialize() on all SimObjects |
| 108 | static void serializeAll(std::ostream &); |
Kevin Lim | f64c175 | 2006-06-29 19:40:12 -0400 | [diff] [blame] | 109 | static void unserializeAll(Checkpoint *cp); |
Nathan Binkert | 838273a | 2004-06-28 16:49:35 -0400 | [diff] [blame] | 110 | |
Ron Dreslinski | 5cfff7d | 2006-05-11 17:24:15 -0400 | [diff] [blame] | 111 | // Methods to drain objects in order to take checkpoints |
| 112 | // Or switch from timing -> atomic memory model |
Ali Saidi | 2bc9229 | 2006-07-12 20:22:07 -0400 | [diff] [blame] | 113 | // 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 Lim | f64c175 | 2006-06-29 19:40:12 -0400 | [diff] [blame] | 117 | virtual void resume(); |
| 118 | virtual void setMemoryMode(State new_mode); |
| 119 | virtual void switchOut(); |
| 120 | virtual void takeOverFrom(BaseCPU *cpu); |
Ron Dreslinski | 5cfff7d | 2006-05-11 17:24:15 -0400 | [diff] [blame] | 121 | |
Nathan Binkert | 3711ea7 | 2004-07-30 10:47:53 -0400 | [diff] [blame] | 122 | #ifdef DEBUG |
| 123 | public: |
| 124 | bool doDebugBreak; |
| 125 | static void debugObjectBreak(const std::string &objs); |
| 126 | #endif |
| 127 | |
Steve Reinhardt | 3952e41 | 2008-01-02 12:20:15 -0800 | [diff] [blame] | 128 | /** |
| 129 | * Find the SimObject with the given name and return a pointer to |
Steve Reinhardt | cde5a79 | 2008-01-02 13:46:22 -0800 | [diff] [blame] | 130 | * it. Primarily used for interactive debugging. Argument is |
Steve Reinhardt | 3952e41 | 2008-01-02 12:20:15 -0800 | [diff] [blame] | 131 | * char* rather than std::string to make it callable from gdb. |
| 132 | */ |
| 133 | static SimObject *find(const char *name); |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 134 | }; |
| 135 | |
Steve Raasch | 92638f9 | 2003-10-07 10:41:54 -0400 | [diff] [blame] | 136 | #endif // __SIM_OBJECT_HH__ |