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 --- 22 unchanged lines hidden (view full) --- 31 32#include "base/logging.hh" 33#include "systemc/core/module.hh" 34#include "systemc/core/scheduler.hh" 35 36namespace sc_gem5 37{ 38 |
39namespace 40{ 41 42bool stopAfterCallbacks = false; 43bool startComplete = false; 44bool endComplete = false; 45 46sc_core::sc_status _status = sc_core::SC_ELABORATION; 47 48} // anonymous namespace 49 50bool Kernel::startOfSimulationComplete() { return startComplete; } 51bool Kernel::endOfSimulationComplete() { return endComplete; } 52 53sc_core::sc_status Kernel::status() { return _status; } 54void Kernel::status(sc_core::sc_status s) { _status = s; } 55 |
56Kernel::Kernel(Params *params) : |
57 SimObject(params), t0Event(this, false, EventBase::Default_Pri - 1) {} |
58 59void 60Kernel::init() 61{ |
62 status(::sc_core::SC_BEFORE_END_OF_ELABORATION); |
63 for (auto m: sc_gem5::allModules) 64 m->sc_mod()->before_end_of_elaboration(); 65 |
66 if (stopAfterCallbacks) |
67 stopWork(); 68} 69 70void 71Kernel::regStats() 72{ |
73 status(::sc_core::SC_END_OF_ELABORATION); |
74 for (auto m: sc_gem5::allModules) 75 m->sc_mod()->end_of_elaboration(); 76 |
77 if (stopAfterCallbacks) |
78 stopWork(); 79} 80 81void 82Kernel::startup() 83{ |
84 status(::sc_core::SC_START_OF_SIMULATION); |
85 for (auto m: sc_gem5::allModules) 86 m->sc_mod()->start_of_simulation(); 87 |
88 startComplete = true; |
89 |
90 if (stopAfterCallbacks) |
91 stopWork(); 92 93 kernel->status(::sc_core::SC_RUNNING); 94 95 schedule(t0Event, curTick()); 96 // Install ourselves as the scheduler's event manager. 97 ::sc_gem5::scheduler.setEventQueue(eventQueue()); 98 // Run update once before the event queue starts. 99 ::sc_gem5::scheduler.update(); 100} 101 102void 103Kernel::stop() 104{ 105 if (status() < ::sc_core::SC_RUNNING) |
106 stopAfterCallbacks = true; |
107 else 108 stopWork(); 109} 110 111void 112Kernel::stopWork() 113{ |
114 status(::sc_core::SC_END_OF_SIMULATION); |
115 for (auto m: sc_gem5::allModules) 116 m->sc_mod()->end_of_simulation(); 117 |
118 endComplete = true; |
119 |
120 status(::sc_core::SC_STOPPED); |
121 |
122 if (stopAfterCallbacks) |
123 fatal("Simulation called sc_stop during elaboration.\n"); 124} 125 126void 127Kernel::t0Handler() 128{ 129 // Now that the event queue has started, mark all the processes that 130 // need to be initialized as ready to run. --- 22 unchanged lines hidden --- |