Datasheet

Semihosting
ARM DUI0058D Copyright © 1999-2001 ARM Limited. All rights reserved. 5-9
Caution
It is essential that the actual position
$semihosting_vector
points to within the
application handler is correct.
See exception handling in the ADS Developer Guide for writing SWI handlers.
The following example SWI handler can detect if it fails to handle a SWI. In this case,
it branches to an error handler:
; r0 = 1 if SWI handled
CMP r0, #1 ; Test if SWI has been handled.
BNE NoSuchSWI ; Call unknown SWI handler.
LDMFD sp!, {r0} ; Unstack SPSR...
MSR spsr_cxsf, r0 ; ...and restore it.
LDMFD sp!, {r0-r12,pc}^ ; Restore registers and return.
This code could be modified to co-operate with Multi-ICE semihosting as follows:
; r0 = 1 if SWI handled
CMP r0, #1 ; Test if SWI has been handled.
LDMFD sp!, {r0} ; Unstack SPSR...
MSR spsr_cxsf, r0 ; ...and restore it.
LDMFD sp!, {r0-r12,lr} ; Restore registers.
MOVEQS pc, lr ; Return if SWI handled.
Semi_SWI
MOVS pc,lr ; Fall through to Multi-ICE
; interface handler.
The
$semihosting_vector
variable must be set up to point to the address of
Semi_SWI
. The
instruction at
Semi_SWI
never gets executed because Multi-ICE returns directly to the
application after processing the semihosted SWI (see Figure 5-2 on page 5-10).
Caution
Using a normal SWI return instruction ensures that the application does not crash if the
semihosting breakpoint is not set up. The semihosting action requested is not carried out
and the handler simply returns.
You must also be careful if you modify
$semihosting_vector
to point to the fall-through
part of the application SWI handler. If
$semihosting_vector
changes value before the
application starts execution, and semihosted SWIs are invoked before the application
SWI handler is installed, an unknown watchpoint error will occur.