gem5  v20.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 #include "cpu/thread_context.hh"
40 
41 void
43 {
44  rt = 0;
45  nPc = 0;
46  sp = 0;
47  fpcr = 0;
48  fpsr = 0;
49  iccPmrEl1 = 0;
50  nzcv = 0;
51  daif = 0;
52  tcreason = 0;
53  x.fill(0);
54  for (auto i = 0; i < NumVecRegs; ++i) {
55  z[i].zero();
56  }
57  for (auto i = 0; i < NumVecPredRegs; ++i) {
58  p[i].reset();
59  }
60  pcstateckpt = PCState();
61 
63 }
64 
65 void
67 {
68  sp = tc->readIntReg(INTREG_SPX);
69  // below should be enabled on condition that GICV3 is enabled
70  //tme_checkpoint->iccPmrEl1 = tc->readMiscReg(MISCREG_ICC_PMR_EL1);
71  nzcv = tc->readMiscReg(MISCREG_NZCV);
73  for (auto n = 0; n < NumIntArchRegs; n++) {
74  x[n] = tc->readIntReg(n);
75  }
76  // TODO first detect if FP is enabled at this EL
77  for (auto n = 0; n < NumVecRegs; n++) {
78  RegId idx = RegId(VecRegClass, n);
79  z[n] = tc->readVecReg(idx);
80  }
81  for (auto n = 0; n < NumVecPredRegs; n++) {
82  RegId idx = RegId(VecPredRegClass, n);
83  p[n] = tc->readVecPredReg(idx);
84  }
85  fpcr = tc->readMiscReg(MISCREG_FPCR);
86  fpsr = tc->readMiscReg(MISCREG_FPSR);
87  pcstateckpt = tc->pcState();
88 
90 }
91 
92 void
94 {
95  tc->setIntReg(INTREG_SPX, sp);
96  // below should be enabled on condition that GICV3 is enabled
97  //tc->setMiscReg(MISCREG_ICC_PMR_EL1, tme_checkpoint->iccPmrEl1);
98  tc->setMiscReg(MISCREG_NZCV, nzcv);
100  for (auto n = 0; n < NumIntArchRegs; n++) {
101  tc->setIntReg(n, x[n]);
102  }
103  // TODO first detect if FP is enabled at this EL
104  for (auto n = 0; n < NumVecRegs; n++) {
105  RegId idx = RegId(VecRegClass, n);
106  tc->setVecReg(idx, z[n]);
107  }
108  for (auto n = 0; n < NumVecPredRegs; n++) {
109  RegId idx = RegId(VecPredRegClass, n);
110  tc->setVecPredReg(idx, p[n]);
111  }
112  tc->setMiscReg(MISCREG_FPCR, fpcr);
113  tc->setMiscReg(MISCREG_FPSR, fpsr);
114 
115  // this code takes the generic HTM failure reason
116  // and prepares an Arm/TME-specific error code
117  // which is written to a destination register
118 
119  bool interrupt = false; // TODO get this from threadcontext
120  bool retry = false;
121  uint64_t error_code = 0;
122  switch (cause) {
124  replaceBits(error_code, 14, 0, tcreason);
125  replaceBits(error_code, 16, 1);
126  retry = bits(15, tcreason);
127  break;
129  replaceBits(error_code, 17, 1);
130  retry = true;
131  break;
133  replaceBits(error_code, 18, 1);
134  break;
136  replaceBits(error_code, 19, 1);
137  break;
139  replaceBits(error_code, 20, 1);
140  break;
142  replaceBits(error_code, 21, 1);
143  break;
144  // case HtmFailureFaultCause_DEBUG:
145  // replaceBits(error_code, 22, 1);
146  // break;
147  default:
148  panic("Unknown HTM failure reason\n");
149  }
150  assert(!retry || !interrupt);
151  if (retry)
152  replaceBits(error_code, 15, 1);
153  if (interrupt)
154  replaceBits(error_code, 23, 1);
155  tc->setIntReg(rt, error_code);
156 
157  // set next PC
158  pcstateckpt.uReset();
159  pcstateckpt.advance();
160  tc->pcState(pcstateckpt);
161 
162  BaseHTMCheckpoint::restore(tc, cause);
163 }
ThreadContext::readVecPredReg
virtual const VecPredRegContainer & readVecPredReg(const RegId &reg) const =0
ArmISA::NumIntArchRegs
const int NumIntArchRegs
Definition: registers.hh:81
ArmISA::HTMCheckpoint::daif
uint8_t daif
Definition: htm.hh:82
replaceBits
void replaceBits(T &val, int first, int last, B bit_val)
A convenience function to replace bits first to last of val with bit_val in place.
Definition: bitfield.hh:179
ArmISA::HTMCheckpoint::fpsr
uint32_t fpsr
Definition: htm.hh:79
ArmISA::daif
Bitfield< 9, 6 > daif
Definition: miscregs_types.hh:66
ArmISA::HTMCheckpoint::save
void save(ThreadContext *tc) override
Every ISA implementing HTM support should override the save method.
Definition: htm.cc:66
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
ArmISA::MISCREG_FPSR
@ MISCREG_FPSR
Definition: miscregs.hh:614
ThreadContext::setVecReg
virtual void setVecReg(const RegId &reg, const VecRegContainer &val)=0
ArmISA::MISCREG_DAIF
@ MISCREG_DAIF
Definition: miscregs.hh:612
ThreadContext::setIntReg
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
ArmISA::HTMCheckpoint::nzcv
uint8_t nzcv
Definition: htm.hh:81
ArmISA::HTMCheckpoint::pcstateckpt
PCState pcstateckpt
Definition: htm.hh:83
HtmFailureFaultCause
HtmFailureFaultCause
Definition: htm.hh:44
ArmISA::HTMCheckpoint::fpcr
uint32_t fpcr
Definition: htm.hh:78
ArmISA::rt
Bitfield< 15, 12 > rt
Definition: types.hh:124
RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
ArmISA::HTMCheckpoint::sp
Addr sp
Definition: htm.hh:76
ArmISA::n
Bitfield< 31 > n
Definition: miscregs_types.hh:450
ArmISA::INTREG_SPX
@ INTREG_SPX
Definition: intregs.hh:160
htm.hh
ArmISA::HTMCheckpoint::rt
uint8_t rt
Definition: htm.hh:71
HtmFailureFaultCause::OTHER
@ OTHER
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
HtmFailureFaultCause::EXCEPTION
@ EXCEPTION
HtmFailureFaultCause::EXPLICIT
@ EXPLICIT
ArmISA::z
Bitfield< 11 > z
Definition: miscregs_types.hh:370
ArmISA::HTMCheckpoint::x
std::array< RegVal, NumIntArchRegs > x
Definition: htm.hh:73
BaseHTMCheckpoint::restore
virtual void restore(ThreadContext *tc, HtmFailureFaultCause cause)
Every ISA implementing HTM support should override the restore method.
Definition: htm.hh:166
ThreadContext::readVecReg
virtual const VecRegContainer & readVecReg(const RegId &reg) const =0
ArmISA::NumVecPredRegs
const int NumVecPredRegs
Definition: registers.hh:98
RiscvISA::x
Bitfield< 3 > x
Definition: pagetable.hh:69
VecPredRegClass
@ VecPredRegClass
Definition: reg_class.hh:59
ArmISA::HTMCheckpoint::tcreason
uint16_t tcreason
Definition: htm.hh:77
ArmISA::sp
Bitfield< 0 > sp
Definition: miscregs_types.hh:71
ArmISA::HTMCheckpoint::reset
void reset() override
Resets the checkpoint once a transaction has completed.
Definition: htm.cc:42
ThreadContext::pcState
virtual TheISA::PCState pcState() const =0
HtmFailureFaultCause::NEST
@ NEST
ArmISA::HTMCheckpoint::p
std::array< VecPredRegContainer, NumVecRegs > p
Definition: htm.hh:75
VecRegClass
@ VecRegClass
Vector Register.
Definition: reg_class.hh:56
ArmISA::MISCREG_FPCR
@ MISCREG_FPCR
Definition: miscregs.hh:613
MipsISA::PCState
GenericISA::DelaySlotPCState< MachInst > PCState
Definition: types.hh:41
ArmISA::HTMCheckpoint::iccPmrEl1
uint32_t iccPmrEl1
Definition: htm.hh:80
ThreadContext::readMiscReg
virtual RegVal readMiscReg(RegIndex misc_reg)=0
ThreadContext::setMiscReg
virtual void setMiscReg(RegIndex misc_reg, RegVal val)=0
ThreadContext::setVecPredReg
virtual void setVecPredReg(const RegId &reg, const VecPredRegContainer &val)=0
BaseHTMCheckpoint::reset
virtual void reset()
Resets the checkpoint once a transaction has completed.
Definition: htm.hh:210
ArmISA::HTMCheckpoint::nPc
Addr nPc
Definition: htm.hh:72
BaseHTMCheckpoint::save
virtual void save(ThreadContext *tc)
Every ISA implementing HTM support should override the save method.
Definition: htm.hh:151
ArmISA::HTMCheckpoint::z
std::array< VecRegContainer, NumVecRegs > z
Definition: htm.hh:74
ArmISA::NumVecRegs
const int NumVecRegs
Definition: registers.hh:97
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
ArmISA::MISCREG_NZCV
@ MISCREG_NZCV
Definition: miscregs.hh:611
ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
ArmISA::HTMCheckpoint::restore
void restore(ThreadContext *tc, HtmFailureFaultCause cause) override
Every ISA implementing HTM support should override the restore method.
Definition: htm.cc:93
HtmFailureFaultCause::SIZE
@ SIZE
HtmFailureFaultCause::MEMORY
@ MEMORY
thread_context.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
bits
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:75

Generated on Wed Sep 30 2020 14:02:00 for gem5 by doxygen 1.8.17