47 uint64_t ptr,
bool data)
53 assert (s1_el ==
EL1 || s1_el ==
EL2);
56 bool b55 =
bits(ptr, 55) == 1;
58 tbi = b55 ? tcr.tbi1 == 1 : tcr.tbi0 == 1;
60 tbi = b55 ? (tcr.tbi1 == 1 && tcr.tbid1 == 0) :
61 (tcr.tbi0 == 1 && tcr.tbid0 == 0);
66 tbi =
data ? tcr.tbi == 1 : (tcr.tbi == 1 && tcr.tbid == 0);
70 tbi =
data ? tcr.tbi == 1 : (tcr.tbi == 1 && tcr.tbid == 0);
83 assert (s1_el ==
EL1 || s1_el ==
EL2);
87 tsz_field = top_bit ? (uint32_t)tcr.t1sz : (uint32_t)tcr.t0sz;
88 using64k = top_bit ? tcr.tg1 == 0x3 : tcr.tg0 == 0x1;
93 tsz_field = top_bit? (uint32_t)tcr.t1sz : (uint32_t)tcr.t0sz;
94 using64k = top_bit ? tcr.tg1 == 0x3 : tcr.tg0 == 0x1;
99 tsz_field =
el ==
EL2 ? (uint32_t)tcr2.t0sz: (uint32_t)tcr3.t0sz;
100 using64k =
el ==
EL2 ? tcr2.tg0 == 0x1 : tcr3.tg0 == 0x1 ;
102 uint32_t max_limit_tsz_field = using64k ? 47 : 48;
103 tsz_field = std::min(tsz_field, max_limit_tsz_field);
106 uint32_t tszmin = (using64k && (bool)mm_fr2.varange) ? 12 : 16;
107 tsz_field = std::max(tsz_field, tszmin);
109 return (64-tsz_field);
116 target_el !=
EL0 && (target_el >=
currEL(tc)));
122 return std::make_shared<SecureMonitorTrap>(0x0, 0,
EC_TRAPPED_PAC);
130 uint64_t modifier, uint64_t k1, uint64_t
k0,
bool data)
138 int top_bit =
tbi ? 55 : 63;
139 bool b55 =
bits(ptr, 55);
140 bool b63 =
bits(ptr, 63);
149 assert (s1_el ==
EL1 || s1_el ==
EL2);
154 selbit = (tcr.tbi1 == 1 || tcr.tbi0 == 1) ? b55: b63;
156 selbit = ((tcr.tbi1 == 1 && tcr.tbid1 == 0)
157 || (tcr.tbi0 == 1 && tcr.tbid0 == 0)) ? b55 : b63;
164 selbit = (have_el2 &&
165 (tcr.tbi0 == 1 || tcr.tbi1 == 1))? b55: b63;
169 selbit = (have_el2 &&
170 ((tcr.tbi1 == 1 && tcr.tbid1 == 0) ||
171 (tcr.tbi0 == 1 && tcr.tbid0 == 0)))? b55: b63;
175 selbit =
tbi ? b55: b63;
182 uint32_t nbits = (top_bit+1) - bottom_PAC_bit;
183 uint64_t pacbits = ((uint64_t)0x1 << nbits) -1;
184 uint64_t
mask = pacbits << bottom_PAC_bit;
187 ext_ptr = ptr |
mask;
189 ext_ptr = ptr & ~
mask;
195 uint64_t
t =
bits(ptr, top_bit, bottom_PAC_bit);
196 if (
t != 0x0 &&
t != pacbits) {
197 PAC ^= ((uint64_t)0x1 << (top_bit-1));
203 result = ptr & 0xFF00000000000000;
206 result = PAC & 0xFF00000000000000;
209 uint64_t masked_PAC = PAC & 0x007FFFFFFFFFFFFF;
210 uint64_t pacbit_mask = ((uint64_t)0x1 << bottom_PAC_bit) -1;
211 uint64_t masked_ptr = ptr & pacbit_mask;
213 masked_PAC &= ~pacbit_mask;
214 result |= ((uint64_t)selbit << 55) | masked_PAC | masked_ptr;
222 uint64_t modifier, uint64_t k1, uint64_t
k0,
bool data,
227 uint64_t original_ptr;
230 bool selbit = (bool)
bits(ptr, 55);
234 uint32_t top_tbi =
tbi? 56: 64;
235 uint32_t nbits = top_tbi - bottom_PAC_bit;
236 uint64_t pacbits = ((uint64_t)0x1 << nbits) -1;
237 uint64_t
mask = (pacbits << bottom_PAC_bit);
240 original_ptr = ptr |
mask;
242 original_ptr = ptr & ~
mask;
250 uint64_t low_mask = ((uint64_t)0x1 << bottom_PAC_bit) -1;
252 uint64_t pac_mask = 0x007FFFFFFFFFFFFF & ~low_mask;
254 uint64_t masked_pac = PAC & pac_mask;
255 uint64_t masked_ptr = ptr & pac_mask;
258 if (masked_pac == masked_ptr) {
259 result = original_ptr;
261 uint64_t mask2= ~((uint64_t)0x3 << 53);
262 result = original_ptr & mask2;
263 result |= (uint64_t)errorcode << 53;
266 if ((masked_pac == masked_ptr) && ((PAC >>56)==(ptr >> 56))) {
267 result = original_ptr;
269 uint64_t mask2 = ~((uint64_t)0x3 << 61);
270 result = original_ptr & mask2;
271 result |= (uint64_t)errorcode << 61;
288 bool trapEL2 =
false;
289 bool trapEL3 =
false;
308 enable = IsEL1Regime ? (bool)sc1.enda : (
bool)
sc2.enda;
310 (hcr.tge == 0 || hcr.e2h == 0));
311 trapEL3 = have_el3 && scr3.api == 0;
317 trapEL3 = have_el3 && scr3.api == 0;
322 trapEL3 = have_el3 && scr3.api == 0;
340 *out =
auth(tc,
el,
X, Y, hi_key, lo_key,
true, 0x1);
356 bool trapEL2 =
false;
357 bool trapEL3 =
false;
377 enable = IsEL1Regime ? (bool)sc1.endb : (
bool)
sc2.endb;
379 (hcr.tge == 0 || hcr.e2h == 0));
380 trapEL3 = have_el3 && scr3.api == 0;
386 trapEL3 = have_el3 && scr3.api == 0;
391 trapEL3 = have_el3 && scr3.api == 0;
409 *out =
auth(tc,
el,
X, Y, hi_key, lo_key,
true, 0x2);
426 bool trapEL2 =
false;
427 bool trapEL3 =
false;
446 enable = IsEL1Regime ? (bool)sc1.enia : (
bool)
sc2.enia;
448 (hcr.tge == 0 || hcr.e2h == 0));
449 trapEL3 = have_el3 && scr3.api == 0;
456 trapEL3 = have_el3 && scr3.api == 0;
463 trapEL3 = have_el3 && scr3.api == 0;
484 *out =
auth(tc,
el,
X, Y, hi_key, lo_key,
false, 0x1);
500 bool trapEL2 =
false;
501 bool trapEL3 =
false;
520 enable = IsEL1Regime ? (bool)sc1.enib : (
bool)
sc2.enib;
522 (hcr.tge == 0 || hcr.e2h == 0));
523 trapEL3 = have_el3 && scr3.api == 0;
530 trapEL3 = have_el3 && scr3.api == 0;
537 trapEL3 = have_el3 && scr3.api == 0;
558 *out =
auth(tc,
el,
X, Y, hi_key, lo_key,
false, 0x2);
568 bool trapEL2 =
false;
569 bool trapEL3 =
false;
588 enable = IsEL1Regime ? (bool)sc1.enda : (
bool)
sc2.enda;
590 (hcr.tge == 0 || hcr.e2h == 0));
591 trapEL3 = have_el3 && scr3.api == 0;
598 trapEL3 = have_el3 && scr3.api == 0;
605 trapEL3 = have_el3 && scr3.api == 0;
623 *out =
addPAC(tc,
el,
X, Y, hi_key, lo_key,
true);
632 bool trapEL2 =
false;
633 bool trapEL3 =
false;
652 enable = IsEL1Regime ? (bool)sc1.endb : (
bool)
sc2.endb;
654 (hcr.tge == 0 || hcr.e2h == 0));
655 trapEL3 = have_el3 && scr3.api == 0;
661 trapEL3 = have_el3 && scr3.api == 0;
666 trapEL3 = have_el3 && scr3.api == 0;
684 *out =
addPAC(tc,
el,
X, Y, hi_key, lo_key,
true);
693 bool trapEL2 =
false;
694 bool trapEL3 =
false;
708 (hcr.tge == 0 || hcr.e2h == 0));
709 trapEL3 = have_el3 && sc3.api == 0;
713 trapEL3 = have_el3 && sc3.api == 0;
717 trapEL3 = have_el3 && sc3.api == 0;
740 bool trapEL2 =
false;
741 bool trapEL3 =
false;
760 enable = IsEL1Regime ? (bool)sc1.enia : (
bool)
sc2.enia;
762 (hcr.tge == 0 || hcr.e2h == 0));
763 trapEL3 = have_el3 && scr3.api == 0;
769 trapEL3 = have_el3 && scr3.api == 0;
774 trapEL3 = have_el3 && scr3.api == 0;
792 *out =
addPAC(tc,
el,
X, Y, hi_key, lo_key,
false);
799 bool trapEL2 =
false;
800 bool trapEL3 =
false;
819 enable = IsEL1Regime ? (bool)sc1.enib : (
bool)
sc2.enib;
821 (hcr.tge == 0 || hcr.e2h == 0));
822 trapEL3 = have_el3 && scr3.api == 0;
828 trapEL3 = have_el3 && scr3.api == 0;
833 trapEL3 = have_el3 && scr3.api == 0;
852 *out =
addPAC(tc,
el,
X, Y, hi_key, lo_key,
false);
861 bool trapEL2 =
false;
862 bool trapEL3 =
false;
869 bool selbit = (bool)
bits(A, 55);
872 int top_bit =
tbi ? 55 : 63;
873 uint32_t nbits = (top_bit+1) - bottom_PAC_bit;
874 uint64_t pacbits = ((uint64_t)0x1 << nbits) -1;
875 uint64_t
mask = pacbits << bottom_PAC_bit;
892 (hcr.tge == 0 || hcr.e2h == 0));
893 trapEL3 = have_el3 && scr3.api == 0;
897 trapEL3 = have_el3 && scr3.api == 0;
901 trapEL3 = have_el3 && scr3.api == 0;