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;
289 bool trapEL2 =
false;
290 bool trapEL3 =
false;
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);
357 bool trapEL2 =
false;
358 bool trapEL3 =
false;
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);
427 bool trapEL2 =
false;
428 bool trapEL3 =
false;
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);
501 bool trapEL2 =
false;
502 bool trapEL3 =
false;
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);
569 bool trapEL2 =
false;
570 bool trapEL3 =
false;
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);
633 bool trapEL2 =
false;
634 bool trapEL3 =
false;
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);
694 bool trapEL2 =
false;
695 bool trapEL3 =
false;
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;
741 bool trapEL2 =
false;
742 bool trapEL3 =
false;
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);
800 bool trapEL2 =
false;
801 bool trapEL3 =
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);
862 bool trapEL2 =
false;
863 bool trapEL3 =
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;