开发者

GNU assembler for MIPS: how to emit sync_* instructions?

开发者 https://www.devze.com 2023-01-14 07:10 出处:网络
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.

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 t开发者_如何学编程o use SYNC_* (WYNC_WMB, SYNC_MB, SYNC_ACQUIRE, ...) instructions from GCC inlined assembly?


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))");
0

精彩评论

暂无评论...
验证码 换一张
取 消