gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
htm.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include "arch/arm/htm.hh"
39 
40 #include "arch/arm/regs/int.hh"
41 #include "arch/arm/regs/misc.hh"
42 #include "cpu/thread_context.hh"
43 
44 namespace gem5
45 {
46 
47 void
49 {
50  rt = 0;
51  nPc = 0;
52  sp = 0;
53  fpcr = 0;
54  fpsr = 0;
55  iccPmrEl1 = 0;
56  nzcv = 0;
57  daif = 0;
58  tcreason = 0;
59  x.fill(0);
60  for (auto i = 0; i < NumVecRegs; ++i) {
61  z[i].zero();
62  }
63  for (auto i = 0; i < NumVecPredRegs; ++i) {
64  p[i].reset();
65  }
66  pcstateckpt = PCState();
67 
69 }
70 
71 void
73 {
74  sp = tc->getReg(int_reg::Spx);
75  // below should be enabled on condition that GICV3 is enabled
76  //tme_checkpoint->iccPmrEl1 = tc->readMiscReg(MISCREG_ICC_PMR_EL1);
77  nzcv = tc->readMiscReg(MISCREG_NZCV);
79  for (auto n = 0; n < int_reg::NumArchRegs; n++) {
80  x[n] = tc->getReg(intRegClass[n]);
81  }
82  // TODO first detect if FP is enabled at this EL
83  for (auto n = 0; n < NumVecRegs; n++)
84  tc->getReg(vecRegClass[n], &z[n]);
85  for (auto n = 0; n < NumVecPredRegs; n++)
86  tc->getReg(vecPredRegClass[n], &p[n]);
87  fpcr = tc->readMiscReg(MISCREG_FPCR);
88  fpsr = tc->readMiscReg(MISCREG_FPSR);
89  pcstateckpt = tc->pcState().as<PCState>();
90 
92 }
93 
94 void
96 {
97  tc->setReg(int_reg::Spx, sp);
98  // below should be enabled on condition that GICV3 is enabled
99  //tc->setMiscReg(MISCREG_ICC_PMR_EL1, tme_checkpoint->iccPmrEl1);
100  tc->setMiscReg(MISCREG_NZCV, nzcv);
102  for (auto n = 0; n < int_reg::NumArchRegs; n++)
103  tc->setReg(intRegClass[n], x[n]);
104  // TODO first detect if FP is enabled at this EL
105  for (auto n = 0; n < NumVecRegs; n++)
106  tc->setReg(vecRegClass[n], &z[n]);
107  for (auto n = 0; n < NumVecPredRegs; n++)
108  tc->setReg(vecPredRegClass[n], &p[n]);
109  tc->setMiscReg(MISCREG_FPCR, fpcr);
110  tc->setMiscReg(MISCREG_FPSR, fpsr);
111 
112  // this code takes the generic HTM failure reason
113  // and prepares an Arm/TME-specific error code
114  // which is written to a destination register
115 
116  bool interrupt = false; // TODO get this from threadcontext
117  bool retry = false;
118  uint64_t error_code = 0;
119  switch (cause) {
121  replaceBits(error_code, 14, 0, tcreason);
122  replaceBits(error_code, 16, 1);
123  retry = bits(tcreason, 15);
124  break;
126  replaceBits(error_code, 17, 1);
127  retry = true;
128  break;
130  replaceBits(error_code, 18, 1);
131  break;
133  replaceBits(error_code, 19, 1);
134  break;
136  replaceBits(error_code, 20, 1);
137  break;
139  replaceBits(error_code, 21, 1);
140  break;
141  // case HtmFailureFaultCause_DEBUG:
142  // replaceBits(error_code, 22, 1);
143  // break;
144  default:
145  panic("Unknown HTM failure reason\n");
146  }
147  assert(!retry || !interrupt);
148  if (retry)
149  replaceBits(error_code, 15, 1);
150  if (interrupt)
151  replaceBits(error_code, 23, 1);
152  tc->setReg(intRegClass[rt], error_code);
153 
154  // set next PC
155  pcstateckpt.uReset();
156  pcstateckpt.advance();
157  tc->pcState(pcstateckpt);
158 
159  BaseHTMCheckpoint::restore(tc, cause);
160 }
161 
162 } // namespace gem5
gem5::ArmISA::HTMCheckpoint::iccPmrEl1
uint32_t iccPmrEl1
Definition: htm.hh:84
gem5::HtmFailureFaultCause::NEST
@ NEST
gem5::ThreadContext::readMiscReg
virtual RegVal readMiscReg(RegIndex misc_reg)=0
gem5::ArmISA::HTMCheckpoint::nPc
Addr nPc
Definition: htm.hh:76
gem5::HtmFailureFaultCause
HtmFailureFaultCause
Definition: htm.hh:47
gem5::ArmISA::NumVecRegs
const int NumVecRegs
Definition: vec.hh:83
gem5::HtmFailureFaultCause::MEMORY
@ MEMORY
gem5::ThreadContext::getReg
virtual RegVal getReg(const RegId &reg) const
Definition: thread_context.cc:180
gem5::ArmISA::MISCREG_NZCV
@ MISCREG_NZCV
Definition: misc.hh:625
gem5::PCStateBase::as
Target & as()
Definition: pcstate.hh:72
gem5::ArmISA::HTMCheckpoint::sp
Addr sp
Definition: htm.hh:80
gem5::ThreadContext::pcState
virtual const PCStateBase & pcState() const =0
gem5::ArmISA::HTMCheckpoint::save
void save(ThreadContext *tc) override
Every ISA implementing HTM support should override the save method.
Definition: htm.cc:72
gem5::replaceBits
constexpr void replaceBits(T &val, unsigned first, unsigned last, B bit_val)
A convenience function to replace bits first to last of val with bit_val in place.
Definition: bitfield.hh:213
gem5::ArmISA::MISCREG_DAIF
@ MISCREG_DAIF
Definition: misc.hh:626
gem5::ArmISA::daif
Bitfield< 9, 6 > daif
Definition: misc_types.hh:70
gem5::HtmFailureFaultCause::EXPLICIT
@ EXPLICIT
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::PowerISA::PCState
Definition: pcstate.hh:42
gem5::BaseHTMCheckpoint::restore
virtual void restore(ThreadContext *tc, HtmFailureFaultCause cause)
Every ISA implementing HTM support should override the restore method.
Definition: htm.hh:169
gem5::HtmFailureFaultCause::OTHER
@ OTHER
gem5::ArmISA::HTMCheckpoint::tcreason
uint16_t tcreason
Definition: htm.hh:81
gem5::HtmFailureFaultCause::EXCEPTION
@ EXCEPTION
htm.hh
gem5::MipsISA::float_reg::NumArchRegs
@ NumArchRegs
Definition: float.hh:79
gem5::ArmISA::NumVecPredRegs
const int NumVecPredRegs
Definition: vec.hh:84
gem5::ArmISA::z
Bitfield< 11 > z
Definition: misc_types.hh:431
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::ArmISA::rt
Bitfield< 15, 12 > rt
Definition: types.hh:115
gem5::MipsISA::PCState
GenericISA::DelaySlotPCState< 4 > PCState
Definition: pcstate.hh:40
gem5::VegaISA::x
Bitfield< 4 > x
Definition: pagetable.hh:61
gem5::ArmISA::intRegClass
constexpr RegClass intRegClass
Definition: int.hh:173
gem5::ArmISA::HTMCheckpoint::z
std::array< VecRegContainer, NumVecRegs > z
Definition: htm.hh:78
gem5::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:76
gem5::ArmISA::HTMCheckpoint::reset
void reset() override
Resets the checkpoint once a transaction has completed.
Definition: htm.cc:48
gem5::ArmISA::HTMCheckpoint::fpsr
uint32_t fpsr
Definition: htm.hh:83
gem5::ArmISA::vecRegClass
constexpr RegClass vecRegClass
Definition: vec.hh:101
gem5::ArmISA::HTMCheckpoint::x
std::array< RegVal, int_reg::NumArchRegs > x
Definition: htm.hh:77
gem5::ArmISA::HTMCheckpoint::nzcv
uint8_t nzcv
Definition: htm.hh:85
gem5::HtmFailureFaultCause::SIZE
@ SIZE
gem5::ArmISA::HTMCheckpoint::rt
uint8_t rt
Definition: htm.hh:75
gem5::BaseHTMCheckpoint::reset
virtual void reset()
Resets the checkpoint once a transaction has completed.
Definition: htm.hh:213
gem5::ArmISA::n
Bitfield< 31 > n
Definition: misc_types.hh:513
misc.hh
gem5::ThreadContext::setMiscReg
virtual void setMiscReg(RegIndex misc_reg, RegVal val)=0
gem5::ArmISA::HTMCheckpoint::fpcr
uint32_t fpcr
Definition: htm.hh:82
gem5::ArmISA::MISCREG_FPSR
@ MISCREG_FPSR
Definition: misc.hh:628
gem5::ArmISA::HTMCheckpoint::p
std::array< VecPredRegContainer, NumVecRegs > p
Definition: htm.hh:79
gem5::ArmISA::MISCREG_FPCR
@ MISCREG_FPCR
Definition: misc.hh:627
gem5::ArmISA::vecPredRegClass
constexpr RegClass vecPredRegClass
Definition: vec.hh:109
gem5::ArmISA::sp
Bitfield< 0 > sp
Definition: misc_types.hh:75
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::BaseHTMCheckpoint::save
virtual void save(ThreadContext *tc)
Every ISA implementing HTM support should override the save method.
Definition: htm.hh:154
gem5::ArmISA::HTMCheckpoint::pcstateckpt
PCState pcstateckpt
Definition: htm.hh:87
gem5::ArmISA::HTMCheckpoint::daif
uint8_t daif
Definition: htm.hh:86
int.hh
gem5::ArmISA::HTMCheckpoint::restore
void restore(ThreadContext *tc, HtmFailureFaultCause cause) override
Every ISA implementing HTM support should override the restore method.
Definition: htm.cc:95
thread_context.hh
gem5::ArmISA::int_reg::Spx
constexpr RegId Spx
Definition: int.hh:238
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188
gem5::ThreadContext::setReg
virtual void setReg(const RegId &reg, RegVal val)
Definition: thread_context.cc:188

Generated on Sun Jul 30 2023 01:56:48 for gem5 by doxygen 1.8.17