The upcoming board info stage dispatch determines the stage it runs in by checking which stage's memory region covers the program counter.
Add asm-generic/registers.h with pc_inside(), built on the get_pc() that ARM, RISC-V and PowerPC provide, as the home for such register level helpers. Signed-off-by: Ahmad Fatoum <[email protected]> --- include/asm-generic/registers.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 include/asm-generic/registers.h diff --git a/include/asm-generic/registers.h b/include/asm-generic/registers.h new file mode 100644 index 000000000000..8ce28f74e1db --- /dev/null +++ b/include/asm-generic/registers.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* SPDX-FileCopyrightText: 2026 Ahmad Fatoum */ + +#ifndef __ASM_GENERIC_REGISTERS_H +#define __ASM_GENERIC_REGISTERS_H + +#include <linux/compiler.h> +#include <asm/common.h> + +/* + * pc_inside - check if the program counter is in [start, start + size) + * + * A single unsigned compare, so it also works for a region ending at the + * top of the address space. + */ +static __always_inline bool pc_inside(unsigned long start, unsigned long size) +{ + unsigned long pc = get_pc(); + + return pc - start < size; +} + +#endif -- 2.47.3
