2 * Copyright (c) 2020 ARM Limited
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.
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.
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.
38 #include "arch/arm/htm.hh"
39 #include "cpu/thread_context.hh"
42 ArmISA::HTMCheckpoint::reset()
54 for (auto i
= 0; i
< NumVecRegs
; ++i
) {
57 for (auto i
= 0; i
< NumVecPredRegs
; ++i
) {
60 pcstateckpt
= PCState();
62 BaseHTMCheckpoint::reset();
66 ArmISA::HTMCheckpoint::save(ThreadContext
*tc
)
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
);
72 daif
= tc
->readMiscReg(MISCREG_DAIF
);
73 for (auto n
= 0; n
< NumIntArchRegs
; n
++) {
74 x
[n
] = tc
->readIntReg(n
);
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
);
81 for (auto n
= 0; n
< NumVecPredRegs
; n
++) {
82 RegId idx
= RegId(VecPredRegClass
, n
);
83 p
[n
] = tc
->readVecPredReg(idx
);
85 fpcr
= tc
->readMiscReg(MISCREG_FPCR
);
86 fpsr
= tc
->readMiscReg(MISCREG_FPSR
);
87 pcstateckpt
= tc
->pcState();
89 BaseHTMCheckpoint::save(tc
);
93 ArmISA::HTMCheckpoint::restore(ThreadContext
*tc
, HtmFailureFaultCause cause
)
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
);
99 tc
->setMiscReg(MISCREG_DAIF
, daif
);
100 for (auto n
= 0; n
< NumIntArchRegs
; n
++) {
101 tc
->setIntReg(n
, x
[n
]);
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
]);
108 for (auto n
= 0; n
< NumVecPredRegs
; n
++) {
109 RegId idx
= RegId(VecPredRegClass
, n
);
110 tc
->setVecPredReg(idx
, p
[n
]);
112 tc
->setMiscReg(MISCREG_FPCR
, fpcr
);
113 tc
->setMiscReg(MISCREG_FPSR
, fpsr
);
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
119 bool interrupt
= false; // TODO get this from threadcontext
121 uint64_t error_code
= 0;
123 case HtmFailureFaultCause::EXPLICIT
:
124 replaceBits(error_code
, 14, 0, tcreason
);
125 replaceBits(error_code
, 16, 1);
126 retry
= bits(15, tcreason
);
128 case HtmFailureFaultCause::MEMORY
:
129 replaceBits(error_code
, 17, 1);
132 case HtmFailureFaultCause::OTHER
:
133 replaceBits(error_code
, 18, 1);
135 case HtmFailureFaultCause::EXCEPTION
:
136 replaceBits(error_code
, 19, 1);
138 case HtmFailureFaultCause::SIZE
:
139 replaceBits(error_code
, 20, 1);
141 case HtmFailureFaultCause::NEST
:
142 replaceBits(error_code
, 21, 1);
144 // case HtmFailureFaultCause_DEBUG:
145 // replaceBits(error_code, 22, 1);
148 panic("Unknown HTM failure reason\n");
150 assert(!retry
|| !interrupt
);
152 replaceBits(error_code
, 15, 1);
154 replaceBits(error_code
, 23, 1);
155 tc
->setIntReg(rt
, error_code
);
158 pcstateckpt
.uReset();
159 pcstateckpt
.advance();
160 tc
->pcState(pcstateckpt
);
162 BaseHTMCheckpoint::restore(tc
, cause
);