From 16a354f920f3959ed847bd917bdfbc7eba48cf1e Mon Sep 17 00:00:00 2001 From: Wolfgang Denk Date: Tue, 26 Oct 2010 00:08:35 +0200 Subject: include/asm-offsets.h: automatically generate assembler constants 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 Acked-by: Kumar Gala --- lib/asm-offsets.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/asm-offsets.c (limited to 'lib') diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c new file mode 100644 index 0000000000..4eb61747c4 --- /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 + +#include + +int main(void) +{ + return 0; +} -- cgit From 25ddd1fb0a2281b182529afbc8fda5de2dc16d96 Mon Sep 17 00:00:00 2001 From: Wolfgang Denk Date: Tue, 26 Oct 2010 14:34:52 +0200 Subject: Replace CONFIG_SYS_GBL_DATA_SIZE by auto-generated value CONFIG_SYS_GBL_DATA_SIZE has always been just a bad workarond for not being able to use "sizeof(struct global_data)" in assembler files. Recent experience has shown that manual synchronization is not reliable enough. This patch renames CONFIG_SYS_GBL_DATA_SIZE into GENERATED_GBL_DATA_SIZE which gets automatically generated by the asm-offsets tool. In the result, all definitions of this value can be deleted from the board config files. We have to make sure that all files that reference such data include the new file. No other changes have been done yet, but it is obvious that similar changes / simplifications can be done for other, related macro definitions as well. Signed-off-by: Wolfgang Denk Acked-by: Kumar Gala --- lib/asm-offsets.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/asm-offsets.c b/lib/asm-offsets.c index 4eb61747c4..22095610f9 100644 --- a/lib/asm-offsets.c +++ b/lib/asm-offsets.c @@ -21,5 +21,9 @@ int main(void) { + /* Round up to make sure size gives nice stack alignment */ + DEFINE(GENERATED_GBL_DATA_SIZE, + (sizeof(struct global_data)+15) & ~15); + return 0; } -- cgit From 071bc923308832bbc541a887fece767d79a6dc7a Mon Sep 17 00:00:00 2001 From: Wolfgang Denk Date: Wed, 27 Oct 2010 22:48:30 +0200 Subject: Coding Style cleanup Signed-off-by: Wolfgang Denk --- lib/hashtable.c | 12 ++++++------ lib/qsort.c | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/hashtable.c b/lib/hashtable.c index 57802cfb6d..7ac3dddda6 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -56,7 +56,7 @@ /* * [Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986 - * [Knuth] The Art of Computer Programming, part 3 (6.4) + * [Knuth] The Art of Computer Programming, part 3 (6.4) */ /* @@ -252,7 +252,7 @@ int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval, if (htab->table[idx].used) { /* - * Further action might be required according to the + * Further action might be required according to the * action value. */ unsigned hval2; @@ -283,8 +283,8 @@ int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval, do { /* - * Because SIZE is prime this guarantees to - * step through all available indices. + * Because SIZE is prime this guarantees to + * step through all available indices. */ if (idx <= hval2) idx = htab->size + idx - hval2; @@ -323,8 +323,8 @@ int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval, /* An empty bucket has been found. */ if (action == ENTER) { /* - * If table is full and another entry should be - * entered return with error. + * If table is full and another entry should be + * entered return with error. */ if (htab->filled == htab->size) { __set_errno(ENOMEM); diff --git a/lib/qsort.c b/lib/qsort.c index bb47319f8b..e771dcfcf2 100644 --- a/lib/qsort.c +++ b/lib/qsort.c @@ -23,9 +23,9 @@ #endif void qsort(void *base, - size_t nel, - size_t width, - int (*comp)(const void *, const void *)) + size_t nel, + size_t width, + int (*comp)(const void *, const void *)) { size_t wgap, i, j, k; char tmp; -- cgit