MIPS 的 GNU 汇编器:如何发出sync_* 指令?

发布于 2024-09-16 16:09:01 字数 488 浏览 8 评论 0原文

MIPS32 ISA为sync指令定义了以下格式:

SYNC (stype = 0 implied)
SYNC stype

这里,stype可以是SYNC_WMB(SYNC 4)、SYNC_MB(SYNC 16)等。 在内联汇编器中,我可以使用默认同步:__asm__ volatile ("sync"::);

但是,如果我写类似 __asm__ volatile ("sync 0x10" ::) 的内容,它不会编译:

Error: invalid operands 'sync 0x10'

如果通过 < gcc 的 code>-mips32r2 选项。

那么,问题是:如何使用 GCC 内联汇编中的 SYNC_* (WYNC_WMB, SYNC_MB, SYNC_ACQUIRE, ...) 指令?

MIPS32 ISA defines the following format for the sync instruction:

SYNC (stype = 0 implied)
SYNC stype

here, stype may be SYNC_WMB (SYNC 4), SYNC_MB (SYNC 16), etc.
In inline assembler, I may use default sync: __asm__ volatile ("sync" ::);.

But, if I write something like __asm__ volatile ("sync 0x10" ::), it doesn't compile:

Error: illegal operands 'sync 0x10'

Same if pass -mips32r2 option to gcc.

So, the question is: how to use SYNC_* (WYNC_WMB, SYNC_MB, SYNC_ACQUIRE, ...) instructions from GCC inlined assembly?

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

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

发布评论

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

评论(1

眼波传意 2024-09-23 16:09:01

我怀疑您的 binutils 太旧了 - 看起来对此的支持仅添加于2.20 版。

作为解决方法,如果您无法轻松升级 binutils,则可以手动构建操作码。

sync 是一条操作码 0 指令,其功能代码(位 5..0)为 0xf,这种形式在移位量字段(位10..6)。因此,例如对于 sync 0x10

__asm__ volatile(".word (0x0000000f | (0x10 << 6))");

I suspect that your binutils are too old - it looks like support for this was only added in version 2.20.

As a workaround, if you can't upgrade your binutils easily, you could construct the opcode by hand.

sync is an opcode 0 instruction with a function code (bits 5..0) of 0xf, and this form of it encodes the sync type in the shift amount field (bits 10..6). So, e.g. for sync 0x10:

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