[Writeup] Shared pseudocode: part 14 of 36 ========================================== Section: Silicon & Architectures Started: 2026-11-28 17:45 UTC by admin Replies: 0, last post 2026-11-28 17:45 UTC Page: 1 of 1 Web: https://romdump.net/t/106 ------------------------------------------------------------------------------ #126 admin, 2026-11-28 17:45 UTC [OP] Source: https://romdump.net/raw/126
Shared pseudocode from the offline Arm documentation snapshot. Part 14 of 36.
X{64}(memcpy.d) = memcpy.toaddress - copied;
X{64}(memcpy.s) = memcpy.fromaddress - copied;
end;
end;
end;
else
X{64}(memcpy.n) = memcpy.cpysize[63:0];
if memcpy.stage == MOPSStage_Prologue || !memcpy.implements_option_a then
X{64}(memcpy.d) = memcpy.toaddress;
X{64}(memcpy.s) = memcpy.fromaddress;
end;
end;
return;
end;
## Library pseudocode for aarch64/functions/mops/UpdateSetRegisters
// UpdateSetRegisters // ==================== // Performs updates to the X[n] and X[d] registers, as appropriate, for the SET* and SETG* // instructions. When fault is TRUE, the values correspond to the first element not set, such // that a return to the instruction will enable a resumption of the memory set.
func UpdateSetRegisters(memset : SETParams, fault : boolean, memory_set : integer) begin if fault then // Undo any formatting of the input parameters performed in the prologue. if memset.stage == MOPSStage_Prologue then if memset.implements_option_a then // setsize is negative. let setsize : integer = memset.setsize + memory_set; X{64}(memset.n) = (0 - setsize)[63:0]; X{64}(memset.d) = memset.toaddress + setsize; else X{64}(memset.n) = (memset.setsize - memory_set)[63:0]; X{64}(memset.d) = memset.toaddress + memory_set; end;
else
if memset.implements_option_a then
X{64}(memset.n) = (memset.setsize + memory_set)[63:0];
else
X{64}(memset.n) = (memset.setsize - memory_set)[63:0];
X{64}(memset.d) = memset.toaddress + memory_set;
end;
end;
else
X{64}(memset.n) = memset.setsize[63:0];
if memset.stage == MOPSStage_Prologue || !memset.implements_option_a then
X{64}(memset.d) = memset.toaddress;
end;
end;
return;
end;
## Library pseudocode for aarch64/functions/movewideop/MoveWideOp
// MoveWideOp // ========== // Move wide 16-bit immediate instruction types.
type MoveWideOp of enumeration {MoveWideOp_N, MoveWideOp_Z, MoveWideOp_K};
## Library pseudocode for aarch64/functions/movwpreferred/MoveWidePreferred
// MoveWidePreferred // =================== // // Return TRUE if a bitmask immediate encoding would generate an immediate // value that could also be represented by a single MOVZ or MOVN instruction. // Used as a condition for the preferred MOV<-ORR alias.
func MoveWidePreferred(sf : bit, immN : bit, imms : bits(6), immr : bits(6)) => boolean begin let s : integer = UInt(imms); let r : integer = UInt(immr); let width : integer = if sf == '1' then 64 else 32;
// element size must equal total immediate size
if sf == '1' && (immN::imms) != '1xxxxxx' then
return FALSE;
end;
if sf == '0' && (immN::imms) != '00xxxxx' then
return FALSE;
end;
// for MOVZ must contain no more than 16 ones
if s < 16 then
// ones must not span halfword boundary when rotated
return (-r MOD 16) <= (15 - s);
end;
// for MOVN must contain no more than 16 zeros
if s >= width - 15 then
// zeros must not span halfword boundary when rotated
return (r MOD 16) <= (s - (width - 15));
end;
return FALSE;
end;
## Library pseudocode for aarch64/functions/pac/addpac/AddPAC
// AddPAC // ======== // Calculates the pointer authentication code for a 64-bit quantity and then // inserts that into pointer authentication code field of that 64-bit quantity.
func AddPAC(ptr : bits(64), modifier : bits(64), K : bits(128), data : boolean) => bits(64) begin let use_modifier2 : boolean = FALSE; return InsertPAC(ptr, modifier, Zeros{64}, use_modifier2, K, data); end;
## Library pseudocode for aarch64/functions/pac/addpac/AddPAC2
// AddPAC2 // ========= // Calculates the pointer authentication code for a 64-bit quantity and then // inserts that into pointer authentication code field of that 64-bit quantity.
func AddPAC2(ptr : bits(64), modifier1 : bits(64), modifier2 : bits(64), K : bits(128), data : boolean) => bits(64) begin let use_modifier2 : boolean = TRUE; return InsertPAC(ptr, modifier1, modifier2, use_modifier2, K, data); end;
## Library pseudocode for aarch64/functions/pac/addpac/InsertPAC
// InsertPAC // =========== // Calculates the pointer authentication code for a 64-bit quantity and then // inserts that into pointer authentication code field of that 64-bit quantity.
func InsertPAC(ptr : bits(64), modifier : bits(64), modifier2 : bits(64), use_modifier2 : boolean, K : bits(128), data : boolean) => bits(64) begin var PAC : bits(64); var result : bits(64); var ext_ptr : bits(64); var extfield : bits(64); var selbit : bit; let tbi : boolean = EffectiveTBI(ptr, !data, PSTATE.EL) == '1'; let mtx : boolean = (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) && EffectiveMTX(ptr, !data, PSTATE.EL) == '1'); let top_bit : integer{} = if tbi then 55 else 63; let EL3_using_lva3 : boolean = (IsFeatureImplemented(FEAT_LVA3) && TranslationRegime(PSTATE.EL) == Regime_EL3 && AArch64_IASize(TCR_EL3().T0SZ) > 52); let is_VA_56bit : boolean = (TranslationRegime(PSTATE.EL) == Regime_EL3 && AArch64_IASize(TCR_EL3().T0SZ) == 56);
// If tagged pointers are in use for a regime with two TTBRs, use
bit[55] of
// the pointer to select between upper and lower ranges, and preserve this.
// This handles the awkward case where there is apparently no correct choice
between
// the upper and lower address range - ie an addr of 1xxxxxxx0... with TBI0=0
and TBI1=1
// and 0xxxxxxx1 with TBI1=0 and TBI0=1:
if PtrHasUpperAndLowerAddRanges() then
assert S1TranslationRegime() IN {EL1, EL2};
if S1TranslationRegime() == EL1 then
// EL1 translation regime registers
if data then
if TCR_EL1().TBI1 == '1' || TCR_EL1().TBI0 == '1' then
selbit = ptr[55];
else
selbit = ptr[63];
end;
else
if ((TCR_EL1().TBI1 == '1' && TCR_EL1().TBID1 == '0') ||
(TCR_EL1().TBI0 == '1' && TCR_EL1().TBID0 == '0')) then
selbit = ptr[55];
else
selbit = ptr[63];
end;
end;
else
// EL2 translation regime registers
if data then
if TCR_EL2().TBI1 == '1' || TCR_EL2().TBI0 == '1' then
selbit = ptr[55];
else
selbit = ptr[63];
end;
else
if ((TCR_EL2().TBI1 == '1' && TCR_EL2().TBID1 == '0') ||
(TCR_EL2().TBI0 == '1' && TCR_EL2().TBID0 == '0')) then
selbit = ptr[55];
else
selbit = ptr[63];
end;
end;
end;
else
selbit = if tbi then ptr[55] else ptr[63];
end;
if IsFeatureImplemented(FEAT_PAuth2) &&
IsFeatureImplemented(FEAT_CONSTPACFIELD) then
selbit = ptr[55];
end;
let bottom_PAC_bit : AddressSize = CalculateBottomPACBit(selbit);
if EL3_using_lva3 then
extfield = Replicate{64}('0');
else
extfield = Replicate{64}(selbit);
end;
// Compute the pointer authentication code for a ptr with good extension bits
if tbi then
if bottom_PAC_bit <= 55 then
ext_ptr = (ptr[63:56] ::
extfield[55:bottom_PAC_bit] :: ptr[bottom_PAC_bit-1:0]);
else
ext_ptr = ptr[63:56] :: ptr[55:0];
end;
elsif mtx then
if bottom_PAC_bit <= 55 then
ext_ptr = (extfield[63:60] :: ptr[59:56] ::
extfield[55:bottom_PAC_bit] :: ptr[bottom_PAC_bit-1:0]);
else
ext_ptr = extfield[63:60] :: ptr[59:56] :: ptr[55:0];
end;
else
ext_ptr = extfield[63:bottom_PAC_bit] :: ptr[bottom_PAC_bit-1:0];
end;
if use_modifier2 then
assert IsFeatureImplemented(FEAT_PAuth_LR);
PAC = ComputePAC2(ext_ptr, modifier, modifier2, K[127:64], K[63:0]);
else
PAC = ComputePAC(ext_ptr, modifier, K[127:64], K[63:0]);
end;
if !IsFeatureImplemented(FEAT_PAuth2) then
// If FEAT_PAuth2 is not implemented, the PAC is corrupted if the pointer does not have
// a canonical VA.
assert bottom_PAC_bit <= 52;
if !IsZero(ptr[top_bit:bottom_PAC_bit]) && !IsOnes(ptr[top_bit:bottom_PAC_bit]) then
PAC[top_bit-1] = NOT(PAC[top_bit-1]);
end;
end;
// Preserve the determination between upper and lower address at bit[55] and
insert PAC into
// bits that are not used for the address or the tag(s).
if !IsFeatureImplemented(FEAT_PAuth2) then
assert (bottom_PAC_bit <= 52);
if tbi then
result = ptr[63:56]::selbit::PAC[54:bottom_PAC_bit]::ptr[bottom_PAC_bit-1:0];
else
result = PAC[63:56]::selbit::PAC[54:bottom_PAC_bit]::ptr[bottom_PAC_bit-1:0];
end;
else
var bit55 : bit;
if EL3_using_lva3 then
// Bit 55 is an address bit (when VA size is 56-bits) or
// used to store PAC (when VA size is less than 56-bits)
if is_VA_56bit then
bit55 = ptr[55];
else
bit55 = ptr[55] XOR PAC[55];
end;
else
bit55 = selbit;
end;
if tbi then
if bottom_PAC_bit < 55 then
result = (ptr[63:56] :: bit55 ::
(ptr[54:bottom_PAC_bit] XOR PAC[54:bottom_PAC_bit]) ::
ptr[bottom_PAC_bit-1:0]);
else
result = (ptr[63:56] :: bit55 :: ptr[54:0]);
end;
elsif mtx then
if bottom_PAC_bit < 55 then
result = ((ptr[63:60] XOR PAC[63:60]) :: ptr[59:56] :: bit55 ::
(ptr[54:bottom_PAC_bit] XOR PAC[54:bottom_PAC_bit]) ::
ptr[bottom_PAC_bit-1:0]);
else
result = ((ptr[63:60] XOR PAC[63:60]) :: ptr[59:56] :: bit55 ::
ptr[54:0]);
end;
else
if bottom_PAC_bit < 55 then
result = ((ptr[63:56] XOR PAC[63:56]) :: bit55 ::
(ptr[54:bottom_PAC_bit] XOR PAC[54:bottom_PAC_bit]) ::
ptr[bottom_PAC_bit-1:0]);
else
result = ((ptr[63:56] XOR PAC[63:56]) :: bit55 ::
ptr[54:0]);
end;
end;
end;
return result;
end;
## Library pseudocode for aarch64/functions/pac/addpacda/AddPACDA
// AddPACDA // ========== // Returns a 64-bit value containing x, but replacing the pointer authentication code // field bits with a pointer authentication code, where the pointer authentication // code is derived using a cryptographic algorithm as a combination of x, y and the // APDAKey_EL1.
func AddPACDA(x : bits(64), y : bits(64)) => bits(64) begin let APDAKey_EL1 : bits(128) = APDAKeyHi_EL1()[63:0] :: APDAKeyLo_EL1()[63:0]; if () then return x; else return AddPAC(x, y, APDAKey_EL1, TRUE); end; end;
## Library pseudocode for aarch64/functions/pac/addpacdb/AddPACDB
// AddPACDB // ========== // Returns a 64-bit value containing x, but replacing the pointer authentication code // field bits with a pointer authentication code, where the pointer authentication // code is derived using a cryptographic algorithm as a combination of x, y and the // APDBKey_EL1.
func AddPACDB(x : bits(64), y : bits(64)) => bits(64) begin let APDBKey_EL1 : bits(128) = APDBKeyHi_EL1()[63:0] :: APDBKeyLo_EL1()[63:0]; if () then return x; else return AddPAC(x, y, APDBKey_EL1, TRUE); end; end;
## Library pseudocode for aarch64/functions/pac/addpacga/AddPACGA
// AddPACGA // ========== // Returns a 64-bit value where the lower 32 bits are 0, and the upper 32 bits contain // a 32-bit pointer authentication code which is derived using a cryptographic // algorithm as a combination of x, y and the APGAKey_EL1.
func AddPACGA(x : bits(64), y : bits(64)) => bits(64) begin var TrapEL2 : boolean; let APGAKey_EL1 : bits(128) = APGAKeyHi_EL1()[63:0] :: APGAKeyLo_EL1()[63:0];
var TrapEL3 : boolean;
case PSTATE.EL of
when EL0 =>
TrapEL2 = EL2Enabled() && HCR_EL2().API == '0' && ();
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL1 =>
TrapEL2 = EL2Enabled() && HCR_EL2().API == '0';
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL2 =>
TrapEL2 = FALSE;
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL3 =>
TrapEL2 = FALSE;
TrapEL3 = FALSE;
end;
if TrapEL3 && EL3SDDUndefPriority() then
Undefined();
elsif TrapEL2 then
TrapPACUse(EL2);
elsif TrapEL3 then
if EL3SDDUndef() then
Undefined();
else
TrapPACUse(EL3);
end;
else
return ComputePAC(x, y, APGAKey_EL1[127:64], APGAKey_EL1[63:0])[63:32]::Zeros{32};
end;
end;
## Library pseudocode for aarch64/functions/pac/addpacia/AddPACIA
// AddPACIA // ========== // Returns a 64-bit value containing x, but replacing the pointer authentication code // field bits with a pointer authentication code, where the pointer authentication // code is derived using a cryptographic algorithm as a combination of x, y, and the // APIAKey_EL1.
func AddPACIA(x : bits(64), y : bits(64)) => bits(64) begin let APIAKey_EL1 : bits(128) = APIAKeyHi_EL1()[63:0]::APIAKeyLo_EL1()[63:0]; if () then return x; else return AddPAC(x, y, APIAKey_EL1, FALSE); end; end;
## Library pseudocode for aarch64/functions/pac/addpacia/AddPACIA2
// AddPACIA2 // =========== // Returns a 64-bit value containing x, but replacing the pointer authentication code // field bits with a pointer authentication code, where the pointer authentication // code is derived using a cryptographic algorithm as a combination of x, y, z, and // the APIAKey_EL1.
func AddPACIA2(x : bits(64), y : bits(64), z : bits(64)) => bits(64) begin let APIAKey_EL1 : bits(128) = APIAKeyHi_EL1()[63:0]::APIAKeyLo_EL1()[63:0]; if () then return x; else return AddPAC2(x, y, z, APIAKey_EL1, FALSE); end; end;
## Library pseudocode for aarch64/functions/pac/addpacib/AddPACIB
// AddPACIB // ========== // Returns a 64-bit value containing x, but replacing the pointer authentication code // field bits with a pointer authentication code, where the pointer authentication // code is derived using a cryptographic algorithm as a combination of x, y and the // APIBKey_EL1.
func AddPACIB(x : bits(64), y : bits(64)) => bits(64) begin let APIBKey_EL1 : bits(128) = APIBKeyHi_EL1()[63:0] :: APIBKeyLo_EL1()[63:0]; if () then return x; else return AddPAC(x, y, APIBKey_EL1, FALSE); end; end;
## Library pseudocode for aarch64/functions/pac/addpacib/AddPACIB2
// AddPACIB2 // =========== // Returns a 64-bit value containing x, but replacing the pointer authentication code // field bits with a pointer authentication code, where the pointer authentication // code is derived using a cryptographic algorithm as a combination of x, y, z, and // the APIBKey_EL1.
func AddPACIB2(x : bits(64), y : bits(64), z : bits(64)) => bits(64) begin let APIBKey_EL1 : bits(128) = APIBKeyHi_EL1()[63:0] :: APIBKeyLo_EL1()[63:0]; if () then return x; else return AddPAC2(x, y, z, APIBKey_EL1, FALSE); end; end;
## Library pseudocode for aarch64/functions/pac/auth/AArch64\_PACFailException
// AArch64_PACFailException // ========================== // Generates a PAC Fail Exception
func AArch64_PACFailException(syndrome : bits(2)) begin let route_to_el2 : boolean = PSTATE.EL == EL0 && EL2Enabled() && HCR_EL2().TGE == '1'; let preferred_exception_return : bits(64) = ThisInstrAddr{}(); let vect_offset : integer = 0x0;
var except : ExceptionRecord =
ExceptionSyndrome(Exception_PACFail);
except.syndrome.iss[1:0] = syndrome;
except.syndrome.iss[24:2] = Zeros{23}; // RES0
if UInt(PSTATE.EL) > UInt(EL0) then
AArch64_TakeException(PSTATE.EL, except, preferred_exception_return, vect_offset);
elsif route_to_el2 then
AArch64_TakeException(EL2, except, preferred_exception_return, vect_offset);
else
AArch64_TakeException(EL1, except, preferred_exception_return, vect_offset);
end;
end;
## Library pseudocode for aarch64/functions/pac/auth/Auth
// Auth // ====== // Restores the upper bits of the address to be all zeros or all ones (based on the // value of bit[55]) and computes and checks the pointer authentication code. If the // check passes, then the restored address is returned. If the check fails, the // second-top and third-top bits of the extension bits in the pointer authentication code // field are corrupted to ensure that accessing the address will give a translation fault.
func Auth(ptr : bits(64), modifier : bits(64), K : bits(128), data : boolean, key_number : bit, is_combined : boolean) => bits(64) begin let use_modifier2 : boolean = FALSE; return Authenticate(ptr, modifier, Zeros{64}, use_modifier2, K, data, key_number, is_combined); end;
## Library pseudocode for aarch64/functions/pac/auth/Auth2
// Auth2 // ======= // Restores the upper bits of the address to be all zeros or all ones (based on the // value of bit[55]) and computes and checks the pointer authentication code. If the // check passes, then the restored address is returned. If the check fails, the // second-top and third-top bits of the extension bits in the pointer authentication code // field are corrupted to ensure that accessing the address will give a translation fault.
func Auth2(ptr : bits(64), modifier1 : bits(64), modifier2 : bits(64), K : bits(128), data : boolean, key_number : bit, is_combined : boolean) => bits(64) begin let use_modifier2 : boolean = TRUE; return Authenticate(ptr, modifier1, modifier2, use_modifier2, K, data, key_number, is_combined); end;
## Library pseudocode for aarch64/functions/pac/auth/Authenticate
// Authenticate // ============== // Restores the upper bits of the address to be all zeros or all ones (based on the // value of bit[55]) and computes and checks the pointer authentication code. If the // check passes, then the restored address is returned. If the check fails, the // second-top and third-top bits of the extension bits in the pointer authentication code // field are corrupted to ensure that accessing the address will give a translation fault.
func Authenticate(ptr : bits(64), modifier : bits(64), modifier2 : bits(64), use_modifier2 : boolean, K : bits(128), data : boolean, key_number : bit, is_combined : boolean) => bits(64) begin var PAC : bits(64); var result : bits(64); var original_ptr : bits(64); var error_code : bits(2); var extfield : bits(64);
// Reconstruct the extension field used of adding the PAC to the
pointer
let tbi : boolean = EffectiveTBI(ptr, !data, PSTATE.EL) == '1';
let mtx : boolean = (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) &&
EffectiveMTX(ptr, !data, PSTATE.EL) == '1');
let bottom_PAC_bit : AddressSize = CalculateBottomPACBit(ptr[55]);
let EL3_using_lva3 : boolean = (IsFeatureImplemented(FEAT_LVA3) &&
TranslationRegime(PSTATE.EL) == Regime_EL3 &&
AArch64_IASize(TCR_EL3().T0SZ) > 52);
let is_VA_56bit : boolean = (TranslationRegime(PSTATE.EL) == Regime_EL3
&&
AArch64_IASize(TCR_EL3().T0SZ) == 56);
if EL3_using_lva3 then
extfield = Replicate{64}('0');
else
extfield = Replicate{64}(ptr[55]);
end;
if tbi then
if bottom_PAC_bit <= 55 then
original_ptr = (ptr[63:56] ::
extfield[55:bottom_PAC_bit] :: ptr[bottom_PAC_bit-1:0]);
else
original_ptr = ptr[63:56] :: ptr[55:0];
end;
elsif mtx then
if bottom_PAC_bit <= 55 then
original_ptr = (extfield[63:60] :: ptr[59:56] ::
extfield[55:bottom_PAC_bit] :: ptr[bottom_PAC_bit-1:0]);
else
original_ptr = extfield[63:60] :: ptr[59:56] :: ptr[55:0];
end;
else
original_ptr = extfield[63:bottom_PAC_bit] :: ptr[bottom_PAC_bit-1:0];
end;
if use_modifier2 then
assert IsFeatureImplemented(FEAT_PAuth_LR);
PAC = ComputePAC2(original_ptr, modifier, modifier2, K[127:64], K[63:0]);
else
PAC = ComputePAC(original_ptr, modifier, K[127:64], K[63:0]);
end;
// Check pointer authentication code
if tbi then
if !IsFeatureImplemented(FEAT_PAuth2) then
assert (bottom_PAC_bit <= 52);
if PAC[54:bottom_PAC_bit] == ptr[54:bottom_PAC_bit] then
result = original_ptr;
else
error_code = key_number::NOT(key_number);
result = original_ptr[63:55]::error_code::original_ptr[52:0];
end;
else
result = ptr;
if EL3_using_lva3 && !is_VA_56bit then
result[55] = result[55] XOR PAC[55];
end;
if (bottom_PAC_bit < 55) then
result[54:bottom_PAC_bit] = result[54:bottom_PAC_bit] XOR PAC[54:bottom_PAC_bit];
end;
if (IsFeatureImplemented(FEAT_FPACCOMBINE) ||
(IsFeatureImplemented(FEAT_FPAC) && !is_combined)) then
if (EL3_using_lva3 && !is_VA_56bit && !IsZero(result[55:bottom_PAC_bit])) then
error_code = (if data then '1' else '0')::key_number;
AArch64_PACFailException(error_code);
elsif (!EL3_using_lva3 && (bottom_PAC_bit < 55) &&
result[54:bottom_PAC_bit] !=
Replicate{55-bottom_PAC_bit}(result[55])) then
error_code = (if data then '1' else '0')::key_number;
AArch64_PACFailException(error_code);
end;
end;
end;
elsif mtx then
assert IsFeatureImplemented(FEAT_PAuth2);
result = ptr;
if EL3_using_lva3 && !is_VA_56bit then
result[55] = result[55] XOR PAC[55];
end;
if (bottom_PAC_bit < 55) then
result[54:bottom_PAC_bit] = result[54:bottom_PAC_bit] XOR PAC[54:bottom_PAC_bit];
end;
result[63:60] = result[63:60] XOR PAC[63:60];
if (IsFeatureImplemented(FEAT_FPACCOMBINE) ||
(IsFeatureImplemented(FEAT_FPAC) && !is_combined)) then
if (EL3_using_lva3 && !is_VA_56bit &&
(!IsZero(result[55:bottom_PAC_bit]) || !IsZero(result[63:60]))) then
error_code = (if data then '1' else '0')::key_number;
AArch64_PACFailException(error_code);
elsif (!EL3_using_lva3 && (bottom_PAC_bit < 55) &&
(((result[54:bottom_PAC_bit] !=
Replicate{55-bottom_PAC_bit}(result[55]))) ||
(result[63:60] != Replicate{4}(result[55])))) then
error_code = (if data then '1' else '0')::key_number;
AArch64_PACFailException(error_code);
end;
end;
else
if !IsFeatureImplemented(FEAT_PAuth2) then
assert (bottom_PAC_bit <= 52);
if PAC[54:bottom_PAC_bit] == ptr[54:bottom_PAC_bit] && PAC[63:56] == ptr[63:56] then
result = original_ptr;
else
error_code = key_number::NOT(key_number);
result = original_ptr[63]::error_code::original_ptr[60:0];
end;
else
result = ptr;
if EL3_using_lva3 && !is_VA_56bit then
result[55] = result[55] XOR PAC[55];
end;
if bottom_PAC_bit < 55 then
result[54:bottom_PAC_bit] = result[54:bottom_PAC_bit] XOR PAC[54:bottom_PAC_bit];
end;
result[63:56] = result[63:56] XOR PAC[63:56];
if (IsFeatureImplemented(FEAT_FPACCOMBINE) ||
(IsFeatureImplemented(FEAT_FPAC) && !is_combined)) then
if (EL3_using_lva3 && !IsZero(result[63:bottom_PAC_bit])) then
error_code = (if data then '1' else '0')::key_number;
AArch64_PACFailException(error_code);
elsif (!EL3_using_lva3 &&
result[63:bottom_PAC_bit] !=
Replicate{64-bottom_PAC_bit}(result[55])) then
error_code = (if data then '1' else '0')::key_number;
AArch64_PACFailException(error_code);
end;
end;
end;
end;
return result;
end;
## Library pseudocode for aarch64/functions/pac/authda/AuthDA
// AuthDA // ======== // Returns a 64-bit value containing x, but replacing the pointer authentication code // field bits with the extension of the address bits. The instruction checks a pointer // authentication code in the pointer authentication code field bits of x, using the same // algorithm and key as AddPACDA().
func AuthDA(x : bits(64), y : bits(64), is_combined : boolean) => bits(64) begin let APDAKey_EL1 : bits(128) = APDAKeyHi_EL1()[63:0] :: APDAKeyLo_EL1()[63:0]; if () then return x; else return Auth(x, y, APDAKey_EL1, TRUE, '0', is_combined); end; end;
## Library pseudocode for aarch64/functions/pac/authdb/AuthDB
// AuthDB // ======== // Returns a 64-bit value containing x, but replacing the pointer authentication code // field bits with the extension of the address bits. The instruction checks a // pointer authentication code in the pointer authentication code field bits of x, using // the same algorithm and key as AddPACDB().
func AuthDB(x : bits(64), y : bits(64), is_combined : boolean) => bits(64) begin let APDBKey_EL1 : bits(128) = APDBKeyHi_EL1()[63:0] :: APDBKeyLo_EL1()[63:0]; if () then return x; else return Auth(x, y, APDBKey_EL1, TRUE, '1', is_combined); end; end;
## Library pseudocode for aarch64/functions/pac/authia/AuthIA
// AuthIA // ======== // Returns a 64-bit value containing x, but replacing the pointer authentication code // field bits with the extension of the address bits. The instruction checks a pointer // authentication code in the pointer authentication code field bits of x, using the same // algorithm and key as AddPACIA().
func AuthIA(x : bits(64), y : bits(64), is_combined : boolean) => bits(64) begin let APIAKey_EL1 : bits(128) = APIAKeyHi_EL1()[63:0] :: APIAKeyLo_EL1()[63:0]; if () then return x; else return Auth(x, y, APIAKey_EL1, FALSE, '0', is_combined); end; end;
## Library pseudocode for aarch64/functions/pac/authia/AuthIA2
// AuthIA2 // ========= // Returns a 64-bit value containing x, but replacing the pointer authentication code // field bits with the extension of the address bits. The instruction checks a pointer // authentication code in the pointer authentication code field bits of x, using the same // algorithm and key as AddPACIA2().
func AuthIA2(x : bits(64), y : bits(64), z : bits(64), is_combined : boolean) => bits(64) begin let APIAKey_EL1 : bits(128) = APIAKeyHi_EL1()[63:0] :: APIAKeyLo_EL1()[63:0]; if () then return x; else return Auth2(x, y, z, APIAKey_EL1, FALSE, '0', is_combined); end; end;
## Library pseudocode for aarch64/functions/pac/authib/AuthIB
// AuthIB // ======== // Returns a 64-bit value containing x, but replacing the pointer authentication code // field bits with the extension of the address bits. The instruction checks a pointer // authentication code in the pointer authentication code field bits of x, using the same // algorithm and key as AddPACIB().
func AuthIB(x : bits(64), y : bits(64), is_combined : boolean) => bits(64) begin let APIBKey_EL1 : bits(128) = APIBKeyHi_EL1()[63:0] :: APIBKeyLo_EL1()[63:0]; if () then return x; else return Auth(x, y, APIBKey_EL1, FALSE, '1', is_combined); end; end;
## Library pseudocode for aarch64/functions/pac/authib/AuthIB2
// AuthIB2 // ========= // Returns a 64-bit value containing x, but replacing the pointer authentication code // field bits with the extension of the address bits. The instruction checks a pointer // authentication code in the pointer authentication code field bits of x, using the same // algorithm and key as AddPACIB2().
func AuthIB2(x : bits(64), y : bits(64), z : bits(64), is_combined : boolean) => bits(64) begin let APIBKey_EL1 : bits(128) = APIBKeyHi_EL1()[63:0] :: APIBKeyLo_EL1()[63:0]; if () then return x; else return Auth2(x, y, z, APIBKey_EL1, FALSE, '1', is_combined); end; end;
## Library pseudocode for
aarch64/functions/pac/calcbottompacbit/AArch64\_PACEffectiveTxSZ
// AArch64_PACEffectiveTxSZ // ========================== // Compute the effective value for TxSZ used to determine the placement of the PAC field
readonly func AArch64_PACEffectiveTxSZ(regime : Regime, walkparams : S1TTWParams) => bits(6) begin let s1maxtxsz : integer = AArch64_MaxTxSZ(walkparams.tgx); let s1mintxsz : integer = AArch64_S1MinTxSZ(regime, walkparams);
if AArch64_S1TxSZFaults(regime, walkparams) then
if ConstrainUnpredictable(Unpredictable_RESTnSZ) == Constraint_FORCE then
if UInt(walkparams.txsz) < s1mintxsz then
return s1mintxsz[5:0];
end;
if UInt(walkparams.txsz) > s1maxtxsz then
return s1maxtxsz[5:0];
end;
end;
elsif UInt(walkparams.txsz) < s1mintxsz then
return s1mintxsz[5:0];
elsif UInt(walkparams.txsz) > s1maxtxsz then
return s1maxtxsz[5:0];
end;
return walkparams.txsz;
end;
## Library pseudocode for
aarch64/functions/pac/calcbottompacbit/CalculateBottomPACBit
// CalculateBottomPACBit // =======================
readonly func CalculateBottomPACBit(top_bit : bit) => AddressSize begin var regime : Regime; var walkparams : S1TTWParams; var bottom_PAC_bit : AddressSize;
regime = TranslationRegime(PSTATE.EL);
let ss : SecurityState = CurrentSecurityState();
walkparams = AArch64_GetS1TTWParams(regime, PSTATE.EL, ss,
Replicate{64}(top_bit));
bottom_PAC_bit = ((64 - UInt(AArch64_PACEffectiveTxSZ(regime, walkparams)))
as AddressSize);
return bottom_PAC_bit;
end;
## Library pseudocode for aarch64/functions/pac/computepac/ComputePAC
// ComputePAC // ============
func ComputePAC(data : bits(64), modifier : bits(64), key0 : bits(64), key1 : bits(64)) => bits(64) begin if IsFeatureImplemented(FEAT_PACIMP) then return ComputePACIMPDEF(data, modifier, key0, key1); end; if IsFeatureImplemented(FEAT_PACQARMA3) then let isqarma3 : boolean = TRUE; return ComputePACQARMA(data, modifier, key0, key1, isqarma3); end; if IsFeatureImplemented(FEAT_PACQARMA5) then let isqarma3 : boolean = FALSE; return ComputePACQARMA(data, modifier, key0, key1, isqarma3); end; unreachable; end;
## Library pseudocode for aarch64/functions/pac/computepac/ComputePAC2
// ComputePAC2 // =============
func ComputePAC2(data : bits(64), modifier1 : bits(64), modifier2 : bits(64), key0 : bits(64), key1 : bits(64)) => bits(64) begin if IsFeatureImplemented(FEAT_PACIMP) then return ComputePAC2IMPDEF(data, modifier1, modifier2, key0, key1); end; if IsFeatureImplemented(FEAT_PACQARMA3) then let isqarma3 : boolean = TRUE; return ComputePAC2QARMA(data, modifier1, modifier2, key0, key1, isqarma3); end; if IsFeatureImplemented(FEAT_PACQARMA5) then let isqarma3 : boolean = FALSE; return ComputePAC2QARMA(data, modifier1, modifier2, key0, key1, isqarma3); end; unreachable; end;
## Library pseudocode for aarch64/functions/pac/computepac/ComputePAC2IMPDEF
// ComputePAC2IMPDEF // =================== // Compute IMPLEMENTATION DEFINED cryptographic algorithm to be used for PAC calculation.
impdef func ComputePAC2IMPDEF(data : bits(64), modifier1 : bits(64), modifier2 : bits(64), key0 : bits(64), key1 : bits(64)) => bits(64) begin Unimplemented(); end;
## Library pseudocode for aarch64/functions/pac/computepac/ComputePAC2QARMA
// ComputePAC2QARMA // ==================
func ComputePAC2QARMA(data : bits(64), modifier1 : bits(64), modifier2 : bits(64), key0 : bits(64), key1 : bits(64), isqarma3 : boolean) => bits(64) begin let concat_modifiers : bits(64) = modifier2[36:5]::modifier1[35:4]; return ComputePACQARMA(data, concat_modifiers, key0, key1, isqarma3); end;
## Library pseudocode for aarch64/functions/pac/computepac/ComputePACIMPDEF
// ComputePACIMPDEF // ================== // Compute IMPLEMENTATION DEFINED cryptographic algorithm to be used for PAC calculation.
impdef func ComputePACIMPDEF(data : bits(64), modifier : bits(64), key0 : bits(64), key1 : bits(64)) => bits(64) begin Unimplemented(); end;
## Library pseudocode for aarch64/functions/pac/computepac/ComputePACQARMA
// ComputePACQARMA // ================= // Compute QARMA3 or QARMA5 cryptographic algorithm for PAC calculation
func ComputePACQARMA(data : bits(64), modifier : bits(64), key0 : bits(64), key1 : bits(64), isqarma3 : boolean) => bits(64) begin var workingval : bits(64); var runningmod : bits(64); var roundkey : bits(64); var modk0 : bits(64); let Alpha : bits(64) = 0xC0AC29B7C97C50DD[63:0];
var iterations : integer;
RC[[0]] = 0x0000000000000000[63:0];
RC[[1]] = 0x13198A2E03707344[63:0];
RC[[2]] = 0xA4093822299F31D0[63:0];
if isqarma3 then
iterations = 2;
else // QARMA5
iterations = 4;
RC[[3]] = 0x082EFA98EC4E6C89[63:0];
RC[[4]] = 0x452821E638D01377[63:0];
end;
modk0 = key0[0]::key0[63:2]::(key0[63] XOR key0[1]);
runningmod = modifier;
workingval = data XOR key0;
for i = 0 to iterations do
roundkey = key1 XOR runningmod;
workingval = workingval XOR roundkey;
workingval = workingval XOR RC
; if i > 0 then workingval = PACCellShuffle(workingval); workingval = PACMult(workingval); end; if isqarma3 then workingval = PACSub1(workingval); else workingval = PACSub(workingval); end; runningmod = TweakShuffle(runningmod[63:0]); end; roundkey = modk0 XOR runningmod; workingval = workingval XOR roundkey; workingval = PACCellShuffle(workingval); workingval = PACMult(workingval); if isqarma3 then workingval = PACSub1(workingval); else workingval = PACSub(workingval); end; workingval = PACCellShuffle(workingval); workingval = PACMult(workingval); workingval = key1 XOR workingval; workingval = PACCellInvShuffle(workingval); if isqarma3 then workingval = PACSub1(workingval); else workingval = PACInvSub(workingval); end; workingval = PACMult(workingval); workingval = PACCellInvShuffle(workingval); workingval = workingval XOR key0; workingval = workingval XOR runningmod; for i = 0 to iterations do if isqarma3 then workingval = PACSub1(workingval); else workingval = PACInvSub(workingval); end; if i < iterations then workingval = PACMult(workingval); workingval = PACCellInvShuffle(workingval); end; runningmod = TweakInvShuffle(runningmod[63:0]); roundkey = key1 XOR runningmod; workingval = workingval XOR RC[[iterations-i]]; workingval = workingval XOR roundkey; workingval = workingval XOR Alpha; end; workingval = workingval XOR modk0;
return workingval; end;
## Library pseudocode for aarch64/functions/pac/computepac/PACCellInvShuffle
// PACCellInvShuffle // ===================
func PACCellInvShuffle(indata : bits(64)) => bits(64) begin var outdata : bits(64); outdata[3:0] = indata[15:12]; outdata[7:4] = indata[27:24]; outdata[11:8] = indata[51:48]; outdata[15:12] = indata[39:36]; outdata[19:16] = indata[59:56]; outdata[23:20] = indata[47:44]; outdata[27:24] = indata[7:4]; outdata[31:28] = indata[19:16]; outdata[35:32] = indata[35:32]; outdata[39:36] = indata[55:52]; outdata[43:40] = indata[31:28]; outdata[47:44] = indata[11:8]; outdata[51:48] = indata[23:20]; outdata[55:52] = indata[3:0]; outdata[59:56] = indata[43:40]; outdata[63:60] = indata[63:60]; return outdata; end;
## Library pseudocode for aarch64/functions/pac/computepac/PACCellShuffle
// PACCellShuffle // ================
func PACCellShuffle(indata : bits(64)) => bits(64) begin var outdata : bits(64); outdata[3:0] = indata[55:52]; outdata[7:4] = indata[27:24]; outdata[11:8] = indata[47:44]; outdata[15:12] = indata[3:0]; outdata[19:16] = indata[31:28]; outdata[23:20] = indata[51:48]; outdata[27:24] = indata[7:4]; outdata[31:28] = indata[43:40]; outdata[35:32] = indata[35:32]; outdata[39:36] = indata[15:12]; outdata[43:40] = indata[59:56]; outdata[47:44] = indata[23:20]; outdata[51:48] = indata[11:8]; outdata[55:52] = indata[39:36]; outdata[59:56] = indata[19:16]; outdata[63:60] = indata[63:60]; return outdata; end;
## Library pseudocode for aarch64/functions/pac/computepac/PACInvSub
// PACInvSub // ===========
func PACInvSub(Tinput : bits(64)) => bits(64) begin // This is a 4-bit substitution from the PRINCE-family cipher var Toutput : bits(64); for i = 0 to 15 do case Tinput[i*:4] of when '0000' => Toutput[i*:4] = '0101'; when '0001' => Toutput[i*:4] = '1110'; when '0010' => Toutput[i*:4] = '1101'; when '0011' => Toutput[i*:4] = '1000'; when '0100' => Toutput[i*:4] = '1010'; when '0101' => Toutput[i*:4] = '1011'; when '0110' => Toutput[i*:4] = '0001'; when '0111' => Toutput[i*:4] = '1001'; when '1000' => Toutput[i*:4] = '0010'; when '1001' => Toutput[i*:4] = '0110'; when '1010' => Toutput[i*:4] = '1111'; when '1011' => Toutput[i*:4] = '0000'; when '1100' => Toutput[i*:4] = '0100'; when '1101' => Toutput[i*:4] = '1100'; when '1110' => Toutput[i*:4] = '0111'; when '1111' => Toutput[i*:4] = '0011'; end; end; return Toutput; end;
## Library pseudocode for aarch64/functions/pac/computepac/PACMult
// PACMult // =========
func PACMult(Sinput : bits(64)) => bits(64) begin var t0 : bits(4); var t1 : bits(4); var t2 : bits(4); var t3 : bits(4); var Soutput : bits(64);
for i = 0 to 3 do
t0[3:0] = ROL(Sinput[((i+8))*:4], 1) XOR ROL(Sinput[((i+4))*:4], 2);
t0[3:0] = t0[3:0] XOR ROL(Sinput[i*:4], 1);
t1[3:0] = ROL(Sinput[((i+12))*:4], 1) XOR ROL(Sinput[((i+4))*:4], 1);
t1[3:0] = t1[3:0] XOR ROL(Sinput[i*:4], 2);
t2[3:0] = ROL(Sinput[((i+12))*:4], 2) XOR ROL(Sinput[((i+8))*:4], 1);
t2[3:0] = t2[3:0] XOR ROL(Sinput[i*:4], 1);
t3[3:0] = ROL(Sinput[((i+12))*:4], 1) XOR ROL(Sinput[((i+8))*:4], 2);
t3[3:0] = t3[3:0] XOR ROL(Sinput[((i+4))*:4], 1);
Soutput[i*:4] = t3[3:0];
Soutput[((i+4))*:4] = t2[3:0];
Soutput[((i+8))*:4] = t1[3:0];
Soutput[((i+12))*:4] = t0[3:0];
end;
return Soutput;
end;
## Library pseudocode for aarch64/functions/pac/computepac/PACSub
// PACSub // ========
func PACSub(Tinput : bits(64)) => bits(64) begin // This is a 4-bit substitution from the PRINCE-family cipher var Toutput : bits(64); for i = 0 to 15 do case Tinput[i*:4] of when '0000' => Toutput[i*:4] = '1011'; when '0001' => Toutput[i*:4] = '0110'; when '0010' => Toutput[i*:4] = '1000'; when '0011' => Toutput[i*:4] = '1111'; when '0100' => Toutput[i*:4] = '1100'; when '0101' => Toutput[i*:4] = '0000'; when '0110' => Toutput[i*:4] = '1001'; when '0111' => Toutput[i*:4] = '1110'; when '1000' => Toutput[i*:4] = '0011'; when '1001' => Toutput[i*:4] = '0111'; when '1010' => Toutput[i*:4] = '0100'; when '1011' => Toutput[i*:4] = '0101'; when '1100' => Toutput[i*:4] = '1101'; when '1101' => Toutput[i*:4] = '0010'; when '1110' => Toutput[i*:4] = '0001'; when '1111' => Toutput[i*:4] = '1010'; end; end; return Toutput; end;
## Library pseudocode for aarch64/functions/pac/computepac/PacSub1
// PacSub1 // =========
func PACSub1(Tinput : bits(64)) => bits(64) begin // This is a 4-bit substitution from Qarma sigma1 var Toutput : bits(64); for i = 0 to 15 do case Tinput[i*:4] of when '0000' => Toutput[i*:4] = '1010'; when '0001' => Toutput[i*:4] = '1101'; when '0010' => Toutput[i*:4] = '1110'; when '0011' => Toutput[i*:4] = '0110'; when '0100' => Toutput[i*:4] = '1111'; when '0101' => Toutput[i*:4] = '0111'; when '0110' => Toutput[i*:4] = '0011'; when '0111' => Toutput[i*:4] = '0101'; when '1000' => Toutput[i*:4] = '1001'; when '1001' => Toutput[i*:4] = '1000'; when '1010' => Toutput[i*:4] = '0000'; when '1011' => Toutput[i*:4] = '1100'; when '1100' => Toutput[i*:4] = '1011'; when '1101' => Toutput[i*:4] = '0001'; when '1110' => Toutput[i*:4] = '0010'; when '1111' => Toutput[i*:4] = '0100'; end; end; return Toutput; end;
## Library pseudocode for aarch64/functions/pac/computepac/RC
// RC[] // ====
var RC : array [[5]] of bits(64);
## Library pseudocode for aarch64/functions/pac/computepac/TweakCellInvRot
// TweakCellInvRot // =================
func TweakCellInvRot(incell : bits(4)) => bits(4) begin var outcell : bits(4); outcell[3] = incell[2]; outcell[2] = incell[1]; outcell[1] = incell[0]; outcell[0] = incell[0] XOR incell[3]; return outcell; end;
## Library pseudocode for aarch64/functions/pac/computepac/TweakCellRot
// TweakCellRot // ==============
func TweakCellRot(incell : bits(4)) => bits(4) begin var outcell : bits(4); outcell[3] = incell[0] XOR incell[1]; outcell[2] = incell[3]; outcell[1] = incell[2]; outcell[0] = incell[1]; return outcell; end;
## Library pseudocode for aarch64/functions/pac/computepac/TweakInvShuffle
// TweakInvShuffle // =================
func TweakInvShuffle(indata : bits(64)) => bits(64) begin var outdata : bits(64); outdata[3:0] = TweakCellInvRot(indata[51:48]); outdata[7:4] = indata[55:52]; outdata[11:8] = indata[23:20]; outdata[15:12] = indata[27:24]; outdata[19:16] = indata[3:0]; outdata[23:20] = indata[7:4]; outdata[27:24] = TweakCellInvRot(indata[11:8]); outdata[31:28] = indata[15:12]; outdata[35:32] = TweakCellInvRot(indata[31:28]); outdata[39:36] = TweakCellInvRot(indata[63:60]); outdata[43:40] = TweakCellInvRot(indata[59:56]); outdata[47:44] = TweakCellInvRot(indata[19:16]); outdata[51:48] = indata[35:32]; outdata[55:52] = indata[39:36]; outdata[59:56] = indata[43:40]; outdata[63:60] = TweakCellInvRot(indata[47:44]); return outdata; end;
## Library pseudocode for aarch64/functions/pac/computepac/TweakShuffle
// TweakShuffle // ==============
func TweakShuffle(indata : bits(64)) => bits(64) begin var outdata : bits(64); outdata[3:0] = indata[19:16]; outdata[7:4] = indata[23:20]; outdata[11:8] = TweakCellRot(indata[27:24]); outdata[15:12] = indata[31:28]; outdata[19:16] = TweakCellRot(indata[47:44]); outdata[23:20] = indata[11:8]; outdata[27:24] = indata[15:12]; outdata[31:28] = TweakCellRot(indata[35:32]); outdata[35:32] = indata[51:48]; outdata[39:36] = indata[55:52]; outdata[43:40] = indata[59:56]; outdata[47:44] = TweakCellRot(indata[63:60]); outdata[51:48] = TweakCellRot(indata[3:0]); outdata[55:52] = indata[7:4]; outdata[59:56] = TweakCellRot(indata[43:40]); outdata[63:60] = TweakCellRot(indata[39:36]); return outdata; end;
## Library pseudocode for aarch64/functions/pac/pac/IsAPDAKeyEnabled
// IsAPDAKeyEnabled // ================== // Returns TRUE if authentication using the APDAKey_EL1 key is enabled. // Otherwise, depending on the state of the PE, generate a trap, or return FALSE.
func IsAPDAKeyEnabled() => boolean begin var TrapEL2 : boolean; var TrapEL3 : boolean; var Enable : bits(1);
case PSTATE.EL of
when EL0 =>
let IsEL1Regime : boolean = S1TranslationRegime() == EL1;
Enable = if IsEL1Regime then SCTLR_EL1().EnDA else SCTLR_EL2().EnDA;
if IsFeatureImplemented(FEAT_PAuth_EnhCtl) then
var enda2 : bit;
if IsEL1Regime then
enda2 = if IsSCTLR2EL1Enabled() then SCTLR2_EL1().EnDA2 else '0';
else
enda2 = if IsSCTLR2EL2Enabled() then SCTLR2_EL2().EnDA2 else '0';
end;
Enable = Enable XOR enda2;
end;
TrapEL2 = EL2Enabled() && HCR_EL2().API == '0' && ();
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL1 =>
Enable = SCTLR_EL1().EnDA;
TrapEL2 = EL2Enabled() && HCR_EL2().API == '0';
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL2 =>
Enable = SCTLR_EL2().EnDA;
TrapEL2 = FALSE;
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL3 =>
Enable = SCTLR_EL3().EnDA;
TrapEL2 = FALSE;
TrapEL3 = FALSE;
end;
if Enable == '0' then
return FALSE;
elsif TrapEL3 && EL3SDDUndefPriority() then
Undefined();
elsif TrapEL2 then
TrapPACUse(EL2);
elsif TrapEL3 then
if EL3SDDUndef() then
Undefined();
else
TrapPACUse(EL3);
end;
else
return TRUE;
end;
end;
## Library pseudocode for aarch64/functions/pac/pac/IsAPDBKeyEnabled
// IsAPDBKeyEnabled // ================== // Returns TRUE if authentication using the APDBKey_EL1 key is enabled. // Otherwise, depending on the state of the PE, generate a trap, or return FALSE.
func IsAPDBKeyEnabled() => boolean begin var TrapEL2 : boolean; var TrapEL3 : boolean; var Enable : bits(1);
case PSTATE.EL of
when EL0 =>
let IsEL1Regime : boolean = S1TranslationRegime() == EL1;
Enable = if IsEL1Regime then SCTLR_EL1().EnDB else SCTLR_EL2().EnDB;
if IsFeatureImplemented(FEAT_PAuth_EnhCtl) then
var endb2 : bit;
if IsEL1Regime then
endb2 = if IsSCTLR2EL1Enabled() then SCTLR2_EL1().EnDB2 else '0';
else
endb2 = if IsSCTLR2EL2Enabled() then SCTLR2_EL2().EnDB2 else '0';
end;
Enable = Enable XOR endb2;
end;
TrapEL2 = EL2Enabled() && HCR_EL2().API == '0' && ();
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL1 =>
Enable = SCTLR_EL1().EnDB;
TrapEL2 = EL2Enabled() && HCR_EL2().API == '0';
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL2 =>
Enable = SCTLR_EL2().EnDB;
TrapEL2 = FALSE;
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL3 =>
Enable = SCTLR_EL3().EnDB;
TrapEL2 = FALSE;
TrapEL3 = FALSE;
end;
if Enable == '0' then
return FALSE;
elsif TrapEL3 && EL3SDDUndefPriority() then
Undefined();
elsif TrapEL2 then
TrapPACUse(EL2);
elsif TrapEL3 then
if EL3SDDUndef() then
Undefined();
else
TrapPACUse(EL3);
end;
else
return TRUE;
end;
end;
## Library pseudocode for aarch64/functions/pac/pac/IsAPIAKeyEnabled
// IsAPIAKeyEnabled // ================== // Returns TRUE if authentication using the APIAKey_EL1 key is enabled. // Otherwise, depending on the state of the PE, generate a trap, or return FALSE.
func IsAPIAKeyEnabled() => boolean begin var TrapEL2 : boolean; var TrapEL3 : boolean; var Enable : bits(1);
case PSTATE.EL of
when EL0 =>
let IsEL1Regime : boolean = S1TranslationRegime() == EL1;
Enable = if IsEL1Regime then SCTLR_EL1().EnIA else SCTLR_EL2().EnIA;
if IsFeatureImplemented(FEAT_PAuth_EnhCtl) then
var enia2 : bit;
if IsEL1Regime then
enia2 = if IsSCTLR2EL1Enabled() then SCTLR2_EL1().EnIA2 else '0';
else
enia2 = if IsSCTLR2EL2Enabled() then SCTLR2_EL2().EnIA2 else '0';
end;
Enable = Enable XOR enia2;
end;
TrapEL2 = EL2Enabled() && HCR_EL2().API == '0' && ();
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL1 =>
Enable = SCTLR_EL1().EnIA;
TrapEL2 = EL2Enabled() && HCR_EL2().API == '0';
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL2 =>
Enable = SCTLR_EL2().EnIA;
TrapEL2 = FALSE;
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL3 =>
Enable = SCTLR_EL3().EnIA;
TrapEL2 = FALSE;
TrapEL3 = FALSE;
end;
if Enable == '0' then
return FALSE;
elsif TrapEL3 && EL3SDDUndefPriority() then
Undefined();
elsif TrapEL2 then
TrapPACUse(EL2);
elsif TrapEL3 then
if EL3SDDUndef() then
Undefined();
else
TrapPACUse(EL3);
end;
else
return TRUE;
end;
end;
## Library pseudocode for aarch64/functions/pac/pac/IsAPIBKeyEnabled
// IsAPIBKeyEnabled // ================== // Returns TRUE if authentication using the APIBKey_EL1 key is enabled. // Otherwise, depending on the state of the PE, generate a trap, or return FALSE.
func IsAPIBKeyEnabled() => boolean begin var TrapEL2 : boolean; var TrapEL3 : boolean; var Enable : bits(1);
case PSTATE.EL of
when EL0 =>
let IsEL1Regime : boolean = S1TranslationRegime() == EL1;
Enable = if IsEL1Regime then SCTLR_EL1().EnIB else SCTLR_EL2().EnIB;
if IsFeatureImplemented(FEAT_PAuth_EnhCtl) then
var enib2 : bit;
if IsEL1Regime then
enib2 = if IsSCTLR2EL1Enabled() then SCTLR2_EL1().EnIB2 else '0';
else
enib2 = if IsSCTLR2EL2Enabled() then SCTLR2_EL2().EnIB2 else '0';
end;
Enable = Enable XOR enib2;
end;
TrapEL2 = EL2Enabled() && HCR_EL2().API == '0' && ();
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL1 =>
Enable = SCTLR_EL1().EnIB;
TrapEL2 = EL2Enabled() && HCR_EL2().API == '0';
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL2 =>
Enable = SCTLR_EL2().EnIB;
TrapEL2 = FALSE;
TrapEL3 = HaveEL(EL3) && SCR_EL3().API == '0';
when EL3 =>
Enable = SCTLR_EL3().EnIB;
TrapEL2 = FALSE;
TrapEL3 = FALSE;
end;
if Enable == '0' then
return FALSE;
elsif TrapEL3 && EL3SDDUndefPriority() then
Undefined();
elsif TrapEL2 then
TrapPACUse(EL2);
elsif TrapEL3 then
if EL3SDDUndef() then
Undefined();
else
TrapPACUse(EL3);
end;
else
return TRUE;
end;
end;
## Library pseudocode for aarch64/functions/pac/pac/IsPACMEnabled
// IsPACMEnabled // =============== // Returns TRUE if the effects of the PACM instruction are enabled, otherwise FALSE.
func IsPACMEnabled() => boolean begin assert IsFeatureImplemented(FEAT_PAuth) && IsFeatureImplemented(FEAT_PAuth_LR);
if IsTrivialPACMImplementation() then
return FALSE;
end;
var enabled : boolean;
// EL2 could force the behavior at EL1 and EL0 to NOP.
if PSTATE.EL IN {EL0, EL1} && EL2Enabled() && () then
enabled = IsHCRXEL2Enabled() && HCRX_EL2().PACMEn == '1';
else
enabled = TRUE;
end;
// Otherwise, the SCTLR2_ELx bit determines the behavior.
if enabled then
var enpacm_bit : bit;
case PSTATE.EL of
when EL3 =>
enpacm_bit = SCTLR2_EL3().EnPACM;
when EL2 =>
------------------------------------------------------------------------------
Page 1 of 1.
End of thread.