summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang W <wxjstz@126.com>2022-03-16 13:16:48 +0300
committerAnup Patel <anup@brainfault.org>2022-03-27 07:14:54 +0300
commit1b42d3ace3ed38bda35276838a880db24ba7db82 (patch)
tree5d3c5dea114f034888eb789e2d8cd3996fb27cb0
parent555bdb1cf3871dd327fc2e4d9b3cf8f89801bc1b (diff)
downloadopensbi-1b42d3ace3ed38bda35276838a880db24ba7db82.tar.xz
include: Use static asserts for SBI_SCRATCH_xxx_OFFSET defines
Add static detection to prevent the modification of struct sbi_scratch from forgetting the modification of SBI_SCRATCH_xxx_OFFSET Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
-rw-r--r--include/sbi/sbi_scratch.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h
index 0c27307..2f6f0a1 100644
--- a/include/sbi/sbi_scratch.h
+++ b/include/sbi/sbi_scratch.h
@@ -73,6 +73,66 @@ struct sbi_scratch {
unsigned long options;
};
+/**
+ * Prevent modification of struct sbi_scratch from affecting
+ * SBI_SCRATCH_xxx_OFFSET
+ */
+_Static_assert(
+ offsetof(struct sbi_scratch, fw_start)
+ == SBI_SCRATCH_FW_START_OFFSET,
+ "struct sbi_scratch definition has changed, please redefine "
+ "SBI_SCRATCH_FW_START_OFFSET");
+_Static_assert(
+ offsetof(struct sbi_scratch, fw_size)
+ == SBI_SCRATCH_FW_SIZE_OFFSET,
+ "struct sbi_scratch definition has changed, please redefine "
+ "SBI_SCRATCH_FW_SIZE_OFFSET");
+_Static_assert(
+ offsetof(struct sbi_scratch, next_arg1)
+ == SBI_SCRATCH_NEXT_ARG1_OFFSET,
+ "struct sbi_scratch definition has changed, please redefine "
+ "SBI_SCRATCH_NEXT_ARG1_OFFSET");
+_Static_assert(
+ offsetof(struct sbi_scratch, next_addr)
+ == SBI_SCRATCH_NEXT_ADDR_OFFSET,
+ "struct sbi_scratch definition has changed, please redefine "
+ "SBI_SCRATCH_NEXT_ADDR_OFFSET");
+_Static_assert(
+ offsetof(struct sbi_scratch, next_mode)
+ == SBI_SCRATCH_NEXT_MODE_OFFSET,
+ "struct sbi_scratch definition has changed, please redefine "
+ "SBI_SCRATCH_NEXT_MODE_OFFSET");
+_Static_assert(
+ offsetof(struct sbi_scratch, warmboot_addr)
+ == SBI_SCRATCH_WARMBOOT_ADDR_OFFSET,
+ "struct sbi_scratch definition has changed, please redefine "
+ "SBI_SCRATCH_WARMBOOT_ADDR_OFFSET");
+_Static_assert(
+ offsetof(struct sbi_scratch, platform_addr)
+ == SBI_SCRATCH_PLATFORM_ADDR_OFFSET,
+ "struct sbi_scratch definition has changed, please redefine "
+ "SBI_SCRATCH_PLATFORM_ADDR_OFFSET");
+_Static_assert(
+ offsetof(struct sbi_scratch, hartid_to_scratch)
+ == SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET,
+ "struct sbi_scratch definition has changed, please redefine "
+ "SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET");
+_Static_assert(
+ offsetof(struct sbi_scratch, trap_exit)
+ == SBI_SCRATCH_TRAP_EXIT_OFFSET,
+ "struct sbi_scratch definition has changed, please redefine "
+ "SBI_SCRATCH_TRAP_EXIT_OFFSET");
+_Static_assert(
+ offsetof(struct sbi_scratch, tmp0)
+ == SBI_SCRATCH_TMP0_OFFSET,
+ "struct sbi_scratch definition has changed, please redefine "
+ "SBI_SCRATCH_TMP0_OFFSET");
+_Static_assert(
+ offsetof(struct sbi_scratch, options)
+ == SBI_SCRATCH_OPTIONS_OFFSET,
+ "struct sbi_scratch definition has changed, please redefine "
+ "SBI_SCRATCH_OPTIONS_OFFSET");
+
/** Possible options for OpenSBI library */
enum sbi_scratch_options {
/** Disable prints during boot */