summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2021-11-23 14:43:07 -0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-21 00:10:31 +0000
commit12e1ed299bf8a1323702fe44cff6a16c36a5d644 (patch)
tree1ddebbc44337f4e424f18216eb8c9d7842579b7b
parentba83e48f20a8f9cc4ffaabbff3e69fb33dbe1141 (diff)
downloadchrome-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>
-rw-r--r--Makefile1
-rw-r--r--Makefile.rules7
-rw-r--r--common/asm_define.h25
-rw-r--r--core/build.mk20
4 files changed, 53 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 065747c017..a8b282c613 100644
--- a/Makefile
+++ b/Makefile
@@ -272,6 +272,7 @@ else
include libc/build.mk
endif
include chip/$(CHIP)/build.mk
+include core/build.mk
include core/$(CORE)/build.mk
include common/build.mk
include driver/build.mk
diff --git a/Makefile.rules b/Makefile.rules
index 860d032981..8b52882635 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -101,6 +101,8 @@ cmd_run_fuzz = build/host/$*/$*.exe -seed=1 -runs=1 $(silent) \
cmd_exe = $(CXX) $(ro-objs) $(HOST_TEST_LDFLAGS) $(LDFLAGS_EXTRA) -o $@
cmd_c_to_o = $(CC) -std=gnu11 $(C_WARN) $(CFLAGS) -MMD -MP -MF $@.d -c $< \
-MT $(@D)/$(@F) -o $(@D)/$(@F)
+cmd_c_to_s = $(CC) -S $(C_WARN) $(CFLAGS) -fno-lto -MMD -MP -MF $@.d -c $< \
+ -MT $(@D)/$(@F) -o $(@D)/$(@F)
cmd_cxx_to_o = $(CXX) -std=gnu++17 $(CFLAGS) $(CXXFLAGS) -MMD -MP -MF $@.d -c $< \
-MT $(@D)/$(@F) -o $(@D)/$(@F)
cmd_c_to_build = $(BUILDCC) $(BUILD_CFLAGS) \
@@ -618,6 +620,11 @@ $(out)/RO/%.o:%.c
$(out)/RW/%.o:%.c
$(call quiet,c_to_o,CC )
+$(out)/RO/%.s:%.c
+ $(call quiet,c_to_s,CC )
+$(out)/RW/%.s:%.c
+ $(call quiet,c_to_s,CC )
+
$(out)/RO/%.o:%.cc
$(call quiet,cxx_to_o,CXX )
$(out)/RW/%.o:%.cc
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 */
diff --git a/core/build.mk b/core/build.mk
new file mode 100644
index 0000000000..407550bf7c
--- /dev/null
+++ b/core/build.mk
@@ -0,0 +1,20 @@
+# 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.
+
+CORE_RW_OUT:=$(out)/RW/core/$(CORE)
+CORE_RO_OUT:=$(out)/RO/core/$(CORE)
+
+cmd_asm_define_to_h = grep ASM_DEFINE $< \
+ | sed 's/.*__ASM_DEFINE__\s\(.*\)\s\#\(.*\)"/\#define \1 \2/g' > $@
+
+$(CORE_RO_OUT)/asm_offsets.h:$(CORE_RO_OUT)/asm_offsets.s
+ $(call quiet,asm_define_to_h, )
+$(CORE_RW_OUT)/asm_offsets.h:$(CORE_RW_OUT)/asm_offsets.s
+ $(call quiet,asm_define_to_h, )
+
+$(CORE_RW_OUT)/asm_offsets.s: core/$(CORE)/asm_offsets.c
+$(CORE_RW_OUT)/asm_offsets.h: $(CORE_RW_OUT)/asm_offsets.s
+
+$(CORE_RO_OUT)/asm_offsets.s: core/$(CORE)/asm_offsets.c
+$(CORE_RO_OUT)/asm_offsets.h: $(CORE_RO_OUT)/asm_offsets.s