112839Sgabeblack@google.com/* 212839Sgabeblack@google.com * Copyright 2018 Google, Inc. 312839Sgabeblack@google.com * 412839Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512839Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612839Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712839Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812839Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912839Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012839Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112839Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212839Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312839Sgabeblack@google.com * this software without specific prior written permission. 1412839Sgabeblack@google.com * 1512839Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612839Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712839Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812839Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912839Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012839Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112839Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212839Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312839Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412839Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512839Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612839Sgabeblack@google.com * 2712839Sgabeblack@google.com * Authors: Gabe Black 2812839Sgabeblack@google.com */ 2912839Sgabeblack@google.com 3012839Sgabeblack@google.com#include "base/logging.hh" 3112993Sgabeblack@google.com#include "systemc/core/process.hh" 3212993Sgabeblack@google.com#include "systemc/core/process_types.hh" 3312993Sgabeblack@google.com#include "systemc/core/scheduler.hh" 3413288Sgabeblack@google.com#include "systemc/ext/channel/sc_in.hh" 3513288Sgabeblack@google.com#include "systemc/ext/channel/sc_inout.hh" 3613288Sgabeblack@google.com#include "systemc/ext/channel/sc_out.hh" 3713288Sgabeblack@google.com#include "systemc/ext/channel/sc_signal_in_if.hh" 3813317Sgabeblack@google.com#include "systemc/ext/core/messages.hh" 3913129Sgabeblack@google.com#include "systemc/ext/core/sc_main.hh" 4012993Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh" 4112839Sgabeblack@google.com#include "systemc/ext/core/sc_spawn.hh" 4212839Sgabeblack@google.com 4312993Sgabeblack@google.comnamespace sc_gem5 4412993Sgabeblack@google.com{ 4512993Sgabeblack@google.com 4612993Sgabeblack@google.comProcess * 4712993Sgabeblack@google.comspawnWork(ProcessFuncWrapper *func, const char *name, 4812993Sgabeblack@google.com const ::sc_core::sc_spawn_options *opts) 4912993Sgabeblack@google.com{ 5012993Sgabeblack@google.com bool method = false; 5112993Sgabeblack@google.com bool dontInitialize = false; 5212993Sgabeblack@google.com if (opts) { 5312993Sgabeblack@google.com if (opts->_spawnMethod) 5412993Sgabeblack@google.com method = true; 5512993Sgabeblack@google.com if (opts->_dontInitialize) 5612993Sgabeblack@google.com dontInitialize = true; 5712993Sgabeblack@google.com if (opts->_stackSize != -1) 5812993Sgabeblack@google.com warn("Ignoring request to set stack size.\n"); 5912993Sgabeblack@google.com } 6012993Sgabeblack@google.com 6112993Sgabeblack@google.com if (!name || name[0] == '\0') { 6212993Sgabeblack@google.com if (method) 6312993Sgabeblack@google.com name = ::sc_core::sc_gen_unique_name("method_p"); 6412993Sgabeblack@google.com else 6512993Sgabeblack@google.com name = ::sc_core::sc_gen_unique_name("thread_p"); 6612993Sgabeblack@google.com } 6712993Sgabeblack@google.com 6812993Sgabeblack@google.com Process *proc; 6912993Sgabeblack@google.com if (method) 7013131Sgabeblack@google.com proc = new Method(name, func); 7112993Sgabeblack@google.com else 7213131Sgabeblack@google.com proc = new Thread(name, func); 7312993Sgabeblack@google.com 7413194Sgabeblack@google.com proc->dontInitialize(dontInitialize); 7513194Sgabeblack@google.com 7612993Sgabeblack@google.com if (opts) { 7712993Sgabeblack@google.com for (auto e: opts->_events) 7813207Sgabeblack@google.com newStaticSensitivityEvent(proc, e); 7912993Sgabeblack@google.com 8012993Sgabeblack@google.com for (auto p: opts->_ports) 8113207Sgabeblack@google.com newStaticSensitivityPort(proc, p); 8212993Sgabeblack@google.com 8312993Sgabeblack@google.com for (auto e: opts->_exports) 8413207Sgabeblack@google.com newStaticSensitivityExport(proc, e); 8512993Sgabeblack@google.com 8612993Sgabeblack@google.com for (auto i: opts->_interfaces) 8713207Sgabeblack@google.com newStaticSensitivityInterface(proc, i); 8812993Sgabeblack@google.com 8912993Sgabeblack@google.com for (auto f: opts->_finders) 9013207Sgabeblack@google.com newStaticSensitivityFinder(proc, f); 9113260Sgabeblack@google.com 9213260Sgabeblack@google.com for (auto p: opts->_in_resets) 9313288Sgabeblack@google.com newReset(p.target, proc, p.sync, p.value); 9413260Sgabeblack@google.com 9513260Sgabeblack@google.com for (auto p: opts->_inout_resets) 9613288Sgabeblack@google.com newReset(p.target, proc, p.sync, p.value); 9713260Sgabeblack@google.com 9813260Sgabeblack@google.com for (auto p: opts->_out_resets) 9913288Sgabeblack@google.com newReset(p.target, proc, p.sync, p.value); 10013260Sgabeblack@google.com 10113260Sgabeblack@google.com for (auto i: opts->_if_resets) 10213288Sgabeblack@google.com newReset(i.target, proc, i.sync, i.value); 10312993Sgabeblack@google.com } 10412993Sgabeblack@google.com 10513180Sgabeblack@google.com if (opts && opts->_dontInitialize && 10613180Sgabeblack@google.com opts->_events.empty() && opts->_ports.empty() && 10713180Sgabeblack@google.com opts->_exports.empty() && opts->_interfaces.empty() && 10813180Sgabeblack@google.com opts->_finders.empty()) { 10913317Sgabeblack@google.com SC_REPORT_WARNING(sc_core::SC_ID_DISABLE_WILL_ORPHAN_PROCESS_, 11013180Sgabeblack@google.com proc->name()); 11113180Sgabeblack@google.com } 11213180Sgabeblack@google.com 11312993Sgabeblack@google.com scheduler.reg(proc); 11412993Sgabeblack@google.com 11512993Sgabeblack@google.com return proc; 11612993Sgabeblack@google.com} 11712993Sgabeblack@google.com 11812993Sgabeblack@google.com} // namespace sc_gem5 11912993Sgabeblack@google.com 12012839Sgabeblack@google.comnamespace sc_core 12112839Sgabeblack@google.com{ 12212839Sgabeblack@google.com 12312993Sgabeblack@google.comsc_spawn_options::sc_spawn_options() : 12412993Sgabeblack@google.com _spawnMethod(false), _dontInitialize(false), _stackSize(-1) 12512993Sgabeblack@google.com{} 12612839Sgabeblack@google.com 12712839Sgabeblack@google.com 12812839Sgabeblack@google.comvoid 12912839Sgabeblack@google.comsc_spawn_options::spawn_method() 13012839Sgabeblack@google.com{ 13112993Sgabeblack@google.com _spawnMethod = true; 13212839Sgabeblack@google.com} 13312839Sgabeblack@google.com 13412839Sgabeblack@google.comvoid 13512839Sgabeblack@google.comsc_spawn_options::dont_initialize() 13612839Sgabeblack@google.com{ 13712993Sgabeblack@google.com _dontInitialize = true; 13812839Sgabeblack@google.com} 13912839Sgabeblack@google.com 14012839Sgabeblack@google.comvoid 14112993Sgabeblack@google.comsc_spawn_options::set_stack_size(int ss) 14212839Sgabeblack@google.com{ 14312993Sgabeblack@google.com _stackSize = ss; 14412839Sgabeblack@google.com} 14512839Sgabeblack@google.com 14612839Sgabeblack@google.com 14712839Sgabeblack@google.comvoid 14812993Sgabeblack@google.comsc_spawn_options::set_sensitivity(const sc_event *e) 14912839Sgabeblack@google.com{ 15012993Sgabeblack@google.com _events.push_back(e); 15112839Sgabeblack@google.com} 15212839Sgabeblack@google.com 15312839Sgabeblack@google.comvoid 15412993Sgabeblack@google.comsc_spawn_options::set_sensitivity(sc_port_base *p) 15512839Sgabeblack@google.com{ 15612993Sgabeblack@google.com _ports.push_back(p); 15712839Sgabeblack@google.com} 15812839Sgabeblack@google.com 15912839Sgabeblack@google.comvoid 16012993Sgabeblack@google.comsc_spawn_options::set_sensitivity(sc_export_base *e) 16112839Sgabeblack@google.com{ 16212993Sgabeblack@google.com _exports.push_back(e); 16312839Sgabeblack@google.com} 16412839Sgabeblack@google.com 16512839Sgabeblack@google.comvoid 16612993Sgabeblack@google.comsc_spawn_options::set_sensitivity(sc_interface *i) 16712839Sgabeblack@google.com{ 16812993Sgabeblack@google.com _interfaces.push_back(i); 16912839Sgabeblack@google.com} 17012839Sgabeblack@google.com 17112839Sgabeblack@google.comvoid 17212993Sgabeblack@google.comsc_spawn_options::set_sensitivity(sc_event_finder *f) 17312839Sgabeblack@google.com{ 17412993Sgabeblack@google.com _finders.push_back(f); 17512839Sgabeblack@google.com} 17612839Sgabeblack@google.com 17712839Sgabeblack@google.com 17812839Sgabeblack@google.comvoid 17913260Sgabeblack@google.comsc_spawn_options::reset_signal_is(const sc_in<bool> &port, bool value) 18012839Sgabeblack@google.com{ 18113260Sgabeblack@google.com _in_resets.emplace_back(&port, value, true); 18212839Sgabeblack@google.com} 18312839Sgabeblack@google.com 18412839Sgabeblack@google.comvoid 18513260Sgabeblack@google.comsc_spawn_options::reset_signal_is(const sc_inout<bool> &port, bool value) 18612839Sgabeblack@google.com{ 18713260Sgabeblack@google.com _inout_resets.emplace_back(&port, value, true); 18812839Sgabeblack@google.com} 18912839Sgabeblack@google.com 19012839Sgabeblack@google.comvoid 19113260Sgabeblack@google.comsc_spawn_options::reset_signal_is(const sc_out<bool> &port, bool value) 19212839Sgabeblack@google.com{ 19313260Sgabeblack@google.com _out_resets.emplace_back(&port, value, true); 19412839Sgabeblack@google.com} 19512839Sgabeblack@google.com 19612839Sgabeblack@google.comvoid 19713260Sgabeblack@google.comsc_spawn_options::reset_signal_is( 19813260Sgabeblack@google.com const sc_signal_in_if<bool> &iface, bool value) 19912839Sgabeblack@google.com{ 20013260Sgabeblack@google.com _if_resets.emplace_back(&iface, value, true); 20112839Sgabeblack@google.com} 20212839Sgabeblack@google.com 20312839Sgabeblack@google.com 20412839Sgabeblack@google.comvoid 20513260Sgabeblack@google.comsc_spawn_options::async_reset_signal_is(const sc_in<bool> &port, bool value) 20612839Sgabeblack@google.com{ 20713260Sgabeblack@google.com _in_resets.emplace_back(&port, value, false); 20812839Sgabeblack@google.com} 20912839Sgabeblack@google.com 21012839Sgabeblack@google.comvoid 21113260Sgabeblack@google.comsc_spawn_options::async_reset_signal_is(const sc_inout<bool> &port, bool value) 21212839Sgabeblack@google.com{ 21313260Sgabeblack@google.com _inout_resets.emplace_back(&port, value, false); 21412839Sgabeblack@google.com} 21512839Sgabeblack@google.com 21612839Sgabeblack@google.comvoid 21713260Sgabeblack@google.comsc_spawn_options::async_reset_signal_is(const sc_out<bool> &port, bool value) 21812839Sgabeblack@google.com{ 21913260Sgabeblack@google.com _out_resets.emplace_back(&port, value, false); 22012839Sgabeblack@google.com} 22112839Sgabeblack@google.com 22212839Sgabeblack@google.comvoid 22313260Sgabeblack@google.comsc_spawn_options::async_reset_signal_is( 22413260Sgabeblack@google.com const sc_signal_in_if<bool> &iface, bool value) 22512839Sgabeblack@google.com{ 22613260Sgabeblack@google.com _if_resets.emplace_back(&iface, value, false); 22712839Sgabeblack@google.com} 22812839Sgabeblack@google.com 22912839Sgabeblack@google.com} // namespace sc_core 230