simple_thread.cc revision 360
12SN/A/*
28733Sgeoffrey.blake@arm.com * Copyright (c) 2003 The Regents of The University of Michigan
37338SAli.Saidi@ARM.com * All rights reserved.
47338SAli.Saidi@ARM.com *
57338SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without
67338SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are
77338SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright
87338SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer;
97338SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright
107338SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the
117338SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution;
127338SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its
137338SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from
141762SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272SN/A */
282SN/A
292SN/A#include <string>
302SN/A
312SN/A#include "cpu/base_cpu.hh"
322SN/A#include "cpu/exec_context.hh"
332SN/A
342SN/A#ifdef FULL_SYSTEM
352SN/A#include "sim/system.hh"
362SN/A#else
372SN/A#include "sim/process.hh"
382SN/A#endif
392665Ssaidi@eecs.umich.edu
402665Ssaidi@eecs.umich.eduusing namespace std;
412SN/A
422SN/A// constructor
438779Sgblack@eecs.umich.edu#ifdef FULL_SYSTEM
448779Sgblack@eecs.umich.eduExecContext::ExecContext(BaseCPU *_cpu, int _thread_num, System *_sys,
458779Sgblack@eecs.umich.edu                         AlphaItb *_itb, AlphaDtb *_dtb,
462439SN/A                         FunctionalMemory *_mem)
478779Sgblack@eecs.umich.edu    : _status(ExecContext::Unallocated),
488229Snate@binkert.org      kernelStats(this, _cpu), cpu(_cpu), thread_num(_thread_num),
496216Snate@binkert.org      cpu_id(-1), mem(_mem), itb(_itb), dtb(_dtb), system(_sys),
50146SN/A      memCtrl(_sys->memCtrl), physmem(_sys->physmem),
51146SN/A#ifdef FS_MEASURE
52146SN/A      swCtx(NULL),
53146SN/A#endif
54146SN/A      func_exe_insn(0), storeCondFailures(0)
55146SN/A{
566216Snate@binkert.org    memset(&regs, 0, sizeof(RegFile));
576658Snate@binkert.org}
588229Snate@binkert.org#else
591717SN/AExecContext::ExecContext(BaseCPU *_cpu, int _thread_num,
608887Sgeoffrey.blake@arm.com                         Process *_process, int _asid)
618887Sgeoffrey.blake@arm.com    : _status(ExecContext::Unallocated),
62146SN/A      cpu(_cpu), thread_num(_thread_num), cpu_id(-1),
631977SN/A      process(_process), mem(process->getMemory()), asid(_asid),
642683Sktlim@umich.edu      func_exe_insn(0), storeCondFailures(0)
651717SN/A{
66146SN/A}
672683Sktlim@umich.edu
688232Snate@binkert.orgExecContext::ExecContext(BaseCPU *_cpu, int _thread_num,
698232Snate@binkert.org                         FunctionalMemory *_mem, int _asid)
708232Snate@binkert.org    : cpu(_cpu), thread_num(_thread_num), process(0), mem(_mem), asid(_asid),
718779Sgblack@eecs.umich.edu      func_exe_insn(0), storeCondFailures(0)
723348Sbinkertn@umich.edu{
736105Ssteve.reinhardt@amd.com}
746216Snate@binkert.org#endif
752036SN/A
76146SN/A
778817Sgblack@eecs.umich.eduvoid
788793Sgblack@eecs.umich.eduExecContext::takeOverFrom(ExecContext *oldContext)
7956SN/A{
8056SN/A    // some things should already be set up
81695SN/A    assert(mem == oldContext->mem);
822901Ssaidi@eecs.umich.edu#ifdef FULL_SYSTEM
832SN/A    assert(system == oldContext->system);
842SN/A#else
852449SN/A    assert(process == oldContext->process);
861355SN/A#endif
875529Snate@binkert.org
889023Sgblack@eecs.umich.edu    // copy over functional state
89224SN/A    _status = oldContext->_status;
908793Sgblack@eecs.umich.edu#ifdef FULL_SYSTEM
918793Sgblack@eecs.umich.edu    kernelStats = oldContext->kernelStats;
928793Sgblack@eecs.umich.edu#endif
938820Sgblack@eecs.umich.edu    regs = oldContext->regs;
948820Sgblack@eecs.umich.edu    cpu_id = oldContext->cpu_id;
952SN/A    func_exe_insn = oldContext->func_exe_insn;
966029Ssteve.reinhardt@amd.com
972672Sktlim@umich.edu    storeCondFailures = 0;
982683Sktlim@umich.edu
992SN/A    oldContext->_status = ExecContext::Unallocated;
1008733Sgeoffrey.blake@arm.com}
1018733Sgeoffrey.blake@arm.com
1028733Sgeoffrey.blake@arm.com
1038733Sgeoffrey.blake@arm.comvoid
1048733Sgeoffrey.blake@arm.comExecContext::serialize(ostream &os)
1058733Sgeoffrey.blake@arm.com{
1068733Sgeoffrey.blake@arm.com    SERIALIZE_ENUM(_status);
1078733Sgeoffrey.blake@arm.com    regs.serialize(os);
1088733Sgeoffrey.blake@arm.com    // thread_num and cpu_id are deterministic from the config
1098733Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(func_exe_insn);
1108733Sgeoffrey.blake@arm.com}
1112SN/A
112334SN/A
1138834Satgutier@umich.eduvoid
1148834Satgutier@umich.eduExecContext::unserialize(Checkpoint *cp, const std::string &section)
115140SN/A{
116334SN/A    UNSERIALIZE_ENUM(_status);
1172SN/A    regs.unserialize(cp, section);
1182SN/A    // thread_num and cpu_id are deterministic from the config
1192SN/A    UNSERIALIZE_SCALAR(func_exe_insn);
1202680Sktlim@umich.edu}
1214377Sgblack@eecs.umich.edu
1225169Ssaidi@eecs.umich.edu
1234377Sgblack@eecs.umich.eduvoid
1244377Sgblack@eecs.umich.eduExecContext::setStatus(Status new_status)
1252SN/A{
1262SN/A#ifdef FULL_SYSTEM
1272623SN/A    if (status() == new_status)
1282SN/A        return;
1292SN/A
1302SN/A    // Don't change the status from active if there are pending interrupts
131180SN/A    if (new_status == Suspended && cpu->check_interrupts()) {
1328737Skoansin.tan@gmail.com        assert(status() == Active);
133393SN/A        return;
134393SN/A    }
135393SN/A#endif
136393SN/A
137384SN/A    _status = new_status;
138384SN/A    cpu->execCtxStatusChg(thread_num);
139393SN/A}
1408737Skoansin.tan@gmail.com
141393SN/Avoid
142393SN/AExecContext::regStats(const string &name)
143393SN/A{
144393SN/A#ifdef FULL_SYSTEM
145384SN/A    kernelStats.regStats(name + ".kern");
146189SN/A#endif
147189SN/A}
1482623SN/A