查看: 4711|回复: 4

找gas文档来学学汇编。

[复制链接]
发表于 2009-7-25 07:59:31 | 显示全部楼层 |阅读模式
关键词: gas , 汇编 , 文档来
本帖最后由 linux_Ultra 于 2009-7-25 08:31 编辑

无法理解 c 语言中那些 变量和常量 被加载到内存里的存储布局, 所以只能找gas文档来学学汇编。
有关
.fill
这个伪指令的解释, 无法明白到底是什么意思。

.fill repeat , size , value
    result, size and value are absolute expressions. This emits repeat
copies of size bytes. Repeat may be zero or more. Size may be zero or more,
but if it is more than 8, then it is deemed to have the value 8, compatible with other people's assemblers. The contents of each repeat bytes is taken from an 8-byte number. The highest order 4 bytes are zero. The lowest order 4 bytes are value rendered in the byte-order of an interger on the computer as is assembling for. Each size bytes in a repetition is taken from the lowest order size bytes of this number. Again, this bizarre behavior is compatible with other people's assemblers.
    size and value are optional. If the second comma and value are absent, value is assumed zero. If the firsr comma  and following tokens are
absent, size is assumed to be 1.
--------------------------------------------------------------------------------
.fill repeat , size , value
result, size and value are absolute expressions.
结果,size 和 value是绝对表达式。
This emits repeat copies of size bytes. Repeat may be zero or more.  
这个伪指令用来重复拷贝size大小的字节数。repeat (重复次数)可以是零或更大。
Size may be zero or more,but if it is more than 8, then it is deemed to have the value 8, compatible with other people's assemblers.
size可以是零或更大,但是如果size比8大, 为了和其他的汇编器兼容,它的值会被认为是8。

The contents of each repeat bytes is taken from an 8-byte number. The highest order 4 bytes are zero. The lowest order 4 bytes are value rendered in the byte-order of an interger on the computer as is assembling for.
每个重复拷贝的内容被降低自于一个8字节的数。最高顺序4字节是零。最低顺序字节是value的值,在电脑上用一个字节顺序的汇编整数来表示。

Each size bytes in a repetition is taken from the lowest order size bytes of this number. Again, this bizarre behavior is compatible with other people's assemblers.
每个size 字节被降低来自最低顺序字节数。同样的, 这些奇怪的行为也是为了和别的汇编器兼容。

    size and value are optional. If the second comma and value are absent, value is assumed zero. If the firsr comma  and following tokens are
absent, size is assumed to be 1.
size 和 value 是可选的。 如果第二个分号和value不写, value 就被假定为1。如果第一个分号和后面的tokens 不写,size 就被假定为1。
fill.JPG
 楼主| 发表于 2009-7-25 08:29:14 | 显示全部楼层
找了些例子。
:~/source/linux-kernel/linux-2.6.29$ find . -name '*.S'|xargs grep -In '\.fill'

-----------------------------------------------------------------------------------------------
.
.
.
/arch/m32r/boot/compressed/head.S:55:        .fillinsn
./arch/m32r/boot/setup.S:167:        .fillinsn
./arch/xtensa/kernel/head.S:239:        .fill        PAGE_SIZE, 1, 0
./arch/xtensa/kernel/head.S:241:        .fill        PAGE_SIZE, 1, 0
./arch/xtensa/kernel/coprocessor.S:332:        .fill XCHAL_CP_MAX, 4, 0
./arch/x86/kernel/head_32.S:616:        .fill 1024*KPMDS,4,0
./arch/x86/kernel/head_32.S:619:        .fill 1024,4,0
./arch/x86/kernel/head_32.S:622:        .fill 1024,4,0
./arch/x86/kernel/head_32.S:624:        .fill 4096,1,0
./arch/x86/kernel/head_32.S:713:        .fill GDT_ENTRY_BOOT_CS,8,0
./arch/x86/kernel/trampoline_64.S:160:        .fill        510,8,0
./arch/x86/kernel/head_64.S:356:        .fill        511,8,0
./arch/x86/kernel/head_64.S:359:        .fill        L3_START_KERNEL,8,0
./arch/x86/kernel/head_64.S:365:        .fill        506,8,0
./arch/x86/kernel/head_64.S:368:        .fill        5,8,0
./arch/x86/kernel/head_64.S:371:        .fill        512,8,0
./arch/x86/kernel/head_64.S:394:        .fill   512, 8, 0
./arch/x86/boot/compressed/head_32.S:188:        .fill BOOT_HEAP_SIZE, 1, 0
./arch/x86/boot/compressed/head_32.S:190:        .fill BOOT_STACK_SIZE, 1, 0
./arch/x86/boot/compressed/head_64.S:320:        .fill BOOT_HEAP_SIZE, 1, 0
./arch/x86/boot/compressed/head_64.S:322:        .fill BOOT_STACK_SIZE, 1, 0
./arch/ia64/kvm/trampoline.S:98:        ld8.fill        r4=[r2],16;                \
./arch/ia64/kvm/trampoline.S:99:        ld8.fill        r5=[r3],16;                \
./arch/ia64/kvm/trampoline.S:101:        ld8.fill        r6=[r2],48;                \
.
.
.
 楼主| 发表于 2009-7-25 08:44:22 | 显示全部楼层
./arch/x86/kernel/head_32.S
------------------------------
/*
* BSS section
*/
.section ".bss.page_aligned","wa"
        .align PAGE_SIZE_asm
#ifdef CONFIG_X86_PAE
swapper_pg_pmd:
        .fill 1024*KPMDS,4,0
