Exit a program without any cleanup.
The OpenRISC 1000 s implementation makes use of the
l.nop
opcode. This opcode takes a 16-bit
immediate operand. Functionally the operand has no effect on the
processor itself. However a simulator can inspect the operand to
provide additional behavior external to the machine.
When executing on Or1ksim, l.nop 1
causes a
tidy exit of the simulator, using the value in
r3
as the return code.
void _exit (int rc) { register int t1 asm ("r3") = rc; asm volatile ("\tl.nop\t%0" : : "K" (NOP_EXIT), "r" (t1)); while (1) { } } /* _exit () */
Note the use of volatile
. Otherwise there is a
strong possibility of an optimizing compiler recognizing that this
opcode does nothing (we are relying on a simulation side-effect)
and removing it.
Caution | |
---|---|
The name of this function is already namespace clean. If a
namespace clean implementation of the system calls has been
specified in |