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 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 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 "base/logging.hh" 31#include "systemc/core/process.hh" 32#include "systemc/core/scheduler.hh" 33#include "systemc/ext/core/sc_main.hh" 34#include "systemc/ext/core/sc_process_handle.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 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution; 11 * neither the name of the copyright holders nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 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 "base/logging.hh" 31#include "systemc/core/process.hh" 32#include "systemc/core/scheduler.hh" 33#include "systemc/ext/core/sc_main.hh" 34#include "systemc/ext/core/sc_process_handle.hh"
|
| 35#include "systemc/ext/utils/sc_report_handler.hh"
|
35 36namespace sc_core 37{ 38 39const char * 40sc_unwind_exception::what() const throw() 41{ 42 return _isReset ? "RESET" : "KILL"; 43} 44 45bool 46sc_unwind_exception::is_reset() const 47{ 48 return _isReset; 49} 50 51sc_unwind_exception::sc_unwind_exception() : _isReset(false) {} 52sc_unwind_exception::sc_unwind_exception(const sc_unwind_exception &e) : 53 _isReset(e._isReset) 54{} 55sc_unwind_exception::~sc_unwind_exception() throw() {} 56 57 58void 59sc_set_location(const char *file, int lineno) 60{ 61 sc_process_b *current = ::sc_gem5::scheduler.current(); 62 if (!current) 63 return; 64 current->file = file; 65 current->lineno = lineno; 66} 67 68 69sc_process_b * 70sc_get_curr_process_handle() 71{ 72 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 73 return nullptr; 74} 75 76 77sc_process_handle::sc_process_handle() : _gem5_process(nullptr) {} 78 79sc_process_handle::sc_process_handle(const sc_process_handle &handle) : 80 _gem5_process(handle._gem5_process) 81{ 82 if (_gem5_process) 83 _gem5_process->incref(); 84} 85 86sc_process_handle::sc_process_handle(sc_object *obj) : 87 _gem5_process(dynamic_cast<::sc_gem5::Process *>(obj)) 88{ 89 if (_gem5_process) 90 _gem5_process->incref(); 91} 92 93sc_process_handle::~sc_process_handle() 94{ 95 if (_gem5_process) 96 _gem5_process->decref(); 97} 98 99 100bool 101sc_process_handle::valid() const 102{ 103 return _gem5_process != nullptr; 104} 105 106 107sc_process_handle & 108sc_process_handle::operator = (const sc_process_handle &handle) 109{ 110 if (_gem5_process) 111 _gem5_process->decref(); 112 _gem5_process = handle._gem5_process; 113 if (_gem5_process) 114 _gem5_process->incref(); 115 return *this; 116} 117 118bool 119sc_process_handle::operator == (const sc_process_handle &handle) const 120{ 121 return _gem5_process && handle._gem5_process && 122 (_gem5_process == handle._gem5_process); 123} 124 125bool 126sc_process_handle::operator != (const sc_process_handle &handle) const 127{ 128 return !(handle == *this); 129} 130 131bool 132sc_process_handle::operator < (const sc_process_handle &other) const 133{ 134 return _gem5_process < other._gem5_process; 135} 136 137void 138sc_process_handle::swap(sc_process_handle &handle) 139{ 140 ::sc_gem5::Process *temp = handle._gem5_process; 141 handle._gem5_process = _gem5_process; 142 _gem5_process = temp; 143} 144 145 146const char * 147sc_process_handle::name() const 148{ 149 return _gem5_process ? _gem5_process->name() : ""; 150} 151 152sc_curr_proc_kind 153sc_process_handle::proc_kind() const 154{ 155 return _gem5_process ? _gem5_process->procKind() : SC_NO_PROC_; 156} 157 158const std::vector<sc_object *> & 159sc_process_handle::get_child_objects() const 160{ 161 static const std::vector<sc_object *> empty; 162 return _gem5_process ? _gem5_process->get_child_objects() : empty; 163} 164 165const std::vector<sc_event *> & 166sc_process_handle::get_child_events() const 167{ 168 static const std::vector<sc_event *> empty; 169 return _gem5_process ? _gem5_process->get_child_events() : empty; 170} 171 172sc_object * 173sc_process_handle::get_parent_object() const 174{ 175 return _gem5_process ? _gem5_process->get_parent_object() : nullptr; 176} 177 178sc_object * 179sc_process_handle::get_process_object() const 180{ 181 return _gem5_process; 182} 183 184bool 185sc_process_handle::dynamic() const 186{ 187 return _gem5_process ? _gem5_process->dynamic() : false; 188} 189 190bool 191sc_process_handle::terminated() const 192{ 193 return _gem5_process ? _gem5_process->terminated() : false; 194} 195 196const sc_event & 197sc_process_handle::terminated_event() const 198{
| 36 37namespace sc_core 38{ 39 40const char * 41sc_unwind_exception::what() const throw() 42{ 43 return _isReset ? "RESET" : "KILL"; 44} 45 46bool 47sc_unwind_exception::is_reset() const 48{ 49 return _isReset; 50} 51 52sc_unwind_exception::sc_unwind_exception() : _isReset(false) {} 53sc_unwind_exception::sc_unwind_exception(const sc_unwind_exception &e) : 54 _isReset(e._isReset) 55{} 56sc_unwind_exception::~sc_unwind_exception() throw() {} 57 58 59void 60sc_set_location(const char *file, int lineno) 61{ 62 sc_process_b *current = ::sc_gem5::scheduler.current(); 63 if (!current) 64 return; 65 current->file = file; 66 current->lineno = lineno; 67} 68 69 70sc_process_b * 71sc_get_curr_process_handle() 72{ 73 warn("%s not implemented.\n", __PRETTY_FUNCTION__); 74 return nullptr; 75} 76 77 78sc_process_handle::sc_process_handle() : _gem5_process(nullptr) {} 79 80sc_process_handle::sc_process_handle(const sc_process_handle &handle) : 81 _gem5_process(handle._gem5_process) 82{ 83 if (_gem5_process) 84 _gem5_process->incref(); 85} 86 87sc_process_handle::sc_process_handle(sc_object *obj) : 88 _gem5_process(dynamic_cast<::sc_gem5::Process *>(obj)) 89{ 90 if (_gem5_process) 91 _gem5_process->incref(); 92} 93 94sc_process_handle::~sc_process_handle() 95{ 96 if (_gem5_process) 97 _gem5_process->decref(); 98} 99 100 101bool 102sc_process_handle::valid() const 103{ 104 return _gem5_process != nullptr; 105} 106 107 108sc_process_handle & 109sc_process_handle::operator = (const sc_process_handle &handle) 110{ 111 if (_gem5_process) 112 _gem5_process->decref(); 113 _gem5_process = handle._gem5_process; 114 if (_gem5_process) 115 _gem5_process->incref(); 116 return *this; 117} 118 119bool 120sc_process_handle::operator == (const sc_process_handle &handle) const 121{ 122 return _gem5_process && handle._gem5_process && 123 (_gem5_process == handle._gem5_process); 124} 125 126bool 127sc_process_handle::operator != (const sc_process_handle &handle) const 128{ 129 return !(handle == *this); 130} 131 132bool 133sc_process_handle::operator < (const sc_process_handle &other) const 134{ 135 return _gem5_process < other._gem5_process; 136} 137 138void 139sc_process_handle::swap(sc_process_handle &handle) 140{ 141 ::sc_gem5::Process *temp = handle._gem5_process; 142 handle._gem5_process = _gem5_process; 143 _gem5_process = temp; 144} 145 146 147const char * 148sc_process_handle::name() const 149{ 150 return _gem5_process ? _gem5_process->name() : ""; 151} 152 153sc_curr_proc_kind 154sc_process_handle::proc_kind() const 155{ 156 return _gem5_process ? _gem5_process->procKind() : SC_NO_PROC_; 157} 158 159const std::vector<sc_object *> & 160sc_process_handle::get_child_objects() const 161{ 162 static const std::vector<sc_object *> empty; 163 return _gem5_process ? _gem5_process->get_child_objects() : empty; 164} 165 166const std::vector<sc_event *> & 167sc_process_handle::get_child_events() const 168{ 169 static const std::vector<sc_event *> empty; 170 return _gem5_process ? _gem5_process->get_child_events() : empty; 171} 172 173sc_object * 174sc_process_handle::get_parent_object() const 175{ 176 return _gem5_process ? _gem5_process->get_parent_object() : nullptr; 177} 178 179sc_object * 180sc_process_handle::get_process_object() const 181{ 182 return _gem5_process; 183} 184 185bool 186sc_process_handle::dynamic() const 187{ 188 return _gem5_process ? _gem5_process->dynamic() : false; 189} 190 191bool 192sc_process_handle::terminated() const 193{ 194 return _gem5_process ? _gem5_process->terminated() : false; 195} 196 197const sc_event & 198sc_process_handle::terminated_event() const 199{
|
199 static sc_event non_event; 200 return _gem5_process ? _gem5_process->terminatedEvent() : non_event;
| 200 if (!_gem5_process) { 201 SC_REPORT_WARNING("(W570) attempt to use an empty " 202 "process handle ignored", "terminated_event()"); 203 static sc_event non_event; 204 return non_event; 205 } 206 return _gem5_process->terminatedEvent();
|
201} 202 203 204void 205sc_process_handle::suspend(sc_descendent_inclusion_info include_descendants) 206{
| 207} 208 209 210void 211sc_process_handle::suspend(sc_descendent_inclusion_info include_descendants) 212{
|
207 if (!_gem5_process)
| 213 if (!_gem5_process) { 214 SC_REPORT_WARNING("(W570) attempt to use an empty " 215 "process handle ignored", "suspend()");
|
208 return;
| 216 return;
|
| 217 }
|
209 _gem5_process->suspend(include_descendants == SC_INCLUDE_DESCENDANTS); 210} 211 212void 213sc_process_handle::resume(sc_descendent_inclusion_info include_descendants) 214{
| 218 _gem5_process->suspend(include_descendants == SC_INCLUDE_DESCENDANTS); 219} 220 221void 222sc_process_handle::resume(sc_descendent_inclusion_info include_descendants) 223{
|
215 if (!_gem5_process)
| 224 if (!_gem5_process) { 225 SC_REPORT_WARNING("(W570) attempt to use an empty " 226 "process handle ignored", "resume()");
|
216 return;
| 227 return;
|
| 228 }
|
217 _gem5_process->resume(include_descendants == SC_INCLUDE_DESCENDANTS); 218} 219 220void 221sc_process_handle::disable(sc_descendent_inclusion_info include_descendants) 222{
| 229 _gem5_process->resume(include_descendants == SC_INCLUDE_DESCENDANTS); 230} 231 232void 233sc_process_handle::disable(sc_descendent_inclusion_info include_descendants) 234{
|
223 if (!_gem5_process)
| 235 if (!_gem5_process) { 236 SC_REPORT_WARNING("(W570) attempt to use an empty " 237 "process handle ignored", "disable()");
|
224 return;
| 238 return;
|
| 239 }
|
225 _gem5_process->disable(include_descendants == SC_INCLUDE_DESCENDANTS); 226} 227 228void 229sc_process_handle::enable(sc_descendent_inclusion_info include_descendants) 230{
| 240 _gem5_process->disable(include_descendants == SC_INCLUDE_DESCENDANTS); 241} 242 243void 244sc_process_handle::enable(sc_descendent_inclusion_info include_descendants) 245{
|
231 if (!_gem5_process)
| 246 if (!_gem5_process) { 247 SC_REPORT_WARNING("(W570) attempt to use an empty " 248 "process handle ignored", "enable()");
|
232 return;
| 249 return;
|
| 250 }
|
233 _gem5_process->enable(include_descendants == SC_INCLUDE_DESCENDANTS); 234} 235 236void 237sc_process_handle::kill(sc_descendent_inclusion_info include_descendants) 238{
| 251 _gem5_process->enable(include_descendants == SC_INCLUDE_DESCENDANTS); 252} 253 254void 255sc_process_handle::kill(sc_descendent_inclusion_info include_descendants) 256{
|
239 if (!_gem5_process)
| 257 if (!_gem5_process) { 258 SC_REPORT_WARNING("(W570) attempt to use an empty " 259 "process handle ignored", "kill()");
|
240 return;
| 260 return;
|
| 261 }
|
241 _gem5_process->kill(include_descendants == SC_INCLUDE_DESCENDANTS); 242} 243 244void 245sc_process_handle::reset(sc_descendent_inclusion_info include_descendants) 246{
| 262 _gem5_process->kill(include_descendants == SC_INCLUDE_DESCENDANTS); 263} 264 265void 266sc_process_handle::reset(sc_descendent_inclusion_info include_descendants) 267{
|
247 if (!_gem5_process)
| 268 if (!_gem5_process) { 269 SC_REPORT_WARNING("(W570) attempt to use an empty " 270 "process handle ignored", "reset()");
|
248 return;
| 271 return;
|
| 272 }
|
249 _gem5_process->reset(include_descendants == SC_INCLUDE_DESCENDANTS); 250} 251 252bool 253sc_process_handle::is_unwinding() 254{ 255 if (!_gem5_process) {
| 273 _gem5_process->reset(include_descendants == SC_INCLUDE_DESCENDANTS); 274} 275 276bool 277sc_process_handle::is_unwinding() 278{ 279 if (!_gem5_process) {
|
256 //TODO This should generate a systemc style warning if the handle is 257 //invalid.
| 280 SC_REPORT_WARNING("(W570) attempt to use an empty " 281 "process handle ignored", "is_unwinding()");
|
258 return false;
| 282 return false;
|
259 } else { 260 return _gem5_process->isUnwinding();
| |
261 }
| 283 }
|
| 284 return _gem5_process->isUnwinding();
|
262} 263 264const sc_event & 265sc_process_handle::reset_event() const 266{
| 285} 286 287const sc_event & 288sc_process_handle::reset_event() const 289{
|
267 static sc_event non_event; 268 return _gem5_process ? _gem5_process->resetEvent() : non_event;
| 290 if (!_gem5_process) { 291 SC_REPORT_WARNING("(W570) attempt to use an empty " 292 "process handle ignored", "reset()"); 293 static sc_event non_event; 294 return non_event; 295 } 296 return _gem5_process->resetEvent();
|
269} 270 271 272void 273sc_process_handle::sync_reset_on( 274 sc_descendent_inclusion_info include_descendants) 275{
| 297} 298 299 300void 301sc_process_handle::sync_reset_on( 302 sc_descendent_inclusion_info include_descendants) 303{
|
276 if (!_gem5_process)
| 304 if (!_gem5_process) { 305 SC_REPORT_WARNING("(W570) attempt to use an empty " 306 "process handle ignored", "sync_reset_on()");
|
277 return;
| 307 return;
|
| 308 }
|
278 _gem5_process->syncResetOn(include_descendants == SC_INCLUDE_DESCENDANTS); 279} 280 281void 282sc_process_handle::sync_reset_off( 283 sc_descendent_inclusion_info include_descendants) 284{
| 309 _gem5_process->syncResetOn(include_descendants == SC_INCLUDE_DESCENDANTS); 310} 311 312void 313sc_process_handle::sync_reset_off( 314 sc_descendent_inclusion_info include_descendants) 315{
|
285 if (!_gem5_process)
| 316 if (!_gem5_process) { 317 SC_REPORT_WARNING("(W570) attempt to use an empty " 318 "process handle ignored", "sync_reset_off()");
|
286 return;
| 319 return;
|
| 320 }
|
287 _gem5_process->syncResetOff(include_descendants == SC_INCLUDE_DESCENDANTS); 288} 289 290 291sc_process_handle 292sc_get_current_process_handle() 293{ 294 if (sc_is_running()) 295 return sc_process_handle(::sc_gem5::scheduler.current()); 296 else 297 return sc_process_handle(::sc_gem5::Process::newest()); 298} 299 300bool 301sc_is_unwinding() 302{ 303 return sc_get_current_process_handle().is_unwinding(); 304} 305 306bool sc_allow_process_control_corners; 307 308} // namespace sc_core
| 321 _gem5_process->syncResetOff(include_descendants == SC_INCLUDE_DESCENDANTS); 322} 323 324 325sc_process_handle 326sc_get_current_process_handle() 327{ 328 if (sc_is_running()) 329 return sc_process_handle(::sc_gem5::scheduler.current()); 330 else 331 return sc_process_handle(::sc_gem5::Process::newest()); 332} 333 334bool 335sc_is_unwinding() 336{ 337 return sc_get_current_process_handle().is_unwinding(); 338} 339 340bool sc_allow_process_control_corners; 341 342} // namespace sc_core
|