46 using namespace ArmISA;
50 uint64_t ptr,
bool data)
56 assert (s1_el ==
EL1 || s1_el ==
EL2);
59 bool b55 =
bits(ptr, 55) == 1;
61 tbi = b55 ? tcr.tbi1 == 1 : tcr.tbi0 == 1;
63 tbi = b55 ? (tcr.tbi1 == 1 && tcr.tbid1 == 0) :
64 (tcr.tbi0 == 1 && tcr.tbid0 == 0);
69 tbi =
data ? tcr.tbi == 1 : (tcr.tbi == 1 && tcr.tbid == 0);
73 tbi =
data ? tcr.tbi == 1 : (tcr.tbi == 1 && tcr.tbid == 0);
86 assert (s1_el ==
EL1 || s1_el ==
EL2);
90 tsz_field = top_bit ? (uint32_t)tcr.t1sz : (uint32_t)tcr.t0sz;
91 using64k = top_bit ? tcr.tg1 == 0x3 : tcr.tg0 == 0x1;
96 tsz_field = top_bit? (uint32_t)tcr.t1sz : (uint32_t)tcr.t0sz;
97 using64k = top_bit ? tcr.tg1 == 0x3 : tcr.tg0 == 0x1;
102 tsz_field =
el ==
EL2 ? (uint32_t)tcr2.t0sz: (uint32_t)tcr3.t0sz;
103 using64k =
el ==
EL2 ? tcr2.tg0 == 0x1 : tcr3.tg0 == 0x1 ;
105 uint32_t max_limit_tsz_field = using64k ? 47 : 48;
106 tsz_field = std::min(tsz_field, max_limit_tsz_field);
109 uint32_t tszmin = (using64k && (bool)mm_fr2.varange) ? 12 : 16;
110 tsz_field = std::max(tsz_field, tszmin);
112 return (64-tsz_field);
119 target_el !=
EL0 && (target_el >=
currEL(tc)));
125 return std::make_shared<SecureMonitorTrap>(0x0, 0,
EC_TRAPPED_PAC);
133 uint64_t modifier, uint64_t k1, uint64_t
k0,
bool data)
141 int top_bit =
tbi ? 55 : 63;
142 bool b55 =
bits(ptr, 55);
143 bool b63 =
bits(ptr, 63);
152 assert (s1_el ==
EL1 || s1_el ==
EL2);
157 selbit = (tcr.tbi1 == 1 || tcr.tbi0 == 1) ? b55: b63;
159 selbit = ((tcr.tbi1 == 1 && tcr.tbid1 == 0)
160 || (tcr.tbi0 == 1 && tcr.tbid0 == 0)) ? b55 : b63;
167 selbit = (have_el2 &&
168 (tcr.tbi0 == 1 || tcr.tbi1 == 1))? b55: b63;
172 selbit = (have_el2 &&
173 ((tcr.tbi1 == 1 && tcr.tbid1 == 0) ||
174 (tcr.tbi0 == 1 && tcr.tbid0 == 0)))? b55: b63;
178 selbit =
tbi ? b55: b63;
185 uint32_t nbits = (top_bit+1) - bottom_PAC_bit;
186 uint64_t pacbits = ((uint64_t)0x1 << nbits) -1;
187 uint64_t
mask = pacbits << bottom_PAC_bit;
190 ext_ptr = ptr |
mask;
192 ext_ptr = ptr & ~
mask;
198 uint64_t
t =
bits(ptr, top_bit, bottom_PAC_bit);
199 if (
t != 0x0 &&
t != pacbits) {
200 PAC ^= ((uint64_t)0x1 << (top_bit-1));
206 result = ptr & 0xFF00000000000000;
209 result = PAC & 0xFF00000000000000;
212 uint64_t masked_PAC = PAC & 0x007FFFFFFFFFFFFF;
213 uint64_t pacbit_mask = ((uint64_t)0x1 << bottom_PAC_bit) -1;
214 uint64_t masked_ptr = ptr & pacbit_mask;
216 masked_PAC &= ~pacbit_mask;
217 result |= ((uint64_t)selbit << 55) | masked_PAC | masked_ptr;
225 uint64_t modifier, uint64_t k1, uint64_t
k0,
bool data,
230 uint64_t original_ptr;
233 bool selbit = (bool)
bits(ptr, 55);
237 uint32_t top_tbi =
tbi? 56: 64;
238 uint32_t nbits = top_tbi - bottom_PAC_bit;
239 uint64_t pacbits = ((uint64_t)0x1 << nbits) -1;
240 uint64_t
mask = (pacbits << bottom_PAC_bit);
243 original_ptr = ptr |
mask;
245 original_ptr = ptr & ~
mask;
253 uint64_t low_mask = ((uint64_t)0x1 << bottom_PAC_bit) -1;
255 uint64_t pac_mask = 0x007FFFFFFFFFFFFF & ~low_mask;
257 uint64_t masked_pac = PAC & pac_mask;
258 uint64_t masked_ptr = ptr & pac_mask;
261 if (masked_pac == masked_ptr) {
262 result = original_ptr;
264 uint64_t mask2= ~((uint64_t)0x3 << 53);
265 result = original_ptr & mask2;
266 result |= (uint64_t)errorcode << 53;
269 if ((masked_pac == masked_ptr) && ((PAC >>56)==(ptr >> 56))) {
270 result = original_ptr;
272 uint64_t mask2 = ~((uint64_t)0x3 << 61);
273 result = original_ptr & mask2;
274 result |= (uint64_t)errorcode << 61;
291 bool trapEL2 =
false;
292 bool trapEL3 =
false;
311 enable = IsEL1Regime ? (bool)sc1.enda : (
bool)
sc2.enda;
313 (hcr.tge == 0 || hcr.e2h == 0));
314 trapEL3 = have_el3 && scr3.api == 0;
320 trapEL3 = have_el3 && scr3.api == 0;
325 trapEL3 = have_el3 && scr3.api == 0;
343 *out =
auth(tc,
el,
X, Y, hi_key, lo_key,
true, 0x1);
359 bool trapEL2 =
false;
360 bool trapEL3 =
false;
380 enable = IsEL1Regime ? (bool)sc1.endb : (
bool)
sc2.endb;
382 (hcr.tge == 0 || hcr.e2h == 0));
383 trapEL3 = have_el3 && scr3.api == 0;
389 trapEL3 = have_el3 && scr3.api == 0;
394 trapEL3 = have_el3 && scr3.api == 0;
412 *out =
auth(tc,
el,
X, Y, hi_key, lo_key,
true, 0x2);
429 bool trapEL2 =
false;
430 bool trapEL3 =
false;
449 enable = IsEL1Regime ? (bool)sc1.enia : (
bool)
sc2.enia;
451 (hcr.tge == 0 || hcr.e2h == 0));
452 trapEL3 = have_el3 && scr3.api == 0;
459 trapEL3 = have_el3 && scr3.api == 0;
466 trapEL3 = have_el3 && scr3.api == 0;
487 *out =
auth(tc,
el,
X, Y, hi_key, lo_key,
false, 0x1);
503 bool trapEL2 =
false;
504 bool trapEL3 =
false;
523 enable = IsEL1Regime ? (bool)sc1.enib : (
bool)
sc2.enib;
525 (hcr.tge == 0 || hcr.e2h == 0));
526 trapEL3 = have_el3 && scr3.api == 0;
533 trapEL3 = have_el3 && scr3.api == 0;
540 trapEL3 = have_el3 && scr3.api == 0;
561 *out =
auth(tc,
el,
X, Y, hi_key, lo_key,
false, 0x2);
571 bool trapEL2 =
false;
572 bool trapEL3 =
false;
591 enable = IsEL1Regime ? (bool)sc1.enda : (
bool)
sc2.enda;
593 (hcr.tge == 0 || hcr.e2h == 0));
594 trapEL3 = have_el3 && scr3.api == 0;
601 trapEL3 = have_el3 && scr3.api == 0;
608 trapEL3 = have_el3 && scr3.api == 0;
626 *out =
addPAC(tc,
el,
X, Y, hi_key, lo_key,
true);
635 bool trapEL2 =
false;
636 bool trapEL3 =
false;
655 enable = IsEL1Regime ? (bool)sc1.endb : (
bool)
sc2.endb;
657 (hcr.tge == 0 || hcr.e2h == 0));
658 trapEL3 = have_el3 && scr3.api == 0;
664 trapEL3 = have_el3 && scr3.api == 0;
669 trapEL3 = have_el3 && scr3.api == 0;
687 *out =
addPAC(tc,
el,
X, Y, hi_key, lo_key,
true);
696 bool trapEL2 =
false;
697 bool trapEL3 =
false;
711 (hcr.tge == 0 || hcr.e2h == 0));
712 trapEL3 = have_el3 && sc3.api == 0;
716 trapEL3 = have_el3 && sc3.api == 0;
720 trapEL3 = have_el3 && sc3.api == 0;
743 bool trapEL2 =
false;
744 bool trapEL3 =
false;
763 enable = IsEL1Regime ? (bool)sc1.enia : (
bool)
sc2.enia;
765 (hcr.tge == 0 || hcr.e2h == 0));
766 trapEL3 = have_el3 && scr3.api == 0;
772 trapEL3 = have_el3 && scr3.api == 0;
777 trapEL3 = have_el3 && scr3.api == 0;
795 *out =
addPAC(tc,
el,
X, Y, hi_key, lo_key,
false);
802 bool trapEL2 =
false;
803 bool trapEL3 =
false;
822 enable = IsEL1Regime ? (bool)sc1.enib : (
bool)
sc2.enib;
824 (hcr.tge == 0 || hcr.e2h == 0));
825 trapEL3 = have_el3 && scr3.api == 0;
831 trapEL3 = have_el3 && scr3.api == 0;
836 trapEL3 = have_el3 && scr3.api == 0;
855 *out =
addPAC(tc,
el,
X, Y, hi_key, lo_key,
false);
864 bool trapEL2 =
false;
865 bool trapEL3 =
false;
872 bool selbit = (bool)
bits(A, 55);
875 int top_bit =
tbi ? 55 : 63;
876 uint32_t nbits = (top_bit+1) - bottom_PAC_bit;
877 uint64_t pacbits = ((uint64_t)0x1 << nbits) -1;
878 uint64_t
mask = pacbits << bottom_PAC_bit;
895 (hcr.tge == 0 || hcr.e2h == 0));
896 trapEL3 = have_el3 && scr3.api == 0;
900 trapEL3 = have_el3 && scr3.api == 0;
904 trapEL3 = have_el3 && scr3.api == 0;