我正在尝试找出我需要在binutils项目中修改哪个文件,以便我可以添加新的x86指令mov2
这将是mov
的精确副本。搜索源文件夹产生了数百个结果,但我仍然找不到任何包含指令引用的文件。
谢谢
正如@Jester提到的需要修改的文件是操作码/i386-opc.tbl 我也不得不在 IRC 上打扰他以获取更多详细信息,但他很好心地指导我。我可能会注意到我只能在 binutils v2.25 上生成,我相信后来的分支开始使用不同的解决方案,可能与"make run-cgen"目标有关,但它的研究还有另一天:(
以下是我遵循的步骤:
创建临时目录,一个用于构建,一个用于二进制文件:
$mkdir -pv /tmp/{instruction-test,tools}
$cd /tmp/instruction-test/
克隆 binutils 存储库,或者您可以直接从 GNU FTP 下载:
$git clone http://sourceware.org/git/binutils-gdb.git
切换到分支:
$cd binutils/
$git checkout binutils-2_25
预构建项目:
$mkdir -v build
$cd build
$../configure --prefix=/tmp/tools --with-sysroot=/tmp/tools --with-lib-path=/tmp/tools/lib --target=x86_64-custom-linux-gnu --disable-nls --disable-werror
$make clean
$time make -s -j XX > make.log || { echo "can not make project, please check logs installation aborted" ; exit 1; }
现在添加 MOV2 指令作为 MOV 的精确副本
$cd ../opcodes
$cat i386-opc.tbl | egrep -e '^mov,' | sed 's/mov/mov2/g' >> i386-opc.tbl
现在您可以在此处暂停一下,看看我们添加了什么:
$git diff i386-opc.tbl
现在我们还需要更新 i386 操作码表:
$cd ../build/opcodes
$make i386-gen
$./i386-gen --srcdir=$(pwd)/../../opcodes
现在我们可以重建并安装到/tmp/tools 中:
$cd ..
$time make -s > make.log
$make -s install > install.log
是时候测试了!下面是带有新说明的小示例:
$cat > /tmp/hello << EOF
.global _start
.text
_start:
# write(1, message, 13)
mov2 $1, %rax # system call 1 is write
mov2 $1, %rdi # file handle 1 is stdout
mov2 $message, %rsi # address of string to output
mov2 $13, %rdx # number of bytes
syscall # invoke operating system to do the write
# exit(0)
mov2 $60, %rax # system call 60 is exit
xor %rdi, %rdi # we want return code 0
syscall # invoke operating system to exit
message:
.ascii "Hello, worldn"
EOF
$cd /tmp/tools/bin
$./x86_64-custom-linux-gnu-as -o /tmp/hello.o /tmp/hello
$ld /tmp/hello.o -o /tmp/hello.bin
$cd /tmp/
$./hello.bin
现在您应该能够看到输出:
Hello, world
如果您遇到问题,我怀疑它与cat/EOF命令有关,您可以简单地尝试使用自己的文件。正如我提到的,这不是最新的解决方案,我在以后的分支上运行 i386-gen 时遇到了问题,我相信这些分支由 cgen 管理?或者也许我需要处理这里使用的 stdin,但我没有太多时间