Services and Modeling for Embedded Software Development
Embecosm divider strip
Prev  Next

5.3.3.  Exit a program, _exit

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]Caution

The name of this function is already namespace clean. If a namespace clean implementation of the system calls has been specified in configure.host (see Section 3.3.1), then this function is still named _exit, not __exit.

Embecosm divider strip