From 81322bb61bc3d05cff0b151a90f31c2670c0dd08 Mon Sep 17 00:00:00 2001 From: Sergiu Moga Date: Mon, 24 Mar 2025 18:34:28 +0200 Subject: [PATCH] arch: Define regular function calling convention register arguments Define the macros that one could use to access the registers within `struct __regs` that represent the ABI/calling convention specific that contain the arguments (and the return value). Signed-off-by: Sergiu Moga Approved-by: Michalis Pappas Reviewed-by: Michalis Pappas Reviewed-by: Andrei Tatar GitHub-Closes: #1618 --- arch/arm/arm64/include/uk/asm/lcpu.h | 19 +++++++++++++++++++ arch/x86/x86_64/include/uk/asm/lcpu.h | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/arch/arm/arm64/include/uk/asm/lcpu.h b/arch/arm/arm64/include/uk/asm/lcpu.h index e1126f8d4..dc574119f 100644 --- a/arch/arm/arm64/include/uk/asm/lcpu.h +++ b/arch/arm/arm64/include/uk/asm/lcpu.h @@ -194,6 +194,25 @@ unsigned char tcr_ips_bits[] = {32, 36, 40, 42, 44, 48, 52}; #include +/* + * Mappings of `struct __regs` register fields + * according to AAPCS64 definition for function calls + * rargX - Arguments 0..7 + * rretX - Function call return value + */ + +#define __fn_rarg0 x[0] +#define __fn_rarg1 x[1] +#define __fn_rarg2 x[2] +#define __fn_rarg3 x[3] +#define __fn_rarg4 x[4] +#define __fn_rarg5 x[5] +#define __fn_rarg6 x[6] +#define __fn_rarg7 x[7] + +#define __fn_rret0 x[0] +#define __fn_rret1 x[1] + /* * Change this structure must update TRAP_STACK_SIZE at the same time. * This data structure must be 16-byte alignment. diff --git a/arch/x86/x86_64/include/uk/asm/lcpu.h b/arch/x86/x86_64/include/uk/asm/lcpu.h index e9e727281..8946b0fc4 100644 --- a/arch/x86/x86_64/include/uk/asm/lcpu.h +++ b/arch/x86/x86_64/include/uk/asm/lcpu.h @@ -66,6 +66,23 @@ #include #include +/* + * Mappings of `struct __regs` register fields + * according to AMD64 SysV ABI definition for function calls + * rargX - Arguments 0..5 + * rretX - Function call return value + */ + +#define __fn_rarg0 rdi +#define __fn_rarg1 rsi +#define __fn_rarg2 rdx +#define __fn_rarg3 rcx +#define __fn_rarg4 r8 +#define __fn_rarg5 r9 + +#define __fn_rret0 rax +#define __fn_rret1 rdx + struct __regs { unsigned long pad; /* 8 bytes to make struct size multiple of 16 */ unsigned long r15; -- 2.39.5