gem5  v21.0.1.0
thread_context.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2020 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 
29 
31 #include "arch/arm/utility.hh"
32 #include "iris/detail/IrisCppAdapter.h"
33 #include "iris/detail/IrisObjects.h"
34 
35 namespace FastModel
36 {
37 
39  ::BaseCPU *cpu, int id, System *system, ::BaseMMU *mmu,
40  ::BaseISA *isa, iris::IrisConnectionInterface *iris_if,
41  const std::string &iris_path) :
42  ThreadContext(cpu, id, system, mmu, isa, iris_if, iris_path)
43 {}
44 
45 bool
47 {
48  // Determine what memory spaces are currently active.
49  Iris::CanonicalMsn in_msn;
50  switch (ArmISA::currEL(this)) {
51  case ArmISA::EL3:
52  in_msn = Iris::SecureMonitorMsn;
53  break;
54  case ArmISA::EL2:
55  in_msn = Iris::NsHypMsn;
56  break;
57  default:
58  in_msn = Iris::GuestMsn;
59  break;
60  }
61 
62  Iris::CanonicalMsn out_msn = ArmISA::isSecure(this) ?
64 
65  // Figure out what memory spaces match the canonical numbers we need.
66  iris::MemorySpaceId in = iris::IRIS_UINT64_MAX;
67  iris::MemorySpaceId out = iris::IRIS_UINT64_MAX;
68 
69  for (auto &space: memorySpaces) {
70  if (space.canonicalMsn == in_msn)
71  in = space.spaceId;
72  else if (space.canonicalMsn == out_msn)
73  out = space.spaceId;
74  }
75 
76  panic_if(in == iris::IRIS_UINT64_MAX || out == iris::IRIS_UINT64_MAX,
77  "Canonical IRIS memory space numbers not found.");
78 
79  return ThreadContext::translateAddress(paddr, out, vaddr, in);
80 }
81 
82 void
84 {
85  pcRscId = extractResourceId(resources, "R15");
86 
89 }
90 
91 RegVal
93 {
94  iris::ResourceReadResult result;
95  call().resource_read(_instId, result, intReg32Ids.at(reg_idx));
96  return result.data.at(0);
97 }
98 
99 void
101 {
102  iris::ResourceWriteResult result;
103  call().resource_write(_instId, result, intReg32Ids.at(reg_idx), val);
104 }
105 
106 RegVal
108 {
110  switch (idx) {
111  case ArmISA::CCREG_NZ:
112  result = ((ArmISA::CPSR)result).nz;
113  break;
114  case ArmISA::CCREG_FP:
115  result = bits(result, 31, 28);
116  break;
117  default:
118  break;
119  }
120  return result;
121 }
122 
123 void
125 {
126  switch (idx) {
127  case ArmISA::CCREG_NZ:
128  {
129  ArmISA::CPSR cpsr = readMiscRegNoEffect(ArmISA::MISCREG_CPSR);
130  cpsr.nz = val;
131  val = cpsr;
132  }
133  break;
134  case ArmISA::CCREG_FP:
135  {
136  ArmISA::FPSCR fpscr = readMiscRegNoEffect(ArmISA::MISCREG_FPSCR);
137  val = insertBits(fpscr, 31, 28, val);
138  }
139  break;
140  default:
141  break;
142  }
144 }
145 
148 {
149  if (bpSpaceIds.empty()) {
150  for (auto &space: memorySpaces) {
151  auto cmsn = space.canonicalMsn;
152  if (cmsn == Iris::SecureMonitorMsn ||
153  cmsn == Iris::GuestMsn ||
154  cmsn == Iris::NsHypMsn ||
155  cmsn == Iris::HypAppMsn) {
156  bpSpaceIds.push_back(space.spaceId);
157  }
158  }
159  panic_if(bpSpaceIds.empty(),
160  "Unable to find address space(s) for breakpoints.");
161  }
162  return bpSpaceIds;
163 }
164 
166  { ArmISA::INTREG_R0, "R0" },
167  { ArmISA::INTREG_R1, "R1" },
168  { ArmISA::INTREG_R2, "R2" },
169  { ArmISA::INTREG_R3, "R3" },
170  { ArmISA::INTREG_R4, "R4" },
171  { ArmISA::INTREG_R5, "R5" },
172  { ArmISA::INTREG_R6, "R6" },
173  { ArmISA::INTREG_R7, "R7" },
174  { ArmISA::INTREG_R8, "R8" },
175  { ArmISA::INTREG_R9, "R9" },
176  { ArmISA::INTREG_R10, "R10" },
177  { ArmISA::INTREG_R11, "R11" },
178  { ArmISA::INTREG_R12, "R12" },
179  { ArmISA::INTREG_R13, "R13" },
180  { ArmISA::INTREG_R14, "R14" },
181  { ArmISA::INTREG_R15, "R15" }
182 });
183 
185  { ArmISA::CCREG_NZ, "CPSR" },
186  { ArmISA::CCREG_C, "CPSR.C" },
187  { ArmISA::CCREG_V, "CPSR.V" },
188  { ArmISA::CCREG_GE, "CPSR.GE" },
189  { ArmISA::CCREG_FP, "FPSCR" },
190 });
191 
193 
194 } // namespace FastModel
ArmISA::INTREG_R4
@ INTREG_R4
Definition: intregs.hh:58
insertBits
constexpr T insertBits(T val, unsigned first, unsigned last, B bit_val)
Returns val with bits first to last set to the LSBs of bit_val.
Definition: bitfield.hh:143
FastModel::CortexR52TC::readCCRegFlat
RegVal readCCRegFlat(RegIndex idx) const override
Definition: thread_context.cc:107
ArmISA::EL2
@ EL2
Definition: types.hh:624
FastModel::CortexR52TC::getBpSpaceIds
const std::vector< iris::MemorySpaceId > & getBpSpaceIds() const override
Definition: thread_context.cc:147
ArmISA::CCREG_NZ
@ CCREG_NZ
Definition: ccregs.hh:45
BaseMMU
Definition: mmu.hh:45
memory_spaces.hh
ArmISA::INTREG_R2
@ INTREG_R2
Definition: intregs.hh:56
ArmISA::INTREG_R8
@ INTREG_R8
Definition: intregs.hh:62
ArmISA::INTREG_R9
@ INTREG_R9
Definition: intregs.hh:63
Iris::ThreadContext::pcRscId
iris::ResourceId pcRscId
Definition: thread_context.hh:88
FastModel::CortexR52TC::CortexR52TC
CortexR52TC(::BaseCPU *cpu, int id, System *system, ::BaseMMU *mmu, ::BaseISA *isa, iris::IrisConnectionInterface *iris_if, const std::string &iris_path)
Definition: thread_context.cc:38
ArmISA::currEL
static ExceptionLevel currEL(const ThreadContext *tc)
Definition: utility.hh:131
Iris::ThreadContext::ccRegIds
ResourceIds ccRegIds
Definition: thread_context.hh:86
ArmISA::CCREG_V
@ CCREG_V
Definition: ccregs.hh:47
Iris::GuestMsn
@ GuestMsn
Definition: memory_spaces.hh:37
FastModel::CortexR52TC::readIntReg
RegVal readIntReg(RegIndex reg_idx) const override
Definition: thread_context.cc:92
std::vector< iris::MemorySpaceId >
ArmISA::EL3
@ EL3
Definition: types.hh:625
ArmISA::INTREG_R13
@ INTREG_R13
Definition: intregs.hh:67
FastModel::CortexR52TC::setCCRegFlat
void setCCRegFlat(RegIndex idx, RegVal val) override
Definition: thread_context.cc:124
Iris::ThreadContext::memorySpaces
std::vector< iris::MemorySpaceInfo > memorySpaces
Definition: thread_context.hh:94
ArmISA::CCREG_GE
@ CCREG_GE
Definition: ccregs.hh:48
Iris::SecureMonitorMsn
@ SecureMonitorMsn
Definition: memory_spaces.hh:36
Iris::PhysicalMemorySecureMsn
@ PhysicalMemorySecureMsn
Definition: memory_spaces.hh:44
FastModel::CortexR52TC::intReg32IdxNameMap
static IdxNameMap intReg32IdxNameMap
Definition: thread_context.hh:41
ArmISA::INTREG_R10
@ INTREG_R10
Definition: intregs.hh:64
ArmISA::CCREG_C
@ CCREG_C
Definition: ccregs.hh:46
X86ISA::system
Bitfield< 15 > system
Definition: misc.hh:997
FastModel::CortexR52TC::ccRegIdxNameMap
static IdxNameMap ccRegIdxNameMap
Definition: thread_context.hh:42
FastModel::CortexR52TC::readMiscRegNoEffect
RegVal readMiscRegNoEffect(RegIndex) const override
Definition: thread_context.hh:73
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
ArmISA::INTREG_R0
@ INTREG_R0
Definition: intregs.hh:54
ArmISA::INTREG_R6
@ INTREG_R6
Definition: intregs.hh:60
System
Definition: system.hh:73
MipsISA::vaddr
vaddr
Definition: pra_constants.hh:275
ArmISA::INTREG_R1
@ INTREG_R1
Definition: intregs.hh:55
ArmISA::INTREG_R12
@ INTREG_R12
Definition: intregs.hh:66
thread_context.hh
ArmISA::INTREG_R14
@ INTREG_R14
Definition: intregs.hh:69
FastModel::CortexR52TC::bpSpaceIds
static std::vector< iris::MemorySpaceId > bpSpaceIds
Definition: thread_context.hh:43
ArmISA::INTREG_R7
@ INTREG_R7
Definition: intregs.hh:61
Iris::ThreadContext::readCCRegFlat
RegVal readCCRegFlat(RegIndex idx) const override
Definition: thread_context.cc:632
ArmISA::INTREG_R15
@ INTREG_R15
Definition: intregs.hh:71
Iris::ThreadContext::IdxNameMap
std::map< int, std::string > IdxNameMap
Definition: thread_context.hh:53
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
ArmISA::CCREG_FP
@ CCREG_FP
Definition: ccregs.hh:49
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
Iris::ThreadContext::call
iris::IrisCppAdapter & call() const
Definition: thread_context.hh:162
FastModel::CortexR52TC::initFromIrisInstance
void initFromIrisInstance(const ResourceMap &resources) override
Definition: thread_context.cc:83
Iris::ThreadContext::intReg32Ids
ResourceIds intReg32Ids
Definition: thread_context.hh:83
utility.hh
ArmISA::MISCREG_FPSCR
@ MISCREG_FPSCR
Definition: miscregs.hh:68
FastModel::CortexR52TC::translateAddress
bool translateAddress(Addr &paddr, Addr vaddr) override
Definition: thread_context.cc:46
BaseCPU
Definition: base.hh:104
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
ArmISA::MISCREG_CPSR
@ MISCREG_CPSR
Definition: miscregs.hh:57
FastModel
Definition: amba_from_tlm_bridge.cc:32
Iris::PhysicalMemoryNonSecureMsn
@ PhysicalMemoryNonSecureMsn
Definition: memory_spaces.hh:45
Iris::ThreadContext::extractResourceMap
void extractResourceMap(ResourceIds &ids, const ResourceMap &resources, const IdxNameMap &idx_names)
Definition: thread_context.cc:100
ArmISA::INTREG_R3
@ INTREG_R3
Definition: intregs.hh:57
RegIndex
uint16_t RegIndex
Definition: types.hh:52
Iris::HypAppMsn
@ HypAppMsn
Definition: memory_spaces.hh:40
Iris::ThreadContext::extractResourceId
iris::ResourceId extractResourceId(const ResourceMap &resources, const std::string &name)
Definition: thread_context.cc:93
bits
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:73
ArmISA::INTREG_R11
@ INTREG_R11
Definition: intregs.hh:65
Iris::ThreadContext::_instId
iris::InstanceId _instId
Definition: thread_context.hh:64
Iris::ThreadContext::ResourceMap
std::map< std::string, iris::ResourceInfo > ResourceMap
Definition: thread_context.hh:50
Iris::CanonicalMsn
CanonicalMsn
Definition: memory_spaces.hh:34
BaseISA
Definition: isa.hh:47
Iris::ThreadContext::setCCRegFlat
void setCCRegFlat(RegIndex idx, RegVal val) override
Definition: thread_context.cc:642
ArmISA::INTREG_R5
@ INTREG_R5
Definition: intregs.hh:59
RegVal
uint64_t RegVal
Definition: types.hh:174
Iris::NsHypMsn
@ NsHypMsn
Definition: memory_spaces.hh:38
ArmISA::id
Bitfield< 33 > id
Definition: miscregs_types.hh:247
ArmISA::isSecure
bool isSecure(ThreadContext *tc)
Definition: utility.cc:112
FastModel::CortexR52TC::setIntReg
void setIntReg(RegIndex reg_idx, RegVal val) override
Definition: thread_context.cc:100

Generated on Tue Jun 22 2021 15:28:19 for gem5 by doxygen 1.8.17