关于asm-offsets的一些说明

对Kbuild里面的asm-offsets一直不太清楚,找到了一个RFC,并简单翻译了一下。详见http://marc.info/?l=linux-kernel&m=100219616028442&w=2

Almost every architecture generates Assembler values to map the offsets of fields in C structures, about the only exception is i386 and that is because its offsets are hard coded into entry.S. Every arch has done it differently, none of them have got it exactly right.
几乎所有的体系结构都会产生汇编的值去和C语言中的数据结构各个域的偏移相对应。但x86是一个例外,因为它的偏移是硬编码的,具体可以参考entry.S.没一种体系结构都是不一样的,但几乎没有一个能够对应的十分准确。

As part of kbuild 2.5 I am standardizing on one method for generating Assembler offsets. This change is required for kbuild 2.5 but it can be added to 2.4 without disturbing the current kbuild, I want to do this gradually now instead of a single massive change in kernel 2.5. I will be issuing per architecture changes for generating Assembler offsets against 2.4.
从kbuild2.5开始,我就开始做了一个标准化的方法去生成汇编的相对偏移。如果你的kbuild是2.4版本的,也可以是用kbuild2.5的这个标准化方法。我想逐步的把这个方法加入到2.5的Linux Kernel中,重点是针对各个架构的不同点。

The kbuild 2.5 method for generating Assembler offsets satisfies these requirements:
在Kbuild 2.5中,要使用这个标准化的方法,需要满足的一下几点:
* No manual intervention required. Many architectures rely on users running make dep after changing config options that affect the Assembler offsets. If the user forgets to run make dep then the C and Assembler code is out of sync - totally unacceptable. This is completely fixed in kbuild 2.5; I cannot do a complete fix in kbuild 2.4 but it is still better than the existing manual system.
不需要人工干预。你只要配置好config,然后make dep就可以啦。如果忘记了make dep,那么后果很严重,C和汇编代码就不会对应,会产生错误。不过,如果你采用2.5,这个问题已经被修复了。虽然我没有在kbuild2.4里面这样做,但是,如果你是用kbuild2.4这样的版本,总比完全手动要好的多吧。
* Standard name for the related files. There are 6+ different names for the files used to generate Assembler offsets, kbuild 2.5 uses asm-offsets.[csh] on all architectures.
相关文件都采用了标准名字。有6个不同名字的文件用来产生汇编的偏移,从kbuild2.5开始,在所有的体系结构中,只采用了asm-offsets.c .h 和.s
* Allows for multiple parallel compiles from the same source tree. Writing the generated asm-offsets.h to include/asm is not an option, it prevents concurrent compiles.
在同一个工作目录下,允许并行编译。通过向include/asm下面写声称的asm-offsets.h,会阻止并发编译。
* The method must work in native and cross compile mode and give exactly the same results. Some 2.4 code only works in native mode, some architectures have different methods for native and cross compile with different output formats. Yeuch!
使用这种方法必须能够保证采用编译器和交叉编译器都能得到同样的计算结果。在2.4版本中就不太好。
* Standard scripts for generating the output. Every arch does it differently in 2.4, standards are good!
采用标准化的脚本来产生输出,这一点在2.4版本中已经做得比较好了。
* Correct dependency trees. Because 2.4 make dep does not scan .S files, there is little or no dependency information. Even if the offsets are regenerated, the affected Assembler code does not always get rebuilt. kbuild 2.5 handles dependencies for Assembler as well as C; I cannot get kbuild 2.4 perfect but I can improve on the existing (or non-existent) 2.4 dependencies.
还是依赖问题。在2.4版本中make dep 不会扫描.S文件。即使重新编译声称asmoffsets,那些汇编代码也不会重新编译。在2.5版本中已经解决了这个问题。我不能让2.4版本完美,但我会想办法提高2.4版本所存在的依赖问题
All architectures will define arch/$(ARCH)/asm-offsets.c. This has a standard prologue for the macros that convert offsets to Assembler, followed by arch specific field references.
所有的架构会定义asm-offsets.c文件,这是一个标准的宏文件将会根据体系结构的信息产生相应汇编代码中的偏移位置。
arch/$(ARCH)/asm-offsets.s is generated from arch/$(ARCH)/asm-offsets.c using standard rules, although kbuild 2.4 needs some tweaking.
asm-offsets.s由asm-offsets.c产生。
arch/$(ARCH)/asm-offsets.h is generated from arch/$(ARCH)/asm-offsets.s by a semi-standard script. Most of the script is common to all architectures but the precise format of the Assembler output is arch specific.
asm-offsets.h由asm-offsets.s产生。各个平台产生代码所是用的脚本大部分都是一样的,但在细微的格式上可能会产生平台差别。
The final result is included in *only* the Assembler programs that need it, as #include asm-offsets.h" with -I arch/$(ARCH) in the relevant Makefiles. Hard coding relative paths in source files is a pet hate, use #include "localname.h" and -I instead. Including the generated
file in C code is not allowed, it severly pollutes the dependency chain, to the extent that any config change can force a complete recompile, unacceptable.
通过在makefile中采用 -I arch/$(ARCH)参数,使最后的结果包含在了要使用的汇编程序中。如果要是用硬编码的话就在汇编源文件中用#include来包含,C文件就不需要了,切记!否则,会产生不必要的麻烦。

评论

此博客中的热门博文

Linux/ARM Page Table Entry 属性设置分析

提交了30次才AC ---【附】POJ 2488解题报告

笔记