LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2036|回复: 6

如何在汇编文件中用二进制形式填充一段内存

[复制链接]
发表于 2005-10-30 17:08:43 | 显示全部楼层 |阅读模式
var: .byte 11100000b
貌似不行
gcc -c出错
发表于 2006-1-17 13:11:33 | 显示全部楼层
伪操作
各种编译器不同,伪操作指令也不同
PC上一般是DB,DW
51上直接DATA
ARM上大概是什么DCB  SET之类的
回复 支持 反对

使用道具 举报

发表于 2006-1-18 15:40:30 | 显示全部楼层
from info as:
[HTML]File: as.info,  Node: Fill,  Next: Float,  Prev: File,  Up: Pseudo Ops

`.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 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 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.[/HTML]

内核中有示例:

  1. crq@ $ find linux-2.6.15/arch/i386 -name '*.S'|xargs grep -In '\.fill'
  2. linux-2.6.15/arch/i386/boot/setup.S:984:        .fill GDT_ENTRY_BOOT_CS,8,0
  3. linux-2.6.15/arch/i386/kernel/head.S:422:       .fill 1024,4,0
  4. linux-2.6.15/arch/i386/kernel/head.S:424:       .fill 4096,1,0
  5. linux-2.6.15/arch/i386/kernel/head.S:469:       .fill NR_CPUS-1,8,0             # space for the other GDT descriptors
  6. linux-2.6.15/arch/i386/kernel/head.S:477:       .fill GDT_ENTRY_BOOT_CS,8,0
复制代码
回复 支持 反对

使用道具 举报

发表于 2006-1-18 15:55:54 | 显示全部楼层
  1. crq@ $ find linux-2.6.15 -name '*.S' -type f|xargs grep -Inw '\.fill'
  2. linux-2.6.15/arch/i386/boot/setup.S:984:        .fill GDT_ENTRY_BOOT_CS,8,0
  3. linux-2.6.15/arch/i386/kernel/head.S:422:       .fill 1024,4,0
  4. linux-2.6.15/arch/i386/kernel/head.S:424:       .fill 4096,1,0
  5. linux-2.6.15/arch/i386/kernel/head.S:469:       .fill NR_CPUS-1,8,0             # space for the other GDT descriptors
  6. linux-2.6.15/arch/i386/kernel/head.S:477:       .fill GDT_ENTRY_BOOT_CS,8,0
  7. linux-2.6.15/arch/mips/kernel/genex.S:216:      .fill   LONGSIZE
  8. linux-2.6.15/arch/mips/kernel/head.S:114:       .fill   0x400
  9. linux-2.6.15/arch/s390/kernel/head.S:163:        .fill  80-24,1,0x40                    # bytes 24-79 are discarded !!
  10. linux-2.6.15/arch/s390/kernel/head31.S:284:     .fill   89,1,0
  11. linux-2.6.15/arch/s390/kernel/head31.S:289:     .fill   3984,1,0
  12. linux-2.6.15/arch/s390/kernel/head64.S:278:     .fill 89,1,0
  13. linux-2.6.15/arch/s390/kernel/head64.S:283:     .fill 3984,1,0
  14. linux-2.6.15/arch/sh64/kernel/entry.S:111:      .fill FAST_TLBMISS_STACK_QUADWORDS, 8, 0x0
  15. linux-2.6.15/arch/x86_64/boot/compressed/head.S:137:    .fill 4096,4,0
  16. linux-2.6.15/arch/x86_64/kernel/head.S:247:     .fill   512,8,0
  17. linux-2.6.15/arch/x86_64/kernel/head.S:252:     .fill   511,8,0
  18. linux-2.6.15/arch/x86_64/kernel/head.S:256:     .fill   510,8,0
  19. linux-2.6.15/arch/x86_64/kernel/head.S:259:     .fill   1,8,0
  20. linux-2.6.15/arch/x86_64/kernel/head.S:287:     .fill   492,8,0
  21. linux-2.6.15/arch/x86_64/kernel/head.S:315:     .fill   492,8,0
  22. linux-2.6.15/arch/x86_64/kernel/head.S:337:     .fill   255,8,0
  23. linux-2.6.15/arch/x86_64/kernel/head.S:339:     .fill   254,8,0
  24. linux-2.6.15/arch/x86_64/kernel/head.S:356:     .fill   255,8,0
  25. linux-2.6.15/arch/x86_64/kernel/head.S:358:     .fill   254,8,0
  26. linux-2.6.15/arch/x86_64/kernel/head.S:405:     .fill (GDT_SIZE * NR_CPUS) - (gdt_end - cpu_gdt_table)
  27. crq@ $
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-6-2 19:27:20 | 显示全部楼层
google到自己几年前的帖子。。。。
我的问题关键不是在fill,而是在如何用二进制表示一个数,呵呵
回复 支持 反对

使用道具 举报

发表于 2008-6-22 20:46:26 | 显示全部楼层
这个问题,linux源代码里面有实例,可以参考一下。在编译linux内核的时候,需要生成initramfs,这个过程首先要生成一个initram_data.cpio.gz的二进制文件,然后将这个文件包含在一个汇编文件里面。你看看usr/initramfs_data.S文件。

.section .init.ramfs,"a"
.incbin "usr/initramfs_data.cpio.gz"
回复 支持 反对

使用道具 举报

发表于 2008-6-24 20:49:23 | 显示全部楼层
Post by neversetsun;1858181
google到自己几年前的帖子。。。。
我的问题关键不是在fill,而是在如何用二进制表示一个数,呵呵


Little Endian vs Big Endian ?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表