diff options
author | Xiang W <wxjstz@126.com> | 2022-03-16 04:45:25 +0300 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2022-03-27 06:37:44 +0300 |
commit | 555bdb1cf3871dd327fc2e4d9b3cf8f89801bc1b (patch) | |
tree | f23f0171d320af43277a61b63d4713a2a0d892ae /include | |
parent | d552fc8d369780150fd9837e1097b4b34a640d12 (diff) | |
download | opensbi-555bdb1cf3871dd327fc2e4d9b3cf8f89801bc1b.tar.xz |
include: Use static asserts for SBI_PLATFORM_xxx_OFFSET defines
Add static detection to prevent the modification of struct sbi_platform
from forgetting the modification of SBI_PLATFORM_xxx_OFFSET
Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/sbi/sbi_platform.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 0b5ae4b..2c777ac 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -175,6 +175,56 @@ struct sbi_platform { const u32 *hart_index2id; }; +/** + * Prevent modification of struct sbi_platform from affecting + * SBI_PLATFORM_xxx_OFFSET + */ +_Static_assert( + offsetof(struct sbi_platform, opensbi_version) + == SBI_PLATFORM_OPENSBI_VERSION_OFFSET, + "struct sbi_platform definition has changed, please redefine " + "SBI_PLATFORM_OPENSBI_VERSION_OFFSET"); +_Static_assert( + offsetof(struct sbi_platform, platform_version) + == SBI_PLATFORM_VERSION_OFFSET, + "struct sbi_platform definition has changed, please redefine " + "SBI_PLATFORM_VERSION_OFFSET"); +_Static_assert( + offsetof(struct sbi_platform, name) + == SBI_PLATFORM_NAME_OFFSET, + "struct sbi_platform definition has changed, please redefine " + "SBI_PLATFORM_NAME_OFFSET"); +_Static_assert( + offsetof(struct sbi_platform, features) + == SBI_PLATFORM_FEATURES_OFFSET, + "struct sbi_platform definition has changed, please redefine " + "SBI_PLATFORM_FEATURES_OFFSET"); +_Static_assert( + offsetof(struct sbi_platform, hart_count) + == SBI_PLATFORM_HART_COUNT_OFFSET, + "struct sbi_platform definition has changed, please redefine " + "SBI_PLATFORM_HART_COUNT_OFFSET"); +_Static_assert( + offsetof(struct sbi_platform, hart_stack_size) + == SBI_PLATFORM_HART_STACK_SIZE_OFFSET, + "struct sbi_platform definition has changed, please redefine " + "SBI_PLATFORM_HART_STACK_SIZE_OFFSET"); +_Static_assert( + offsetof(struct sbi_platform, platform_ops_addr) + == SBI_PLATFORM_OPS_OFFSET, + "struct sbi_platform definition has changed, please redefine " + "SBI_PLATFORM_OPS_OFFSET"); +_Static_assert( + offsetof(struct sbi_platform, firmware_context) + == SBI_PLATFORM_FIRMWARE_CONTEXT_OFFSET, + "struct sbi_platform definition has changed, please redefine " + "SBI_PLATFORM_FIRMWARE_CONTEXT_OFFSET"); +_Static_assert( + offsetof(struct sbi_platform, hart_index2id) + == SBI_PLATFORM_HART_INDEX2ID_OFFSET, + "struct sbi_platform definition has changed, please redefine " + "SBI_PLATFORM_HART_INDEX2ID_OFFSET"); + /** Get pointer to sbi_platform for sbi_scratch pointer */ #define sbi_platform_ptr(__s) \ ((const struct sbi_platform *)((__s)->platform_addr)) |