root.cc (2632:1bb2f91485ea) root.cc (2665:a124942bacb8)
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
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.
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
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.
27 *
28 * Authors: Nathan Binkert
29 * Steve Reinhardt
27 */
28
29#include <cstring>
30#include <fstream>
31#include <list>
32#include <string>
33#include <vector>
34
35#include "base/misc.hh"
36#include "base/output.hh"
37#include "sim/builder.hh"
38#include "sim/host.hh"
39#include "sim/sim_events.hh"
40#include "sim/sim_object.hh"
41#include "sim/root.hh"
42
43using namespace std;
44
45Tick curTick = 0;
46ostream *outputStream;
47ostream *configStream;
48
49/// The simulated frequency of curTick. (This is only here for a short time)
50Tick ticksPerSecond;
51
52namespace Clock {
53/// The simulated frequency of curTick. (In ticks per second)
54Tick Frequency;
55
56namespace Float {
57double s;
58double ms;
59double us;
60double ns;
61double ps;
62
63double Hz;
64double kHz;
65double MHz;
66double GHZ;
67/* namespace Float */ }
68
69namespace Int {
70Tick s;
71Tick ms;
72Tick us;
73Tick ns;
74Tick ps;
75/* namespace Float */ }
76
77/* namespace Clock */ }
78
79
80// Dummy Object
81class Root : public SimObject
82{
83 private:
84 Tick max_tick;
85 Tick progress_interval;
86
87 public:
88 Root(const std::string &name, Tick maxtick, Tick pi)
89 : SimObject(name), max_tick(maxtick), progress_interval(pi)
90 {}
91
92 virtual void startup();
93};
94
95void
96Root::startup()
97{
98 if (max_tick != 0)
99 new SimExitEvent(curTick + max_tick, "reached maximum cycle count");
100
101 if (progress_interval != 0)
102 new ProgressEvent(&mainEventQueue, progress_interval);
103}
104
105BEGIN_DECLARE_SIM_OBJECT_PARAMS(Root)
106
107 Param<Tick> clock;
108 Param<Tick> max_tick;
109 Param<Tick> progress_interval;
110 Param<string> output_file;
111
112END_DECLARE_SIM_OBJECT_PARAMS(Root)
113
114BEGIN_INIT_SIM_OBJECT_PARAMS(Root)
115
116 INIT_PARAM(clock, "tick frequency"),
117 INIT_PARAM(max_tick, "maximum simulation time"),
118 INIT_PARAM(progress_interval, "print a progress message"),
119 INIT_PARAM(output_file, "file to dump simulator output to")
120
121END_INIT_SIM_OBJECT_PARAMS(Root)
122
123CREATE_SIM_OBJECT(Root)
124{
125 static bool created = false;
126 if (created)
127 panic("only one root object allowed!");
128
129 created = true;
130
131 outputStream = simout.find(output_file);
132 Root *root = new Root(getInstanceName(), max_tick, progress_interval);
133
134 using namespace Clock;
135 Frequency = clock;
136 Float::s = static_cast<double>(Frequency);
137 Float::ms = Float::s / 1.0e3;
138 Float::us = Float::s / 1.0e6;
139 Float::ns = Float::s / 1.0e9;
140 Float::ps = Float::s / 1.0e12;
141
142 Float::Hz = 1.0 / Float::s;
143 Float::kHz = 1.0 / Float::ms;
144 Float::MHz = 1.0 / Float::us;
145 Float::GHZ = 1.0 / Float::ns;
146
147 Int::s = Frequency;
148 Int::ms = Int::s / 1000;
149 Int::us = Int::ms / 1000;
150 Int::ns = Int::us / 1000;
151 Int::ps = Int::ns / 1000;
152
153 return root;
154}
155
156REGISTER_SIM_OBJECT("Root", Root)
30 */
31
32#include <cstring>
33#include <fstream>
34#include <list>
35#include <string>
36#include <vector>
37
38#include "base/misc.hh"
39#include "base/output.hh"
40#include "sim/builder.hh"
41#include "sim/host.hh"
42#include "sim/sim_events.hh"
43#include "sim/sim_object.hh"
44#include "sim/root.hh"
45
46using namespace std;
47
48Tick curTick = 0;
49ostream *outputStream;
50ostream *configStream;
51
52/// The simulated frequency of curTick. (This is only here for a short time)
53Tick ticksPerSecond;
54
55namespace Clock {
56/// The simulated frequency of curTick. (In ticks per second)
57Tick Frequency;
58
59namespace Float {
60double s;
61double ms;
62double us;
63double ns;
64double ps;
65
66double Hz;
67double kHz;
68double MHz;
69double GHZ;
70/* namespace Float */ }
71
72namespace Int {
73Tick s;
74Tick ms;
75Tick us;
76Tick ns;
77Tick ps;
78/* namespace Float */ }
79
80/* namespace Clock */ }
81
82
83// Dummy Object
84class Root : public SimObject
85{
86 private:
87 Tick max_tick;
88 Tick progress_interval;
89
90 public:
91 Root(const std::string &name, Tick maxtick, Tick pi)
92 : SimObject(name), max_tick(maxtick), progress_interval(pi)
93 {}
94
95 virtual void startup();
96};
97
98void
99Root::startup()
100{
101 if (max_tick != 0)
102 new SimExitEvent(curTick + max_tick, "reached maximum cycle count");
103
104 if (progress_interval != 0)
105 new ProgressEvent(&mainEventQueue, progress_interval);
106}
107
108BEGIN_DECLARE_SIM_OBJECT_PARAMS(Root)
109
110 Param<Tick> clock;
111 Param<Tick> max_tick;
112 Param<Tick> progress_interval;
113 Param<string> output_file;
114
115END_DECLARE_SIM_OBJECT_PARAMS(Root)
116
117BEGIN_INIT_SIM_OBJECT_PARAMS(Root)
118
119 INIT_PARAM(clock, "tick frequency"),
120 INIT_PARAM(max_tick, "maximum simulation time"),
121 INIT_PARAM(progress_interval, "print a progress message"),
122 INIT_PARAM(output_file, "file to dump simulator output to")
123
124END_INIT_SIM_OBJECT_PARAMS(Root)
125
126CREATE_SIM_OBJECT(Root)
127{
128 static bool created = false;
129 if (created)
130 panic("only one root object allowed!");
131
132 created = true;
133
134 outputStream = simout.find(output_file);
135 Root *root = new Root(getInstanceName(), max_tick, progress_interval);
136
137 using namespace Clock;
138 Frequency = clock;
139 Float::s = static_cast<double>(Frequency);
140 Float::ms = Float::s / 1.0e3;
141 Float::us = Float::s / 1.0e6;
142 Float::ns = Float::s / 1.0e9;
143 Float::ps = Float::s / 1.0e12;
144
145 Float::Hz = 1.0 / Float::s;
146 Float::kHz = 1.0 / Float::ms;
147 Float::MHz = 1.0 / Float::us;
148 Float::GHZ = 1.0 / Float::ns;
149
150 Int::s = Frequency;
151 Int::ms = Int::s / 1000;
152 Int::us = Int::ms / 1000;
153 Int::ns = Int::us / 1000;
154 Int::ps = Int::ns / 1000;
155
156 return root;
157}
158
159REGISTER_SIM_OBJECT("Root", Root)