J-Link / J-Trace (UM08001) © 2004-2017 SEGGER Microcontroller GmbH & Co. KG
457
mally in case no debugger is connected and handling the semihosting call. It also
inhibits the CPU from being halted on each non-semihosting call, preserving the real-
time behavior of the target application.
Advantages
Application also runs stand-alone (no debugger connected).
Real-time behavior of the application is preserved.
Disadvantages
One hardware breakpoint is not available for debugging / stepping as it is perma-
nently used while semihosting is enabled.
Only works with J-Link GDBServer as other debuggers do not support this specialized
version.
19.3.3.1 SVC exception handler sample code
In the following, some sample code for the SVC handler, prepared to be used with J-
Link GDBServer optimized semihosting, is given:
SVC_Handler:
;
; For semihosting R0 and R1 contain the semihosting information and may not
; be changed before semihosting is handled.
; If R2 and R3 contain values for the SVC handler or need to be restored for
; the calling function, save them on the stack.
;
#if SAVE_REGS_IN_SVC
PUSH {R2,R3}
#endif
BIC R2, LR, #0xFFFFFFFE
CMP R2, #0x01 ; Check whether we come from Thumb or ARM mode
BNE CheckSemiARM
CheckSemiThumb:
#if BIG_ENDIAN
LDRB R2, [LR, #-2]
#else
LDRB R2, [LR, #-1]
#endif
LDR R3, _DataTable2
CMP R2, R3 ; ARM semihosting call?
BNE DoSVC
B SemiBreak
CheckSemiARM:
LDR R2, [LR, #-4]
BIC R2, R2, #0xFF000000
LDR R3, _DataTable1
CMP R2, R3 ; Thumb semihosting call?
BNE DoSVC
#if SAVE_REGS_IN_SVC
POP {R2,R3} ; Restore regs needed for semihosting
#endif
SemiBreak: ; Debugger will set a breakpoint here and perform exception return
NOP
MOVS R0, #+0 ; Make sure we have a valid return value in case
BX LR ; debugger is not connected
DoSVC:
;
; Customer specific SVC handler code
;
MOVS R0, #+0 ; Replace this code with your SVC Handler
BX LR
_DataTable1:
.word 0x00123456
_DataTable2:
.byte 0xAB
.byte 0x00
.byte 0x00
.byte 0x00