如何从 gcc(或其他地方)获取合法 ARM 操作码的列表?

发布于 2024-10-22 05:36:04 字数 168 浏览 1 评论 0原文

我想生成伪随机 ARM 指令。通过汇编器指令,我可以告诉 gcc 我处于什么模式,如果我尝试一组在该模式下不合法的操作码和操作数,它会抱怨,因此它必须有一些内部列表,说明在哪种模式下可以做什么。那住在哪里?从 LLVM 中提取该信息会更容易吗?

这个问题是不是“根本就没有错”?我应该尝试完全不同的方法吗?

I'd like to generate pseudo-random ARM instructions. Via assembler directives, I can tell gcc what mode I'm in, and it will complain if I try a set of opcodes and operands that's not legal in that mode, so it must have some internal listing of what can be done in which mode. Where does that live? Would it be easier to extract that info from LLVM?

Is this question "not even wrong"? Should I try a different approach entirely?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尽揽少女心 2024-10-29 05:36:04

为了回答我自己的问题,这实际上很容易从 gcc/config/arm/ 中的arm.md 和constraints.md 完成。我可能花了更多的时间来回答这个问题并回答评论,而不是弄清楚这个问题。结果我只需要寻找'TARGET_THUMB1',直到我开始实现thumb2。

To answer my own question, this is actually really easy to do from arm.md and and constraints.md in gcc/config/arm/. I probably spent more time answering asking this question and answering comments for it than I did figuring this out. Turns out I just need to look for 'TARGET_THUMB1', until I get around to implementing thumb2.

迟月 2024-10-29 05:36:04

对于 ARM 系列,责任仅限于 ARM ARM(ARM 架构参考手册)。有ARM指令集部分和Thumb指令集部分。在这两条指令中,每条指令都会告诉您第几代(ARMvX,其中 X 是某个数字,例如 4(arm7)或 5(arm9 时间范围)等)。由于每个指令都列出了操作码和伪代码,因此您应该能够弄清楚什么是真正的指令,如果有的话,是节省在另一条指令上输入的语法(例如推送和弹出)。

特别是对于 Cortex-m3 和thumb2,您还需要查看 TRM(技术参考手册)。我忘记了 ARM 的名称,他们正在尝试使用一种通用语法,该语法应该适用于 Thumb 和 ARM。例如,在 ARM 上,您有三个寄存器指令:

add r1,r1,r2

总而言之,只有两个寄存器操作

add r1,r2

愿望基本上是在中间相遇,或者更准确地说,是为了鼓励 ARM 汇编器解析 Thumb 指令并使用等效的 ARM 指令对它们进行编码没有抱怨。这可能是从thumb而不是thumb2开始的,直到最近我一直在代码中分离这两种语法(并且我通常仍然对ARM使用ARM语法,对Thumb使用Thumb语法)。

然后,是的,您必须查看汇编工具的具体实现是什么,在您的例子中是 binutils。听起来你已经找到了 binutils/gnu 秘密解码器环。

For the ARM family the buck stops at the ARM ARM (ARM Architectural Reference Manual). There is an ARM instruction set section and a Thumb instruction set section. Within both each instruction tells you what generation (ARMvX where X is some number like 4 (arm7), or 5 (arm9 time frame) ,etc). Since the opcode and pseudo code is listed for each instruction you should be able to figure out what is a real instruction and, if any, are syntax to save typing on another (push and pop for example).

With the Cortex-m3 and thumb2 in particular you also need to look at the TRM (Technical Reference Manual) as well. ARM has, I forget the name, a universal syntax they are trying to use that should work on both Thumb and ARM. For example on an ARM you have three register instructions:

add r1,r1,r2

In thumb there are only two register operations

add r1,r2

The desire basically is to meet in the middle or I would say more accurately to encourage ARM assemblers to parse Thumb instructions and encode them with the equivalent ARM instruction without complaining. This may have started with thumb and not thumb2, I have always separated the two syntaxes in my code until recently (and I still generally use ARM syntax for ARM and Thumb for Thumb).

And then yes you have to see what the specific implementation of the assembler tool is, in your case binutils. And it sounds like you have found the binutils/gnu secret decoder ring.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文