从编译器源代码中提取ARMv8的指令编码

2012年11月份的资料,之前ARMv8手冊还没公布,我想办法从编译器的binutils中提取出了全部ARMv8指令的二进制编码,之前不能随便发,如今相当于解禁了^_^。

问题1:提取ARMv8的指令编码

答:ARMv8指令的opcode能够在支持ARMv8的编译器binutils中找到,该工具能在网上找到,见參考资料[1],或者在[1]中搜索aarch64_opcode_table。

为了说明指令编码细节。现将网页中部分内容摘录例如以下:

1208
struct aarch64_opcode aarch64_opcode_table[] =

1209 {

1210  /* Add/subtract (with carry).  */

1211  {"adc", 0x1a000000, 0x7fe0fc00, addsub_carry, 0, CORE, OP3 (Rd, Rn, Rm), QL_I3SAMER, F_SF},

p=jk/arm64/binutils.git;a=blob;f=opcodes/aarch64-tbl.h;h=d360b1406718257da86050f5b3a760cd02196250;hb=aarch64#l1212">1212  {"adcs", 0x3a000000, 0x7fe0fc00, addsub_carry, 0, CORE, OP3 (Rd, Rn, Rm), QL_I3SAMER, F_SF},

以上结构体中的每一项相应某条指令的操作码等信息。当中aarch64_opcode结构体(见參考文献[2])在。内容摘录例如以下:

structaarch64_opcode

{

/*The name of the mnemonic.  */

const char *name;

/*The opcode itself.  Those bits which willbe filled in with operands are zeroes. */

aarch64_insn opcode;

/*The opcode mask.  This is used by thedisassembler.  This is a mask containingones indicating those bits which must match the opcode field, and zeroesindicating those bits which need not match (and are presumably filled in byoperands).  */

aarch64_insn mask;

/*Instruction class.
 */

enum aarch64_insn_class iclass;

/*Enumerator identifier.  */

enum aarch64_op op;

/*Which architecture variant provides this instruction.  */

const aarch64_feature_set *avariant;

/*An array of operand codes.  Each code isan index into the operand table.  Theyappear in the order which the operands must appear in assembly code, and are terminatedby a zero.  */

enum aarch64_opnd operands[AARCH64_MAX_OPND_NUM];

/*A list of operand qualifier code sequence. Each operand qualifier code qualifies the corresponding operandcode.  Each operand qualifier sequencespecifies a valid opcode variant and related constraint on operands.  */

aarch64_opnd_qualifier_seq_t qualifiers_list[AARCH64_MAX_QLF_SEQ_NUM];

/*Flags providing information about this instruction */

uint32_t flags;

}

依照以上信息解释aarch64_opcode_table中的结构体例如以下表:


"adc",


0x1a000000


0x7fe0fc00


 addsub_carry,


 0


CORE


OP3 (Rd, Rn, Rm)


QL_I3SAMER, 


F_SF


助记符


操作码


操作码掩码


指令所属类


枚举器标识符


提供这样的指令的结构体变量


操作数编码数组


操作数限定符的代码序列列表


指令信息标志位

1:Aarch64-opc.c中有关于指令位域的定义。

const aarch64_field fields[] =

{

{  0,  0 },      /*NIL.  */

{  0,  4 },      /*cond2: condition in truly conditional-executed inst.  */

{  0,  4 },      /*nzcv: flag bit specifier, encoded in the "nzcv" field.  */

{  5,  5 },      /*defgh: d:e:f:g:h bits in AdvSIMD modified immediate.  */

{16,  3 },       /*abc: a:b:c bits in AdvSIMD modified immediate. */

{  5, 19 },       /* imm19: e.g. in CBZ. */

{  5, 19 },       /* immhi: e.g. in ADRP. */

{29,  2 },       /*immlo: e.g. in ADRP.  */

{22,  2 },       /*size: in most AdvSIMD and floating-point instructions.  */

{10,  2 },       /*vldst_size: size field in the AdvSIMD load/store inst.  */

{29,  1 },       /*op: in AdvSIMD modified immediate instructions. */

{30,  1 },       /*Q: in most AdvSIMD instructions.  */

{  0,  5 },      /*Rt: in load/store instructions.  */

{  0,  5 },      /*Rd: in many integer instructions.  */

{  5,  5 },      /*Rn: in many integer instructions.  */

{10,  5 },       /*Rt2: in load/store pair instructions.  */

{10,  5 },       /*Ra: in fp instructions.  */

{  5,  3 },      /*op2: in the system instructions.  */

{  8,  4 },      /*CRm: in the system instructions.  */

{12,  4 },       /*CRn: in the system instructions.  */

{16,  3 },       /*op1: in the system instructions.  */

{19,  2 },       /*op0: in the system instructions.  */

{10,  3 },       /*imm3: in add/sub extended reg instructions. */

{12,  4 },       /*cond: condition flags as a source operand. */

{12,  4 },       /*opcode: in advsimd load/store instructions. */

{12,  4 },       /*cmode: in advsimd modified immediate instructions.  */

{13,  3 },       /*asisdlso_opcode: opcode in advsimd ld/st single element.  */

{13,  2 },       /*len: in advsimd tbl/tbx instructions.  */

{16,  5 },       /*Rm: in ld/st reg offset and some integer inst. */

{16,  5 },       /*Rs: in load/store exclusive instructions. */

{13,  3 },       /*option: in ld/st reg offset + add/sub extended reg inst.  */

{12,  1 },       /*S: in load/store reg offset instructions. */

{21,  2 },       /*hw: in move wide constant instructions. */

{22,  2 },       /*opc: in load/store reg offset instructions. */

{23,  1 },       /*opc1: in load/store reg offset instructions. */

{22,  2 },       /*shift: in add/sub reg/imm shifted instructions. */

{22,  2 },       /*type: floating point type field in fp data inst.  */

{30,  2 },       /*ldst_size: size field in ld/st reg offset inst. */

{10,  6 },       /*imm6: in add/sub reg shifted instructions. */

{11,  4 },       /*imm4: in advsimd ext and advsimd ins instructions.  */

{16,  5 },       /*imm5: in conditional compare (immediate) instructions.  */

{15,  7 },       /*imm7: in load/store pair pre/post index instructions.  */

{13,  8 },       /*imm8: in floating-point scalar move immediate inst.  */

{12,  9 },       /*imm9: in load/store pre/post index instructions.  */

{10, 12 },         /* imm12: in ld/stunsigned imm or add/sub shifted inst.  */

{  5, 14 },       /* imm14: in test bit and branch instructions.  */

{  5, 16 },       /* imm16: in exception instructions.  */

{  0, 26 },       /* imm26: in unconditional branch instructions.  */

{ 10, 6 },       /* imms: in bitfield andlogical immediate instructions.  */

{16,  6 },       /*immr: in bitfield and logical immediate instructions.  */

{16,  3 },       /*immb: in advsimd shift by immediate instructions.  */

{19,  4 },       /*immh: in advsimd shift by immediate instructions.  */

{22,  1 },       /*N: in logical (immediate) instructions. */

{11,  1 },       /*index: in ld/st inst deciding the pre/post-index.  */

{24,  1 },       /*index2: in ld/st pair inst deciding the pre/post-index.  */

{31,  1 },       /*sf: in integer data processing instructions. */

{11,  1 },       /*H: in advsimd scalar x indexed element instructions.  */

{21,  1 },       /*L: in advsimd scalar x indexed element instructions.  */

{20,  1 },       /*M: in advsimd scalar x indexed element instructions.  */

{31,  1 },       /*b5: in the test bit and branch instructions. */

{19,  5 },       /*b40: in the test bit and branch instructions. */

{10,  6 },       /*scale: in the fixed-point scalar to fp converting inst.  */

};

2、函数aarch64_opcode_encode用于将操作数插入opcode中

參考资料

[1] ARMv8的编译器binutils,结构体aarch64_opcode_table定义见line 1208

p=jk/arm64/binutils.git;a=blob;f=opcodes/aarch64-tbl.h;h=d360b1406718257da86050f5b3a760cd02196250;hb=aarch64">http://kernel.ubuntu.com/git?p=jk/arm64/binutils.git;a=blob;f=opcodes/aarch64-tbl.h;h=d360b1406718257da86050f5b3a760cd02196250;hb=aarch64

[2] 结构体aarch64_opcode定义,line451

http://kernel.ubuntu.com/git?p=jk/arm64/binutils.git;a=blob;f=include/opcode/aarch64.h;h=98529954ea098349eb16572d4915f4edbd2e7b5d;hb=aarch64

[3] 《ARMv8 InstructionSet Overview 》page11

时间: 2024-08-07 04:30:24

从编译器源代码中提取ARMv8的指令编码的相关文章

提取ARMv8的指令编码

2012年11月份的资料,之前ARMv8手册还没发布,我想办法从编译器的binutils中提取出了所有ARMv8指令的二进制编码,之前不能随便发,现在相当于解禁了^_^. 问题1:提取ARMv8的指令编码 答:ARMv8指令的opcode可以在支持ARMv8的编译器binutils中找到,该工具能在网上找到,见参考资料[1],或者在[1]中搜索aarch64_opcode_table. 为了说明指令编码细节,现将网页中部分内容摘录如下: 1208 struct aarch64_opcode aa

从PHP源代码中提取出来的md5 - md5.h

md5.h /*    +----------------------------------------------------------------------+    | PHP Version 5                                                        |    +----------------------------------------------------------------------+    | Copyrigh

从Wireshark监听的数据中提取需要的数据

最近,需要将wireshark监听的数据进行提取,分两步:首先,应该得出wireshark的数据包吧,在图形化界面中可以非常直观的将监听数据进行存储,但是这样需要手动操作非常麻烦,而且容易出错(随着处理数据包的数量增加,图形化可能吃不消,以前就遇见过),在linux下,采用了tshark命令,tshark就是wireshark图形界面命令行化,命令如下: sudo tshark -f "udp port 1243" -i eth0 (-w)> /tmp/capture.cap 对

【转】如何单独编译Android源代码中的模块

原文网址:http://blog.csdn.net//article/details/6566662/ 第一次下载好Android源代码工程后,我们通常是在Android源代码工程目录下执行make命令,经过漫长的等待之后,就可以得到Android系统镜像system.img了.以后如果我们修改了Android源代码中的某个模块或者在Android源代码工程新增一个自己的模块,是不是还是执行make命令呢?答案是否定的,Google为我们准备了另外的命令来支持编译单独的模块,以及重新打包syst

使用t-sql从身份证号中提取生日

使用t-sql从身份证号中提取生日,一下是转换16位身份证号的例子,仅供参考. create function getDateFromID( @id char(15) ) returns datetime as begin declare @birthPart char(6); set @birthPart = substring(@id,7,6); declare @year int; set @year = cast(left(@birthPart,2) as int); if @year

试图从数据库 ‘UFData_001_2003' 中提取的逻辑页 (1:10720) 属于对象 '0',而非对象 'syscolumns'

数据库可以使用,可以备份,但对备份进行恢复时报错,使用sp_attach_db对两个物理文件进行连接时,报同样错误: 服务器: 消息 605,级别 21,状态 1,行 1 试图从数据库 ‘UFData_001_2003' 中提取的逻辑页 (1:10720) 属于对象 '0',而非对象 'syscolumns'. 连接中断 注:严重级别 21:数据库 (dbid) 进程中的 SQL Server 严重错误 这些消息表明遇到了影响当前数据库中所有进程的问题:但数据库本身损坏的可能性不大 错误分析 针

SQLServer 从xml 文件中提取节点数据到数据库中

原文出处:http://blog.csdn.net/kk185800961/article/details/12350715  转载请注明出处 XML实例文件: <?xml version="1.0" encoding="utf-8"?> <!-- edited with XMLSpy v2010 (http://www.altova.com) by fengshuai (founder) --> <Root> <Frame

ant中提取properties和xml提高代码复用性

本文接着上文对前面的示例进行优化,在前面的build.xml中,有些代码是重复的,我们可以将其抽象出来拿来共同使用,比如将一些路劲提取出来放入properties,可以达到共用的同时,还可以增强程序的可维护性,以后路劲变了只需改配置文件,不用改动build.xml.properties维护简单,以键值对形式存放:而xml不单可以提取属性,还可以提取target. 比如在上文中可以将src1,src2,src3的路劲提取出来,放入properties,以后要是路劲变了,直接更改properties

C#控制台基础 在博客备份xml文件中提取所有博文的标题 (正则,流读取)

镇场诗: 清心感悟智慧语,不着世间名与利.学水处下纳百川,舍尽贡高我慢意. 学有小成返哺根,愿铸一良心博客.诚心于此写经验,愿见文者得启发.------------------------------------------ introduction: 解析 博客园-博客备份 生成的XML文件,获得所有博文的标题. code: 1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System