#else
ENTRY(swapper_pg_dir)
        .fill 1024,4,0
#endif
swapper_pg_fixmap:
        .fill 1024,4,0
ENTRY(empty_zero_page)
        .fill 4096,1,0
 楼主| 发表于 2009-7-25 08:50:47 | 显示全部楼层
如:
.fill 1024,4,0------------>拷贝1024个块,每个块是4个字节,每个块用0来初始化?
 楼主| 发表于 2009-7-25 13:13:48 | 显示全部楼层
在linuxforum上找到的这本gas手册的翻译项目。
关于这部分的翻译:
-----------------------------------------------
7.28 .fill repeat , size , value
repeat, size and value are absolute expressions. This emits repeat copies of size bytes. Repeat may be zero or more. Size may be zero or more, but if it is more than 8, then it is deemed to have the value 8, compatible with other people’s assemblers. The contents of each repeat bytes are taken from an 8-byte number. The highest order 4 bytes are zero. The lowest order 4 bytes are value rendered in the byte-order of an integer on the computer as is assembling for. Each size bytes in a repetition is taken from the lowest order size bytes of this number. Again, this bizarre behavior is compatible with other people’s assemblers.
size and value are optional. If the second comma and value are absent, value is assumed zero. If the first comma and following tokens are absent, size is assumed to be 1.

7.28 .fill repeat , size , value
repeat, size 和value都必须是纯粹的表达式。本命令生成size个字节的repeat个副本。Repeat可以是0或更大的值。Size 可以是0或更大的值, 但即使size大于8,也被视作8,以兼容其它的汇编器。各个副本中的内容取自一个8字节长的数。最高4个字节为零,最低的4个字节是value,它以 as正在汇编的目标计算机的整数字节顺序排列。每个副本中的size个字节都取值于这个数最低的size个字节。再次说明,这个古怪的动作只是为了兼容其他的汇编器。
size参数和value参数是可选的。如果不存在第2个逗号和value参数,则假定value为零。如果不存在第1个逗号和其后的参数,则假定size为1。

------------------------------------------------------------------------------------------------------
再贴一个关于 alignment 和 padding(对齐和填充 )伪指令 的翻译:

7.3 .align abs-expr, abs-expr, abs-expr
Pad the location counter (in the current subsection) to a particular storage boundary. The first expression (which must be absolute) is the alignment required, as described below.
The second expression (also absolute) gives the fill value to be stored in the padding bytes. It (and the comma) may be omitted. If it is omitted, the padding bytes are normally zero. However, on some systems, if the section is marked as containing code and the fill value is omitted, the space is filled with no-op instructions.
The third expression is also absolute, and is also optional. If it is present, it is the maximum number of bytes that should be skipped by this alignment directive. If doing the alignment would require skipping more bytes than the specified maximum, then the alignment is not done at all. You can omit the fill value (the second argument) entirely by simply using two commas after the required alignment; this can be useful if you want the alignment to be filled with no-op instructions when appropriate.
The way the required alignment is specified varies from system to system. For the a29k, hppa, m68k, m88k, w65, sparc, and Hitachi SH, and i386 using ELF format, the first expression is the alignment request in bytes. For example ‘.align 8’ advances the location counter until it is a multiple of 8. If the location counter is already a multiple of 8, no change is needed.
For other systems, including the i386 using a.out format, and the arm and strongarm, it is the number of low-order zero bits the location counter must have after advancement. For example ‘.align 3’ advances the location counter until it a multiple of 8. If the location counter is already a multiple of 8, no change is needed.
This inconsistency is due to the different behaviors of the various native assemblers for these systems which GAS must emulate. GAS also provides .balign and .p2align directives, described later, which have a consistent behavior across all architectures (but are specific to GAS).


7.3 .align abs-expr, abs-expr, abs-expr
增加位置计数器(在当前的子段)使它指向规定的存储边界。第一个表达式参数(结果必须是纯粹的数字)是必需参数:边界基准,见后面的描述。
第二个表达式参数(结果必须是纯粹的数字)给出填充字节的值,用这个值填充位置计数器越过的地方。这个参数(和逗点)可以省略,如果省略它,填充字节的值通常是0。但在某些系统上,如果本段标识为包含代码,而填充值被省略,则使用no-op指令填充这个空间。
第3个参数表达式的结果也必须是纯粹的数字,这个参数是可选的。如果存在第3个参数,它代表本对齐命令允许越过字节数的最大值。如果完成这个对齐需要跳过的字节比指定的最大值还多,则根本无法完成对齐。您可以在边界基准后简单地使用两个逗号,以省略填充值参数(第二参数);如果您想在适当的时候,对齐操作自动使用no-op指令填充,这个方法将非常奏效。
边界基准的定义因系统而有差异。a29k,hppa,m68k,m88k,w65,sparc,Hitachi SH, 和使用ELF格式的i386,第一个表达式是边界基准,单位是字节。例如‘.align 8’向后移动位置计数器至8的倍数。如果地址已经是8的倍数,则无需移动。
有些其它系统,包括使用a.out格式的i386,ARM和strongarm,这代表位置计数器移动后,计数器中连续为0的低序位数量。例如‘.align 3’向后移动位置计数器直至8的倍数(计数器的最低的3位为0)。如果地址已经是8倍数,则无需移动。
之所以存在这样的区别,是因为GAS需要模仿各种汇编器的不同动作。GAS还提供.balign和.p2align命令,在以后详细讲述,这两条命令在所有的机型上使用相同的动作 (但需要向GAS明确说明机型)。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
快速回复 返回顶部 返回列表