sc_process_handle.cc revision 12994
112838Sgabeblack@google.com/* 212838Sgabeblack@google.com * Copyright 2018 Google, Inc. 312838Sgabeblack@google.com * 412838Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512838Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612838Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712838Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812838Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912838Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012838Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112838Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212838Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312838Sgabeblack@google.com * this software without specific prior written permission. 1412838Sgabeblack@google.com * 1512838Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612838Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712838Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812838Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912838Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012838Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112838Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212838Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312838Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412838Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512838Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612838Sgabeblack@google.com * 2712838Sgabeblack@google.com * Authors: Gabe Black 2812838Sgabeblack@google.com */ 2912838Sgabeblack@google.com 3012838Sgabeblack@google.com#include "base/logging.hh" 3112952Sgabeblack@google.com#include "systemc/core/process.hh" 3212953Sgabeblack@google.com#include "systemc/core/scheduler.hh" 3312960Sgabeblack@google.com#include "systemc/ext/core/sc_main.hh" 3412838Sgabeblack@google.com#include "systemc/ext/core/sc_process_handle.hh" 3512838Sgabeblack@google.com 3612838Sgabeblack@google.comnamespace sc_core 3712838Sgabeblack@google.com{ 3812838Sgabeblack@google.com 3912838Sgabeblack@google.comconst char * 4012838Sgabeblack@google.comsc_unwind_exception::what() const throw() 4112838Sgabeblack@google.com{ 4212994Sgabeblack@google.com return _isReset ? "RESET" : "KILL"; 4312838Sgabeblack@google.com} 4412838Sgabeblack@google.com 4512838Sgabeblack@google.combool 4612838Sgabeblack@google.comsc_unwind_exception::is_reset() const 4712838Sgabeblack@google.com{ 4812994Sgabeblack@google.com return _isReset; 4912838Sgabeblack@google.com} 5012838Sgabeblack@google.com 5112994Sgabeblack@google.comsc_unwind_exception::sc_unwind_exception() : _isReset(false) {} 5212994Sgabeblack@google.comsc_unwind_exception::sc_unwind_exception(const sc_unwind_exception &e) : 5312994Sgabeblack@google.com _isReset(e._isReset) 5412994Sgabeblack@google.com{} 5512952Sgabeblack@google.comsc_unwind_exception::~sc_unwind_exception() throw() {} 5612838Sgabeblack@google.com 5712838Sgabeblack@google.com 5812939Sgabeblack@google.comconst char * 5912939Sgabeblack@google.comsc_process_b::name() 6012939Sgabeblack@google.com{ 6112939Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 6212939Sgabeblack@google.com return ""; 6312939Sgabeblack@google.com} 6412939Sgabeblack@google.com 6512939Sgabeblack@google.comconst char * 6612939Sgabeblack@google.comsc_process_b::kind() 6712939Sgabeblack@google.com{ 6812939Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 6912939Sgabeblack@google.com return ""; 7012939Sgabeblack@google.com} 7112939Sgabeblack@google.com 7212939Sgabeblack@google.com 7312939Sgabeblack@google.comsc_process_b * 7412939Sgabeblack@google.comsc_get_curr_process_handle() 7512939Sgabeblack@google.com{ 7612939Sgabeblack@google.com warn("%s not implemented.\n", __PRETTY_FUNCTION__); 7712939Sgabeblack@google.com return nullptr; 7812939Sgabeblack@google.com} 7912939Sgabeblack@google.com 8012939Sgabeblack@google.com 8112952Sgabeblack@google.comsc_process_handle::sc_process_handle() : _gem5_process(nullptr) {} 8212952Sgabeblack@google.com 8312952Sgabeblack@google.comsc_process_handle::sc_process_handle(const sc_process_handle &handle) : 8412952Sgabeblack@google.com _gem5_process(handle._gem5_process) 8512838Sgabeblack@google.com{ 8612952Sgabeblack@google.com if (_gem5_process) 8712952Sgabeblack@google.com _gem5_process->incref(); 8812838Sgabeblack@google.com} 8912838Sgabeblack@google.com 9012952Sgabeblack@google.comsc_process_handle::sc_process_handle(sc_object *obj) : 9112952Sgabeblack@google.com _gem5_process(dynamic_cast<::sc_gem5::Process *>(obj)) 9212838Sgabeblack@google.com{ 9312952Sgabeblack@google.com if (_gem5_process) 9412952Sgabeblack@google.com _gem5_process->incref(); 9512838Sgabeblack@google.com} 9612838Sgabeblack@google.com 9712838Sgabeblack@google.comsc_process_handle::~sc_process_handle() 9812838Sgabeblack@google.com{ 9912952Sgabeblack@google.com if (_gem5_process) 10012952Sgabeblack@google.com _gem5_process->decref(); 10112838Sgabeblack@google.com} 10212838Sgabeblack@google.com 10312838Sgabeblack@google.com 10412838Sgabeblack@google.combool 10512838Sgabeblack@google.comsc_process_handle::valid() const 10612838Sgabeblack@google.com{ 10712952Sgabeblack@google.com return _gem5_process != nullptr; 10812838Sgabeblack@google.com} 10912838Sgabeblack@google.com 11012838Sgabeblack@google.com 11112838Sgabeblack@google.comsc_process_handle & 11212952Sgabeblack@google.comsc_process_handle::operator = (const sc_process_handle &handle) 11312838Sgabeblack@google.com{ 11412952Sgabeblack@google.com if (_gem5_process) 11512952Sgabeblack@google.com _gem5_process->decref(); 11612952Sgabeblack@google.com _gem5_process = handle._gem5_process; 11712952Sgabeblack@google.com if (_gem5_process) 11812952Sgabeblack@google.com _gem5_process->incref(); 11912838Sgabeblack@google.com return *this; 12012838Sgabeblack@google.com} 12112838Sgabeblack@google.com 12212838Sgabeblack@google.combool 12312952Sgabeblack@google.comsc_process_handle::operator == (const sc_process_handle &handle) const 12412838Sgabeblack@google.com{ 12512952Sgabeblack@google.com return _gem5_process && handle._gem5_process && 12612952Sgabeblack@google.com (_gem5_process == handle._gem5_process); 12712838Sgabeblack@google.com} 12812838Sgabeblack@google.com 12912838Sgabeblack@google.combool 13012952Sgabeblack@google.comsc_process_handle::operator != (const sc_process_handle &handle) const 13112838Sgabeblack@google.com{ 13212952Sgabeblack@google.com return !(handle == *this); 13312838Sgabeblack@google.com} 13412838Sgabeblack@google.com 13512838Sgabeblack@google.combool 13612952Sgabeblack@google.comsc_process_handle::operator < (const sc_process_handle &other) const 13712838Sgabeblack@google.com{ 13812952Sgabeblack@google.com return _gem5_process < other._gem5_process; 13912838Sgabeblack@google.com} 14012838Sgabeblack@google.com 14112952Sgabeblack@google.comvoid 14212952Sgabeblack@google.comsc_process_handle::swap(sc_process_handle &handle) 14312838Sgabeblack@google.com{ 14412952Sgabeblack@google.com ::sc_gem5::Process *temp = handle._gem5_process; 14512952Sgabeblack@google.com handle._gem5_process = _gem5_process; 14612952Sgabeblack@google.com _gem5_process = temp; 14712838Sgabeblack@google.com} 14812838Sgabeblack@google.com 14912838Sgabeblack@google.com 15012838Sgabeblack@google.comconst char * 15112838Sgabeblack@google.comsc_process_handle::name() const 15212838Sgabeblack@google.com{ 15312952Sgabeblack@google.com return _gem5_process ? _gem5_process->name() : ""; 15412838Sgabeblack@google.com} 15512838Sgabeblack@google.com 15612838Sgabeblack@google.comsc_curr_proc_kind 15712838Sgabeblack@google.comsc_process_handle::proc_kind() const 15812838Sgabeblack@google.com{ 15912952Sgabeblack@google.com return _gem5_process ? _gem5_process->procKind() : SC_NO_PROC_; 16012838Sgabeblack@google.com} 16112838Sgabeblack@google.com 16212838Sgabeblack@google.comconst std::vector<sc_object *> & 16312838Sgabeblack@google.comsc_process_handle::get_child_objects() const 16412838Sgabeblack@google.com{ 16512952Sgabeblack@google.com static const std::vector<sc_object *> empty; 16612952Sgabeblack@google.com return _gem5_process ? _gem5_process->get_child_objects() : empty; 16712838Sgabeblack@google.com} 16812838Sgabeblack@google.com 16912838Sgabeblack@google.comconst std::vector<sc_event *> & 17012838Sgabeblack@google.comsc_process_handle::get_child_events() const 17112838Sgabeblack@google.com{ 17212952Sgabeblack@google.com static const std::vector<sc_event *> empty; 17312952Sgabeblack@google.com return _gem5_process ? _gem5_process->get_child_events() : empty; 17412838Sgabeblack@google.com} 17512838Sgabeblack@google.com 17612838Sgabeblack@google.comsc_object * 17712838Sgabeblack@google.comsc_process_handle::get_parent_object() const 17812838Sgabeblack@google.com{ 17912952Sgabeblack@google.com return _gem5_process ? _gem5_process->get_parent_object() : nullptr; 18012838Sgabeblack@google.com} 18112838Sgabeblack@google.com 18212838Sgabeblack@google.comsc_object * 18312838Sgabeblack@google.comsc_process_handle::get_process_object() const 18412838Sgabeblack@google.com{ 18512952Sgabeblack@google.com return _gem5_process; 18612838Sgabeblack@google.com} 18712838Sgabeblack@google.com 18812838Sgabeblack@google.combool 18912838Sgabeblack@google.comsc_process_handle::dynamic() const 19012838Sgabeblack@google.com{ 19112952Sgabeblack@google.com return _gem5_process ? _gem5_process->dynamic() : false; 19212838Sgabeblack@google.com} 19312838Sgabeblack@google.com 19412838Sgabeblack@google.combool 19512838Sgabeblack@google.comsc_process_handle::terminated() const 19612838Sgabeblack@google.com{ 19712952Sgabeblack@google.com return _gem5_process ? _gem5_process->terminated() : false; 19812838Sgabeblack@google.com} 19912838Sgabeblack@google.com 20012838Sgabeblack@google.comconst sc_event & 20112838Sgabeblack@google.comsc_process_handle::terminated_event() const 20212838Sgabeblack@google.com{ 20312952Sgabeblack@google.com static sc_event non_event; 20412952Sgabeblack@google.com return _gem5_process ? _gem5_process->terminatedEvent() : non_event; 20512838Sgabeblack@google.com} 20612838Sgabeblack@google.com 20712838Sgabeblack@google.com 20812838Sgabeblack@google.comvoid 20912838Sgabeblack@google.comsc_process_handle::suspend(sc_descendent_inclusion_info include_descendants) 21012838Sgabeblack@google.com{ 21112952Sgabeblack@google.com if (!_gem5_process) 21212952Sgabeblack@google.com return; 21312952Sgabeblack@google.com _gem5_process->suspend(include_descendants == SC_INCLUDE_DESCENDANTS); 21412838Sgabeblack@google.com} 21512838Sgabeblack@google.com 21612838Sgabeblack@google.comvoid 21712838Sgabeblack@google.comsc_process_handle::resume(sc_descendent_inclusion_info include_descendants) 21812838Sgabeblack@google.com{ 21912952Sgabeblack@google.com if (!_gem5_process) 22012952Sgabeblack@google.com return; 22112952Sgabeblack@google.com _gem5_process->resume(include_descendants == SC_INCLUDE_DESCENDANTS); 22212838Sgabeblack@google.com} 22312838Sgabeblack@google.com 22412838Sgabeblack@google.comvoid 22512838Sgabeblack@google.comsc_process_handle::disable(sc_descendent_inclusion_info include_descendants) 22612838Sgabeblack@google.com{ 22712952Sgabeblack@google.com if (!_gem5_process) 22812952Sgabeblack@google.com return; 22912952Sgabeblack@google.com _gem5_process->disable(include_descendants == SC_INCLUDE_DESCENDANTS); 23012838Sgabeblack@google.com} 23112838Sgabeblack@google.com 23212838Sgabeblack@google.comvoid 23312838Sgabeblack@google.comsc_process_handle::enable(sc_descendent_inclusion_info include_descendants) 23412838Sgabeblack@google.com{ 23512952Sgabeblack@google.com if (!_gem5_process) 23612952Sgabeblack@google.com return; 23712952Sgabeblack@google.com _gem5_process->enable(include_descendants == SC_INCLUDE_DESCENDANTS); 23812838Sgabeblack@google.com} 23912838Sgabeblack@google.com 24012838Sgabeblack@google.comvoid 24112838Sgabeblack@google.comsc_process_handle::kill(sc_descendent_inclusion_info include_descendants) 24212838Sgabeblack@google.com{ 24312952Sgabeblack@google.com if (!_gem5_process) 24412952Sgabeblack@google.com return; 24512952Sgabeblack@google.com _gem5_process->kill(include_descendants == SC_INCLUDE_DESCENDANTS); 24612838Sgabeblack@google.com} 24712838Sgabeblack@google.com 24812838Sgabeblack@google.comvoid 24912838Sgabeblack@google.comsc_process_handle::reset(sc_descendent_inclusion_info include_descendants) 25012838Sgabeblack@google.com{ 25112952Sgabeblack@google.com if (!_gem5_process) 25212952Sgabeblack@google.com return; 25312952Sgabeblack@google.com _gem5_process->reset(include_descendants == SC_INCLUDE_DESCENDANTS); 25412838Sgabeblack@google.com} 25512838Sgabeblack@google.com 25612838Sgabeblack@google.combool 25712838Sgabeblack@google.comsc_process_handle::is_unwinding() 25812838Sgabeblack@google.com{ 25912952Sgabeblack@google.com if (!_gem5_process) { 26012952Sgabeblack@google.com //TODO This should generate a systemc style warning if the handle is 26112952Sgabeblack@google.com //invalid. 26212952Sgabeblack@google.com return false; 26312952Sgabeblack@google.com } else { 26412952Sgabeblack@google.com return _gem5_process->isUnwinding(); 26512952Sgabeblack@google.com } 26612838Sgabeblack@google.com} 26712838Sgabeblack@google.com 26812838Sgabeblack@google.comconst sc_event & 26912838Sgabeblack@google.comsc_process_handle::reset_event() const 27012838Sgabeblack@google.com{ 27112952Sgabeblack@google.com static sc_event non_event; 27212952Sgabeblack@google.com return _gem5_process ? _gem5_process->resetEvent() : non_event; 27312838Sgabeblack@google.com} 27412838Sgabeblack@google.com 27512838Sgabeblack@google.com 27612838Sgabeblack@google.comvoid 27712838Sgabeblack@google.comsc_process_handle::sync_reset_on( 27812838Sgabeblack@google.com sc_descendent_inclusion_info include_descendants) 27912838Sgabeblack@google.com{ 28012952Sgabeblack@google.com if (!_gem5_process) 28112952Sgabeblack@google.com return; 28212952Sgabeblack@google.com _gem5_process->syncResetOn(include_descendants == SC_INCLUDE_DESCENDANTS); 28312838Sgabeblack@google.com} 28412838Sgabeblack@google.com 28512838Sgabeblack@google.comvoid 28612838Sgabeblack@google.comsc_process_handle::sync_reset_off( 28712838Sgabeblack@google.com sc_descendent_inclusion_info include_descendants) 28812838Sgabeblack@google.com{ 28912952Sgabeblack@google.com if (!_gem5_process) 29012952Sgabeblack@google.com return; 29112952Sgabeblack@google.com _gem5_process->syncResetOff(include_descendants == SC_INCLUDE_DESCENDANTS); 29212838Sgabeblack@google.com} 29312838Sgabeblack@google.com 29412838Sgabeblack@google.com 29512838Sgabeblack@google.comsc_process_handle 29612838Sgabeblack@google.comsc_get_current_process_handle() 29712838Sgabeblack@google.com{ 29812960Sgabeblack@google.com if (sc_is_running()) 29912960Sgabeblack@google.com return sc_process_handle(::sc_gem5::scheduler.current()); 30012960Sgabeblack@google.com else 30112960Sgabeblack@google.com return sc_process_handle(::sc_gem5::Process::newest()); 30212838Sgabeblack@google.com} 30312838Sgabeblack@google.com 30412838Sgabeblack@google.combool 30512838Sgabeblack@google.comsc_is_unwinding() 30612838Sgabeblack@google.com{ 30712952Sgabeblack@google.com return sc_get_current_process_handle().is_unwinding(); 30812838Sgabeblack@google.com} 30912838Sgabeblack@google.com 31012899Sgabeblack@google.combool sc_allow_process_control_corners; 31112899Sgabeblack@google.com 31212838Sgabeblack@google.com} // namespace sc_core 313