简体   繁体   English

故意在 RISC-V 中引发非法指令

[英]Raise an Illegal Instruction in RISC-V on Purpose

What is the simplest, most readable and straightforward way to raise an illegal instruction in RISC-V on purpose?在 RISC-V中故意引发非法指令的最简单、最易读和直接的方法是什么?

I know that per spec any "full zero" instruction (so 32/16 bits only zeros) is a "Defined Illegal Instruction" (section 12.5, user spec).我知道根据规范,任何“全零”指令(因此 32/16 位只有零)都是“定义的非法指令”(第 12.5 节,用户规范)。 But I have no idea if there exists an asm shorthand for that (at least I could not find any) that I could then use in inline asm in C code.但我不知道是否存在一个 asm 简写(至少我找不到任何),然后我可以在 C 代码中的内联 asm 中使用它。

There must surely be a portable and reliable way to always cause an illegal instruction exception?肯定有一种可移植且可靠的方法来始终导致非法指令异常? I personally find writing to read-only registers or similar hacks quite offputting, as they are not very explicit.我个人发现写入只读寄存器或类似的黑客非常令人反感,因为它们不是很明确。 But maybe this is just how its done?但也许这就是它的完成方式?

Thank you in advance先感谢您

The mnemonic for it is unimp .它的助记符是unimp It is documented in the RISC-V asm manual , so it should be portable.记录在 RISC-V asm 手册中,因此它应该是可移植的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM