48 uint64_t ptr,
bool data)
54 assert (s1_el ==
EL1 || s1_el ==
EL2);
57 bool b55 =
bits(ptr, 55) == 1;
59 tbi = b55 ? tcr.tbi1 == 1 : tcr.tbi0 == 1;
61 tbi = b55 ? (tcr.tbi1 == 1 && tcr.tbid1 == 0) :
62 (tcr.tbi0 == 1 && tcr.tbid0 == 0);
67 tbi = data ? tcr.tbi == 1 : (tcr.tbi == 1 && tcr.tbid == 0);
71 tbi = data ? tcr.tbi == 1 : (tcr.tbi == 1 && tcr.tbid == 0);
84 assert (s1_el ==
EL1 || s1_el ==
EL2);
88 tsz_field = top_bit ? (uint32_t)tcr.t1sz : (uint32_t)tcr.t0sz;
89 using64k = top_bit ? tcr.tg1 == 0x3 : tcr.tg0 == 0x1;
94 tsz_field = top_bit? (uint32_t)tcr.t1sz : (uint32_t)tcr.t0sz;
95 using64k = top_bit ? tcr.tg1 == 0x3 : tcr.tg0 == 0x1;
100 tsz_field = el ==
EL2 ? (uint32_t)tcr2.t0sz: (uint32_t)tcr3.t0sz;
101 using64k = el ==
EL2 ? tcr2.tg0 == 0x1 : tcr3.tg0 == 0x1 ;
103 uint32_t max_limit_tsz_field = using64k ? 47 : 48;
104 tsz_field = min(tsz_field, max_limit_tsz_field);
107 uint32_t tszmin = (using64k && (bool)mm_fr2.varange) ? 12 : 16;
108 tsz_field = max(tsz_field, tszmin);
110 return (64-tsz_field);
117 target_el !=
EL0 && (target_el >=
currEL(tc)));
123 return std::make_shared<SecureMonitorTrap>(0x0, 0,
EC_TRAPPED_PAC);
131 uint64_t modifier, uint64_t k1, uint64_t
k0,
bool data)
139 int top_bit = tbi ? 55 : 63;
140 bool b55 =
bits(ptr, 55);
141 bool b63 =
bits(ptr, 63);
150 assert (s1_el ==
EL1 || s1_el ==
EL2);
155 selbit = (tcr.tbi1 == 1 || tcr.tbi0 == 1) ? b55: b63;
157 selbit = ((tcr.tbi1 == 1 && tcr.tbid1 == 0)
158 || (tcr.tbi0 == 1 && tcr.tbid0 == 0)) ? b55 : b63;
165 selbit = (have_el2 &&
166 (tcr.tbi0 == 1 || tcr.tbi1 == 1))? b55: b63;
170 selbit = (have_el2 &&
171 ((tcr.tbi1 == 1 && tcr.tbid1 == 0) ||
172 (tcr.tbi0 == 1 && tcr.tbid0 == 0)))? b55: b63;
176 selbit = tbi ? b55: b63;
183 uint32_t nbits = (top_bit+1) - bottom_PAC_bit;
184 uint64_t pacbits = ((uint64_t)0x1 << nbits) -1;
185 uint64_t
mask = pacbits << bottom_PAC_bit;
188 ext_ptr = ptr |
mask;
190 ext_ptr = ptr & ~mask;
196 uint64_t
t =
bits(ptr, top_bit, bottom_PAC_bit);
197 if (t != 0x0 && t != pacbits) {
198 PAC ^= ((uint64_t)0x1 << (top_bit-1));
204 result = ptr & 0xFF00000000000000;
207 result = PAC & 0xFF00000000000000;
210 uint64_t masked_PAC = PAC & 0x007FFFFFFFFFFFFF;
211 uint64_t pacbit_mask = ((uint64_t)0x1 << bottom_PAC_bit) -1;
212 uint64_t masked_ptr = ptr & pacbit_mask;
214 masked_PAC &= ~pacbit_mask;
215 result |= ((uint64_t)selbit << 55) | masked_PAC | masked_ptr;
223 uint64_t modifier, uint64_t k1, uint64_t
k0,
bool data,
228 uint64_t original_ptr;
231 bool selbit = (bool)
bits(ptr, 55);
235 uint32_t top_tbi = tbi? 56: 64;
236 uint32_t nbits = top_tbi - bottom_PAC_bit;
237 uint64_t pacbits = ((uint64_t)0x1 << nbits) -1;
238 uint64_t
mask = (pacbits << bottom_PAC_bit);
241 original_ptr = ptr |
mask;
243 original_ptr = ptr & ~mask;
251 uint64_t low_mask = ((uint64_t)0x1 << bottom_PAC_bit) -1;
253 uint64_t pac_mask = 0x007FFFFFFFFFFFFF & ~low_mask;
255 uint64_t masked_pac = PAC & pac_mask;
256 uint64_t masked_ptr = ptr & pac_mask;
259 if (masked_pac == masked_ptr) {
260 result = original_ptr;
262 uint64_t mask2= ~((uint64_t)0x3 << 53);
263 result = original_ptr & mask2;
264 result |= (uint64_t)errorcode << 53;
267 if ((masked_pac == masked_ptr) && ((PAC >>56)==(ptr >> 56))) {
268 result = original_ptr;
270 uint64_t mask2 = ~((uint64_t)0x3 << 61);
271 result = original_ptr & mask2;
272 result |= (uint64_t)errorcode << 61;
309 enable = IsEL1Regime ? (bool)sc1.enda : (
bool)sc2.enda;
311 (hcr.tge == 0 || hcr.e2h == 0));
312 trapEL3 = have_el3 && scr3.api == 0;
318 trapEL3 = have_el3 && scr3.api == 0;
323 trapEL3 = have_el3 && scr3.api == 0;
341 *out =
auth(tc, el, X, Y, hi_key, lo_key,
true, 0x1);
378 enable = IsEL1Regime ? (bool)sc1.endb : (
bool)sc2.endb;
380 (hcr.tge == 0 || hcr.e2h == 0));
381 trapEL3 = have_el3 && scr3.api == 0;
387 trapEL3 = have_el3 && scr3.api == 0;
392 trapEL3 = have_el3 && scr3.api == 0;
410 *out =
auth(tc, el, X, Y, hi_key, lo_key,
true, 0x2);
447 enable = IsEL1Regime ? (bool)sc1.enia : (
bool)sc2.enia;
449 (hcr.tge == 0 || hcr.e2h == 0));
450 trapEL3 = have_el3 && scr3.api == 0;
457 trapEL3 = have_el3 && scr3.api == 0;
464 trapEL3 = have_el3 && scr3.api == 0;
485 *out =
auth(tc, el, X, Y, hi_key, lo_key,
false, 0x1);
521 enable = IsEL1Regime ? (bool)sc1.enib : (
bool)sc2.enib;
523 (hcr.tge == 0 || hcr.e2h == 0));
524 trapEL3 = have_el3 && scr3.api == 0;
531 trapEL3 = have_el3 && scr3.api == 0;
538 trapEL3 = have_el3 && scr3.api == 0;
559 *out =
auth(tc, el, X, Y, hi_key, lo_key,
false, 0x2);
589 enable = IsEL1Regime ? (bool)sc1.enda : (
bool)sc2.enda;
591 (hcr.tge == 0 || hcr.e2h == 0));
592 trapEL3 = have_el3 && scr3.api == 0;
599 trapEL3 = have_el3 && scr3.api == 0;
606 trapEL3 = have_el3 && scr3.api == 0;
624 *out =
addPAC(tc, el, X, Y, hi_key, lo_key,
true);
653 enable = IsEL1Regime ? (bool)sc1.endb : (
bool)sc2.endb;
655 (hcr.tge == 0 || hcr.e2h == 0));
656 trapEL3 = have_el3 && scr3.api == 0;
662 trapEL3 = have_el3 && scr3.api == 0;
667 trapEL3 = have_el3 && scr3.api == 0;
685 *out =
addPAC(tc, el, X, Y, hi_key, lo_key,
true);
709 (hcr.tge ==
'0' || hcr.e2h == 0));
710 trapEL3 = have_el3 && sc3.api == 0;
714 trapEL3 = have_el3 && sc3.api == 0;
718 trapEL3 = have_el3 && sc3.api == 0;
761 enable = IsEL1Regime ? (bool)sc1.enia : (
bool)sc2.enia;
763 (hcr.tge == 0 || hcr.e2h == 0));
764 trapEL3 = have_el3 && scr3.api == 0;
770 trapEL3 = have_el3 && scr3.api == 0;
775 trapEL3 = have_el3 && scr3.api == 0;
793 *out =
addPAC(tc, el, X, Y, hi_key, lo_key,
false);
820 enable = IsEL1Regime ? (bool)sc1.enib : (
bool)sc2.enib;
822 (hcr.tge == 0 || hcr.e2h == 0));
823 trapEL3 = have_el3 && scr3.api == 0;
829 trapEL3 = have_el3 && scr3.api == 0;
834 trapEL3 = have_el3 && scr3.api == 0;
853 *out =
addPAC(tc, el, X, Y, hi_key, lo_key,
false);
870 bool selbit = (bool)
bits(A, 55);
873 int top_bit = tbi ? 55 : 63;
874 uint32_t nbits = (top_bit+1) - bottom_PAC_bit;
875 uint64_t pacbits = ((uint64_t)0x1 << nbits) -1;
876 uint64_t
mask = pacbits << bottom_PAC_bit;
893 (hcr.tge == 0 || hcr.e2h == 0));
894 trapEL3 = have_el3 && scr3.api == 0;
898 trapEL3 = have_el3 && scr3.api == 0;
902 trapEL3 = have_el3 && scr3.api == 0;
Fault authIA(ThreadContext *tc, uint64_t X, uint64_t Y, uint64_t *out)
decltype(nullptr) constexpr NoFault
bool upperAndLowerRange(ThreadContext *tc, ExceptionLevel el)
Fault authIB(ThreadContext *tc, uint64_t X, uint64_t Y, uint64_t *out)
Overload hash function for BasicBlockRange type.
Fault addPACGA(ThreadContext *tc, uint64_t X, uint64_t Y, uint64_t *out)
Fault stripPAC(ThreadContext *tc, uint64_t A, bool data, uint64_t *out)
ThreadContext is the external interface to all thread state for anything outside of the CPU...
static ExceptionLevel currEL(const ThreadContext *tc)
static bool haveEL(ThreadContext *tc, ExceptionLevel el)
Return true if the system implements a specific exception level.
Fault addPACDA(ThreadContext *tc, uint64_t X, uint64_t Y, uint64_t *out)
ExceptionLevel s1TranslationRegime(ThreadContext *tc, ExceptionLevel el)
BIT64 computePAC(BIT64 data, BIT64 modifier, BIT64 key0, BIT64 key1)
Fault authDB(ThreadContext *tc, uint64_t X, uint64_t Y, uint64_t *out)
Fault addPACDB(ThreadContext *tc, uint64_t X, uint64_t Y, uint64_t *out)
int calculateBottomPACBit(ThreadContext *tc, ExceptionLevel el, bool top_bit)
uint64_t addPAC(ThreadContext *tc, ExceptionLevel el, uint64_t ptr, uint64_t modifier, uint64_t k1, uint64_t k0, bool data)
Fault trapPACUse(ThreadContext *tc, ExceptionLevel el)
bool calculateTBI(ThreadContext *tc, ExceptionLevel el, uint64_t ptr, bool data)
Fault addPACIB(ThreadContext *tc, uint64_t X, uint64_t Y, uint64_t *out)
uint64_t auth(ThreadContext *tc, ExceptionLevel el, uint64_t ptr, uint64_t modifier, uint64_t k1, uint64_t K0, bool data, uint8_t errorcode)
Fault addPACIA(ThreadContext *tc, uint64_t X, uint64_t Y, uint64_t *out)
Fault authDA(ThreadContext *tc, uint64_t X, uint64_t Y, uint64_t *out)
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
bool EL2Enabled(ThreadContext *tc)
virtual RegVal readMiscReg(RegIndex misc_reg)=0
std::shared_ptr< FaultBase > Fault