Branches, exception generating and system instructions
fixed bit field field the encoding fixes should be
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | M | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| Z | op | A | Rn | Rm | |||||||||||||||||||||||||||
110101100101111100001x1111111111
n : range(0, 31) = UInt(Rn);
branch_type : BranchType = undefined;
let 'm = UInt(Rm);
let pac : bool = A == 0b1;
let use_key_a : bool = M == 0b0;
source_is_sp : bool = Z == 0b1 & m == 31;
if not_bool(pac) & m != 0 then {
throw(Error_Undefined())
} else if pac & not_bool(HavePACExt()) then {
throw(Error_Undefined())
} else ();
match op {
0b00 => {
branch_type = BranchType_INDIR
},
0b01 => {
branch_type = BranchType_INDCALL
},
0b10 => {
branch_type = BranchType_RET
},
_ => {
throw(Error_Undefined())
}
};
let branch_type = branch_type;
if pac then {
if Z == 0b0 & m != 31 then {
throw(Error_Undefined())
};
if branch_type == BranchType_RET then {
if n != 31 then {
throw(Error_Undefined())
};
n = 30;
source_is_sp = true
};
()
};
let 'n = n;
execute_aarch64_instrs_branch_unconditional_register(branch_type, m, n, pac, source_is_sp, use_key_a)
inst_type : GCSInstruction = undefined;
target : bits(64) = X_read(n, 64);
let auth_then_branch : bool = true;
if pac then {
let modifier : bits(64) = if source_is_sp then SP_read() else
X_read(m, 64);
if use_key_a then {
target = AuthIA(target, modifier, auth_then_branch)
} else {
target = AuthIB(target, modifier, auth_then_branch)
}
};
if (branch_type == BranchType_RET & HaveGCS()) & GCSPCREnabled(PSTATE.EL) then {
if not_bool(pac) then {
inst_type = GCSInstType_PRET
} else {
if use_key_a then {
inst_type = GCSInstType_PRETAA
} else {
inst_type = GCSInstType_PRETAB
}
};
target = LoadCheckGCSRecord(target, inst_type);
SetCurrentGCSPointer(GetCurrentGCSPointer() + 8)
};
if branch_type == BranchType_INDCALL then {
if HaveGCS() & GCSPCREnabled(PSTATE.EL) then {
AddGCSRecord(PC_read() + 4)
};
X_set(30, 64) = PC_read() + 4
};
match branch_type {
BranchType_INDIR => {
if InGuardedPage then {
if n == 16 | n == 17 then {
BTypeNext = 0b01
} else {
BTypeNext = 0b11
}
} else {
BTypeNext = 0b01
}
},
BranchType_INDCALL => {
BTypeNext = 0b10
},
BranchType_RET => {
BTypeNext = 0b00
},
_ => ()
};
let branch_conditional : bool = false;
BranchTo(target, branch_type, branch_conditional)
Made from ScarletNX's Sail at 166ad3910f80. sail-arm's definitions are Arm's ASL in Sail (BSD 3-Clause Clear, license); ScarletNX's fixups are GPL-3.0-or-later.