From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/3 v2] include/asm-offsets.h: automatically generate assembler constants
Date: Tue, 26 Oct 2010 16:19:58 +0200 [thread overview]
Message-ID: <1288102798-5475-1-git-send-email-wd@denx.de> (raw)
In-Reply-To: <1288101601-24871-3-git-send-email-wd@denx.de>
A recurrent issue is that certain C level constructs like sizeof() or
offsetof() cannot be used in assembler files, which is inconvenient
when such constructs are used in the definition of macro names etc.
To avoid duplication of such definitions (and thus another cause of
problems), we adapt the Linux way to automatically generate the
respective definitions from the respective C header files.
In Linux, this is implemented in include/linux/kbuild.h, Kbuild, and
arch/*/kernel/asm-offsets.c; we adapt the code from the Linux v2.6.36
kernel tree.
We also copy the concept of the include/generated/ directory which can
be used to hold other automatically generated files as well.
We start with an architecture-independent lib/asm-offsets.c which
generates include/generated/generic-asm-offsets.h (included by
include/asm-offsets.h, which is what will be referred to in the actual
source code). Later this may be extended by architecture-specific
arch/*/lib/asm-offsets.c files that will generate a
include/generated/asm-offsets.h.
Signed-off-by: Wolfgang Denk <wd@denx.de>
---
v2: fix typo
add SoB line
.gitignore | 3 +++
Makefile | 21 +++++++++++++++++++--
include/asm-offsets.h | 2 ++
include/linux/kbuild.h | 20 ++++++++++++++++++++
lib/asm-offsets.c | 25 +++++++++++++++++++++++++
tools/scripts/make-asm-offsets | 27 +++++++++++++++++++++++++++
6 files changed, 96 insertions(+), 2 deletions(-)
create mode 100644 include/asm-offsets.h
create mode 100644 include/linux/kbuild.h
create mode 100644 lib/asm-offsets.c
create mode 100755 tools/scripts/make-asm-offsets
diff --git a/.gitignore b/.gitignore
index 67d2cd6..e71f6ac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,6 +40,9 @@
/errlog
/reloc_off
+/include/generated/
+/lib/asm-offsets.s
+
# stgit generated dirs
patches-*
.stgit-edit.txt
diff --git a/Makefile b/Makefile
index f8e13d7..6e146d4 100644
--- a/Makefile
+++ b/Makefile
@@ -372,7 +372,8 @@ GEN_UBOOT = \
cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
--start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
-Map u-boot.map -o u-boot
-$(obj)u-boot: depend $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds
+$(obj)u-boot: depend \
+ $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds
$(GEN_UBOOT)
ifeq ($(CONFIG_KALLSYMS),y)
smap=`$(call SYSTEM_MAP,u-boot) | \
@@ -426,7 +427,9 @@ updater:
# Explicitly make _depend in subdirs containing multiple targets to prevent
# parallel sub-makes creating .depend files simultaneously.
-depend dep: $(TIMESTAMP_FILE) $(VERSION_FILE) $(obj)include/autoconf.mk
+depend dep: $(TIMESTAMP_FILE) $(VERSION_FILE) \
+ $(obj)include/autoconf.mk \
+ $(obj)include/generated/generic-asm-offsets.h
for dir in $(SUBDIRS) $(CPUDIR) $(dir $(LDSCRIPT)) ; do \
$(MAKE) -C $$dir _depend ; done
@@ -473,6 +476,18 @@ $(obj)include/autoconf.mk: $(obj)include/config.h
sed -n -f tools/scripts/define2mk.sed > $@.tmp && \
mv $@.tmp $@
+$(obj)include/generated/generic-asm-offsets.h: $(obj)include/autoconf.mk.dep \
+ $(obj)lib/asm-offsets.s
+ @$(XECHO) Generating $@
+ tools/scripts/make-asm-offsets $(obj)lib/asm-offsets.s $@
+
+$(obj)lib/asm-offsets.s: $(obj)include/autoconf.mk.dep \
+ $(src)lib/asm-offsets.c
+ @mkdir -p $(obj)lib
+ $(CC) -DDO_DEPS_ONLY \
+ $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) \
+ -o $@ $(src)lib/asm-offsets.c -c -S
+
#########################################################################
else # !config.mk
all $(obj)u-boot.hex $(obj)u-boot.srec $(obj)u-boot.bin \
@@ -1214,6 +1229,7 @@ clean:
$(obj)u-boot.lds \
$(obj)arch/blackfin/cpu/bootrom-asm-offsets.[chs]
@rm -f $(obj)include/bmp_logo.h
+ @rm -f $(obj)lib/asm-offsets.s
@rm -f $(obj)nand_spl/{u-boot.lds,u-boot-spl,u-boot-spl.map,System.map}
@rm -f $(obj)onenand_ipl/onenand-{ipl,ipl.bin,ipl.map}
@rm -f $(ONENAND_BIN)
@@ -1237,6 +1253,7 @@ clobber: clean
@rm -f $(obj)tools/{env/crc32.c,inca-swap-bytes}
@rm -f $(obj)arch/powerpc/cpu/mpc824x/bedbug_603e.c
@rm -f $(obj)include/asm/proc $(obj)include/asm/arch $(obj)include/asm
+ @rm -fr $(obj)include/generated
@[ ! -d $(obj)nand_spl ] || find $(obj)nand_spl -name "*" -type l -print | xargs rm -f
@[ ! -d $(obj)onenand_ipl ] || find $(obj)onenand_ipl -name "*" -type l -print | xargs rm -f
diff --git a/include/asm-offsets.h b/include/asm-offsets.h
new file mode 100644
index 0000000..ab28184
--- /dev/null
+++ b/include/asm-offsets.h
@@ -0,0 +1,2 @@
+#include <generated/generic-asm-offsets.h>
+/* #include <generated/asm-offsets.h> */
diff --git a/include/linux/kbuild.h b/include/linux/kbuild.h
new file mode 100644
index 0000000..be76384
--- /dev/null
+++ b/include/linux/kbuild.h
@@ -0,0 +1,20 @@
+/*
+ * Copied from Linux:
+ * commit 37487a56523d402e25650da16c337acf4cecd13d
+ * Author: Christoph Lameter <clameter@sgi.com>
+ */
+#ifndef __LINUX_KBUILD_H
+#define __LINUX_KBUILD_H
+
+#define DEFINE(sym, val) \
+ asm volatile("\n->" #sym " %0 " #val : : "i" (val))
+
+#define BLANK() asm volatile("\n->" : : )
+
+#define OFFSET(sym, str, mem) \
+ DEFINE(sym, offsetof(struct str, mem))
+
+#define COMMENT(x) \
+ asm volatile("\n->#" x)
+
+#endif
diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c
new file mode 100644
index 0000000..4eb6174
--- /dev/null
+++ b/lib/asm-offsets.c
@@ -0,0 +1,25 @@
+/*
+ * Adapted from Linux v2.6.36 kernel: arch/powerpc/kernel/asm-offsets.c
+ *
+ * This program is used to generate definitions needed by
+ * assembly language modules.
+ *
+ * We use the technique used in the OSF Mach kernel code:
+ * generate asm statements containing #defines,
+ * compile this file to assembler, and then extract the
+ * #defines from the assembly-language output.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <common.h>
+
+#include <linux/kbuild.h>
+
+int main(void)
+{
+ return 0;
+}
diff --git a/tools/scripts/make-asm-offsets b/tools/scripts/make-asm-offsets
new file mode 100755
index 0000000..61c095f
--- /dev/null
+++ b/tools/scripts/make-asm-offsets
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# Adapted from Linux kernel's "Kbuild":
+# commit 1cdf25d704f7951d02a04064c97db547d6021872
+# Author: Christoph Lameter <clameter@sgi.com>
+
+mkdir -p $(dirname $2)
+
+# Default sed regexp - multiline due to syntax constraints
+SED_CMD="/^->/{s:->#\(.*\):/* \1 */:; \
+ s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 (\2) /* \3 */:; \
+ s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
+ s:->::; p;}"
+
+(set -e
+ echo "#ifndef __ASM_OFFSETS_H__"
+ echo "#define __ASM_OFFSETS_H__"
+ echo "/*"
+ echo " * DO NOT MODIFY."
+ echo " *"
+ echo " * This file was generated by $(basename $0)"
+ echo " *"
+ echo " */"
+ echo ""
+ sed -ne "${SED_CMD}" $1
+ echo ""
+ echo "#endif" ) > $2
--
1.7.2.3
next prev parent reply other threads:[~2010-10-26 14:19 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-26 13:59 [U-Boot] [PATCH 0/3] Introduce asm-offsets and fix CONFIG_SYS_GBL_DATA_SIZE problems Wolfgang Denk
2010-10-26 13:59 ` [U-Boot] [PATCH 1/3] Rename CONFIG_SYS_INIT_RAM_END into CONFIG_SYS_INIT_RAM_SIZE Wolfgang Denk
2010-10-26 19:02 ` Wolfgang Denk
2010-10-26 14:00 ` [U-Boot] [PATCH 2/3] include/asm-offsets.h: automatically generate assembler constants Wolfgang Denk
2010-10-26 14:11 ` Alexander Stein
2010-10-26 14:16 ` Wolfgang Denk
2010-10-26 14:19 ` Wolfgang Denk [this message]
2010-10-26 19:04 ` [U-Boot] [PATCH 2/3 v2] " Wolfgang Denk
2010-10-26 14:00 ` [U-Boot] [PATCH 3/3] Replace CONFIG_SYS_GBL_DATA_SIZE by auto-generated value Wolfgang Denk
2010-10-26 14:22 ` Stefan Roese
2010-10-26 14:32 ` Kumar Gala
2010-10-26 14:41 ` Wolfgang Denk
2010-10-26 15:22 ` Stefan Roese
2010-10-26 14:52 ` [U-Boot] [PATCH 3/3 v2] " Wolfgang Denk
2010-10-26 19:05 ` Wolfgang Denk
2010-10-26 19:54 ` Alessandro Rubini
2010-10-26 20:38 ` Wolfgang Denk
2010-10-26 20:57 ` Alessandro Rubini
2010-10-26 21:12 ` Wolfgang Denk
2010-10-26 21:18 ` Alessandro Rubini
2010-10-26 21:31 ` Wolfgang Denk
2010-10-26 21:40 ` Alessandro Rubini
2010-10-27 18:41 ` Wolfgang Denk
2010-10-26 15:17 ` [U-Boot] [PATCH 3/3] " Mike Frysinger
2010-10-26 16:42 ` Wolfgang Denk
2010-10-26 14:16 ` [U-Boot] [PATCH 0/3] Introduce asm-offsets and fix CONFIG_SYS_GBL_DATA_SIZE problems Kumar Gala
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1288102798-5475-1-git-send-email-wd@denx.de \
--to=wd@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox