Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 用于添加新GNU汇编程序x86指令和重新编译的源代码_Assembly_X86_Gnu Assembler - Fatal编程技术网

Assembly 用于添加新GNU汇编程序x86指令和重新编译的源代码

Assembly 用于添加新GNU汇编程序x86指令和重新编译的源代码,assembly,x86,gnu-assembler,Assembly,X86,Gnu Assembler,我正试图找出需要在binutils项目中修改的文件,以便添加一条新的x86指令mov2,它将是mov的精确副本。搜索源文件夹得到了上百个结果,但我仍然找不到任何包含指令引用的文件 谢谢,因为@提到的文件需要修改,我也不得不在IRC上打扰他了解更多细节,但他很好心地指导了我。我可能会注意到,我只能在binutils v2.25上生成,我相信以后的分支会开始使用不同的解决方案,可能与“make-run-cgen”目标有关,但它的研究将持续一天:) 以下是我遵循的步骤: 创建临时目录,一个用于生成,一

我正试图找出需要在binutils项目中修改的文件,以便添加一条新的x86指令
mov2
,它将是
mov
的精确副本。搜索源文件夹得到了上百个结果,但我仍然找不到任何包含指令引用的文件

谢谢,

因为@提到的文件需要修改,我也不得不在IRC上打扰他了解更多细节,但他很好心地指导了我。我可能会注意到,我只能在binutils v2.25上生成,我相信以后的分支会开始使用不同的解决方案,可能与“make-run-cgen”目标有关,但它的研究将持续一天:)

以下是我遵循的步骤:

创建临时目录,一个用于生成,一个用于二进制:

$mkdir -pv /tmp/{instruction-test,tools}
$cd /tmp/instruction-test/
克隆binutils repo或直接从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, world\n"
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

如果您遇到我怀疑与cat/EOF命令有关的问题,您只需尝试使用自己的文件即可。正如我所提到的,这不是最新的解决方案,我在以后的分支上运行i386 gen时遇到了问题,我相信这是由cgen管理的?或者也许我需要处理stdin的使用,但我没有太多时间

如果你真的想说
mov2
,你现在可以说
mov
,也许一个预处理应用程序可以工作。@500 InternalServerError在我确定我还想在mov2Maybe中添加自定义逻辑后,您可以添加一个自我回答,详细说明添加指令所需的所有步骤。这对其他人可能更有用。@Jester当然我能做到,如果没有问题,我会在周末完成一个LFS,除非有英雄愿意这样做
Hello, world