kernel.cc (12957:e54f9890363d) kernel.cc (12982:c7966254372e)
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Authors: Gabe Black
28 */
29
30#include "systemc/core/kernel.hh"
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Authors: Gabe Black
28 */
29
30#include "systemc/core/kernel.hh"
31
32#include "base/logging.hh"
33#include "systemc/core/module.hh"
31#include "systemc/core/scheduler.hh"
32
34#include "systemc/core/scheduler.hh"
35
33namespace SystemC
36namespace sc_gem5
34{
35
36Kernel::Kernel(Params *params) :
37{
38
39Kernel::Kernel(Params *params) :
37 SimObject(params), t0Event(this, false, EventBase::Default_Pri - 1) {}
40 SimObject(params), _stopAfterCallbacks(false),
41 _startComplete(false), _endComplete(false),
42 _status(sc_core::SC_ELABORATION),
43 t0Event(this, false, EventBase::Default_Pri - 1) {}
38
39void
44
45void
46Kernel::init()
47{
48 kernel->status(::sc_core::SC_BEFORE_END_OF_ELABORATION);
49 for (auto m: sc_gem5::allModules)
50 m->sc_mod()->before_end_of_elaboration();
51
52 if (_stopAfterCallbacks)
53 stopWork();
54}
55
56void
57Kernel::regStats()
58{
59 kernel->status(::sc_core::SC_END_OF_ELABORATION);
60 for (auto m: sc_gem5::allModules)
61 m->sc_mod()->end_of_elaboration();
62
63 if (_stopAfterCallbacks)
64 stopWork();
65}
66
67void
40Kernel::startup()
41{
68Kernel::startup()
69{
70 kernel->status(::sc_core::SC_START_OF_SIMULATION);
71 for (auto m: sc_gem5::allModules)
72 m->sc_mod()->start_of_simulation();
73
74 _startComplete = true;
75
76 if (_stopAfterCallbacks)
77 stopWork();
78
79 kernel->status(::sc_core::SC_RUNNING);
80
42 schedule(t0Event, curTick());
43 // Install ourselves as the scheduler's event manager.
44 ::sc_gem5::scheduler.setEventQueue(eventQueue());
45 // Run update once before the event queue starts.
46 ::sc_gem5::scheduler.update();
47}
48
49void
81 schedule(t0Event, curTick());
82 // Install ourselves as the scheduler's event manager.
83 ::sc_gem5::scheduler.setEventQueue(eventQueue());
84 // Run update once before the event queue starts.
85 ::sc_gem5::scheduler.update();
86}
87
88void
89Kernel::stop()
90{
91 if (status() < ::sc_core::SC_RUNNING)
92 _stopAfterCallbacks = true;
93 else
94 stopWork();
95}
96
97void
98Kernel::stopWork()
99{
100 kernel->status(::sc_core::SC_END_OF_SIMULATION);
101 for (auto m: sc_gem5::allModules)
102 m->sc_mod()->end_of_simulation();
103
104 _endComplete = true;
105
106 kernel->status(::sc_core::SC_STOPPED);
107
108 if (_stopAfterCallbacks)
109 fatal("Simulation called sc_stop during elaboration.\n");
110}
111
112void
50Kernel::t0Handler()
51{
52 // Now that the event queue has started, mark all the processes that
53 // need to be initialized as ready to run.
54 //
55 // This event has greater priority than delta notifications and so will
56 // happen before them, honoring the ordering for the initialization phase
57 // in the spec. The delta phase will happen at normal priority, and then
58 // the event which runs the processes which is at a lower priority.
59 ::sc_gem5::scheduler.prepareForInit();
113Kernel::t0Handler()
114{
115 // Now that the event queue has started, mark all the processes that
116 // need to be initialized as ready to run.
117 //
118 // This event has greater priority than delta notifications and so will
119 // happen before them, honoring the ordering for the initialization phase
120 // in the spec. The delta phase will happen at normal priority, and then
121 // the event which runs the processes which is at a lower priority.
122 ::sc_gem5::scheduler.prepareForInit();
123
124 status(::sc_core::SC_RUNNING);
60}
61
125}
126
62} // namespace SystemC
127Kernel *kernel;
63
128
64SystemC::Kernel *
129} // namespace sc_gem5
130
131sc_gem5::Kernel *
65SystemC_KernelParams::create()
66{
132SystemC_KernelParams::create()
133{
67 return new SystemC::Kernel(this);
134 panic_if(sc_gem5::kernel,
135 "Only one systemc kernel object may be defined.\n");
136 sc_gem5::kernel = new sc_gem5::Kernel(this);
137 return sc_gem5::kernel;
68}
138}