forked from AsahiLinux/u-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Acked-by: Kumar Gala <[email protected]>
- Loading branch information
Showing
6 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include <generated/generic-asm-offsets.h> | ||
/* #include <generated/asm-offsets.h> */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copied from Linux: | ||
* commit 37487a56523d402e25650da16c337acf4cecd13d | ||
* Author: Christoph Lameter <[email protected]> | ||
*/ | ||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/sh | ||
|
||
# Adapted from Linux kernel's "Kbuild": | ||
# commit 1cdf25d704f7951d02a04064c97db547d6021872 | ||
# Author: Christoph Lameter <[email protected]> | ||
|
||
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 |