The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=a9e12d3ec8bde29e97227757bc08cb1a0a93afa9
commit a9e12d3ec8bde29e97227757bc08cb1a0a93afa9 Author: Andrew Turner <[email protected]> AuthorDate: 2026-06-18 13:34:04 +0000 Commit: Andrew Turner <[email protected]> CommitDate: 2026-06-18 14:56:52 +0000 arm64: Support building sys/sysl instructions Add support to build system instructions from a macro. These are based on the existing support for msr/mrs instructions with adjustments for the different instruction format. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D57017 --- sys/arm64/include/_armreg.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/sys/arm64/include/_armreg.h b/sys/arm64/include/_armreg.h index 0f5134e5a978..0ade9e6168c9 100644 --- a/sys/arm64/include/_armreg.h +++ b/sys/arm64/include/_armreg.h @@ -52,6 +52,34 @@ #define WRITE_SPECIALREG(reg, _val) \ __asm __volatile("msr " __STRING(reg) ", %0" : : "r"((uint64_t)_val)) + +#define __SYS_ALT_NAME(op1, crn, crm, op2) \ + "#" #op1 ", C" #crn ", C" #crm ", #" #op2 +#define _SYS_ALT_NAME(op1, crn, crm, op2) \ + __SYS_ALT_NAME(op1, crn, crm, op2) +#define SYS_ALT_NAME(insn) \ + _SYS_ALT_NAME(insn##_op1, insn##_CRn, insn##_CRm, insn##_op2) + +#define SYS(insn) do { \ + _Static_assert(insn##_op0 == 1, "Invalid SYS instruction"); \ + __asm __volatile("sys " SYS_ALT_NAME(insn)); \ +} while (0) + +#define SYS_ARG(insn, _val) do { \ + _Static_assert(insn##_op0 == 1, "Invalid SYS instruction"); \ + __asm __volatile("sys " SYS_ALT_NAME(insn) ", %0" \ + : : "r"((uint64_t)_val)); \ +} while (0) + +#define SYSL(insn) \ +({ \ + uint64_t _val; \ + _Static_assert(insn##_op0 == 1, "Invalid SYS instruction"); \ + __asm __volatile("sysl %0, " SYS_ALT_NAME(insn) \ + : "=&r"(_val)); \ + _val; \ +}) + #define UL(x) UINT64_C(x) #endif /* !_MACHINE__ARMREG_H_ */
