diff options
author | Tom Hughes <tomhughes@chromium.org> | 2021-11-23 14:43:07 -0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-21 00:10:31 +0000 |
commit | 12e1ed299bf8a1323702fe44cff6a16c36a5d644 (patch) | |
tree | 1ddebbc44337f4e424f18216eb8c9d7842579b7b /common/asm_define.h | |
parent | ba83e48f20a8f9cc4ffaabbff3e69fb33dbe1141 (diff) | |
download | chrome-ec-12e1ed299bf8a1323702fe44cff6a16c36a5d644.tar.gz |
Add ability to get struct offsets for use in assembly
BRANCH=none
BUG=b:172020503
TEST=Using https://crrev.com/c/3299275:
make BOARD=discovery-stm32f072 -j
manually inspect generated file:
build/discovery-stm32f072/RW/core/cortex-m0/asm_offsets.h
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Change-Id: I6c5a982a88ed1e77f8e98b9a0a451d52d5c03a87
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3299274
Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'common/asm_define.h')
-rw-r--r-- | common/asm_define.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/common/asm_define.h b/common/asm_define.h new file mode 100644 index 0000000000..b47bae067f --- /dev/null +++ b/common/asm_define.h @@ -0,0 +1,25 @@ +/* Copyright 2021 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_COMMON_ASM_DEFINE_H +#define __CROS_EC_COMMON_ASM_DEFINE_H + +#include "stddef.h" + +/* + * Use an immediate integer constraint + * (https://gcc.gnu.org/onlinedocs/gcc/Simple-Constraints.html) to write the + * value. This file is compiled with the "-S" flag, which stops the compiler + * after generating assembly. The resulting assembly is then grepped for the + * "__ASM_DEFINE__" strings, which is used to create a header file with the + * value. + */ +#define ASM_DEFINE(NAME, VAL) \ + __asm__ volatile(".ascii \" __ASM_DEFINE__ " NAME " %0\"" : : "i"(VAL)) + +#define ASM_DEFINE_OFFSET(NAME, TYPE, MEMBER) \ + ASM_DEFINE(NAME, offsetof(TYPE, MEMBER)) + +#endif /* __CROS_EC_COMMON_ASM_DEFINE_H */ |