gem5  v22.1.0.0
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
ISA-specific types for hardware transactional memory.
std::array< VecPredRegContainer, NumVecRegs > p
Definition: htm.hh:79
void save(ThreadContext *tc) override
Every ISA implementing HTM support should override the save method.
Definition: htm.cc:72
std::array< VecRegContainer, NumVecRegs > z
Definition: htm.hh:78
void reset() override
Resets the checkpoint once a transaction has completed.
Definition: htm.cc:48
std::array< RegVal, int_reg::NumArchRegs > x
Definition: htm.hh:77
void restore(ThreadContext *tc, HtmFailureFaultCause cause) override
Every ISA implementing HTM support should override the restore method.
Definition: htm.cc:95
virtual void restore(ThreadContext *tc, HtmFailureFaultCause cause)
Every ISA implementing HTM support should override the restore method.
Definition: htm.hh:169
virtual void save(ThreadContext *tc)
Every ISA implementing HTM support should override the save method.
Definition: htm.hh:154
virtual void reset()
Resets the checkpoint once a transaction has completed.
Definition: htm.hh:213
Target & as()
Definition: pcstate.hh:72
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual RegVal readMiscReg(RegIndex misc_reg)=0
virtual void setMiscReg(RegIndex misc_reg, RegVal val)=0
virtual RegVal getReg(const RegId &reg) const
virtual const PCStateBase & pcState() const =0
virtual void setReg(const RegId &reg, RegVal val)
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
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:197
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
constexpr RegId Spx
Definition: int.hh:238
Bitfield< 31 > n
Definition: misc_types.hh:462
Bitfield< 15, 12 > rt
Definition: types.hh:115
const int NumVecPredRegs
Definition: vec.hh:84
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 11 > z
Definition: misc_types.hh:381
const int NumVecRegs
Definition: vec.hh:83
constexpr RegClass intRegClass
Definition: int.hh:173
constexpr RegClass vecPredRegClass
Definition: vec.hh:109
@ MISCREG_FPSR
Definition: misc.hh:627
@ MISCREG_FPCR
Definition: misc.hh:626
@ MISCREG_DAIF
Definition: misc.hh:625
@ MISCREG_NZCV
Definition: misc.hh:624
Bitfield< 9, 6 > daif
Definition: misc_types.hh:70
Bitfield< 0 > sp
Definition: misc_types.hh:75
constexpr RegClass vecRegClass
Definition: vec.hh:101
GenericISA::DelaySlotPCState< 4 > PCState
Definition: pcstate.hh:40
Bitfield< 4 > x
Definition: pagetable.hh:61
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
HtmFailureFaultCause
Definition: htm.hh:48

Generated on Wed Dec 21 2022 10:22:25 for gem5 by doxygen 1.9.1