ARM DS-5 Using the Debug Hardware Configuration Utilities
ARM DS-5 Using the Debug Hardware Configuration Utilities
ARM DS-5 Using the Debug Hardware Configuration Utilities
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Debug</strong>ging with your debug hardware unit8.3 Adding an application SVC handler when using debug hardwareMany applications require <strong>the</strong>ir own SVC handlers in addition to semihosting SVCs. To ensurethat <strong>the</strong> application SVC handler cooperates with <strong>the</strong> debug hardware semihosting mechanism,use your debugger to:1. Install <strong>the</strong> application SVC handler into <strong>the</strong> vector table.2. Modify <strong>the</strong> value of SEMIHOST_VECTOR to point to a location that is only reached if yourhandler does not recognize <strong>the</strong> SVC, or recognizes it as a semihosting SVC.For example, a particular SVC handler might detect if it has failed to handle a SVC and branchto an error handler. An example of a basic exception handler is shown in <strong>the</strong> following example.Example 8-1 Basic SVC handler; r0 = 1 if SVC handledCMP r0, #1; Test if SVC has been handled.BNE NoSuchSVC; Call unknown SVC handler.LDMFD sp!, {r0}; Unstack SPSR...MSR spsr_cf, r0; ...and restore it.LDMFD sp!, {r0-r12, pc}^ ; Restore registers and return.You can modify this code for use in conjunction with debug hardware semihosting as shown in<strong>the</strong> following example.Example 8-2 SVC handler with debug hardware link; r0 = 1 if SVC handledCMP r0, #1; Test if SVC has been handled.LDMFD sp!, {r0}; Unstack SPSR...MSR spsr_cf, r0; ...and restore it.LDMFD sp!, {r0-r12, lr} ; Restore registers.MOVEQS pc, lr; Return if SVC handled.Semi_SVCMOVS pc, lrYou must <strong>the</strong>n set up <strong>the</strong> SEMIHOST_VECTOR with <strong>the</strong> address of Semi_SVC. The instruction at thisaddress is never actually executed because <strong>the</strong> debug software returns directly to <strong>the</strong> applicationafter processing <strong>the</strong> semihosted SVC. <strong>Using</strong> a normal SVC return instruction ensures that <strong>the</strong>application does not crash if <strong>the</strong> semihosting breakpoint is not set up.If <strong>the</strong> application is linked with <strong>the</strong> semihosted <strong>ARM</strong> C library, and <strong>the</strong>refore uses <strong>the</strong> C librarystartup code, you must change <strong>the</strong> contents of SEMIHOST_VECTOR before <strong>the</strong> application installs itsown handler, typically by setting a breakpoint in <strong>the</strong> main code. This is because, ifSEMIHOST_VECTOR is set to <strong>the</strong> fall-through part of <strong>the</strong> application SVC handler before <strong>the</strong>application starts execution, <strong>the</strong> semihosted SVCs that are called by <strong>the</strong> library initialization cantrigger an unknown breakpoint error. At this point, <strong>the</strong> SVC vector has not yet had <strong>the</strong>application handler written to it, and might still contain <strong>the</strong> software breakpoint bit pattern. Thistriggers a breakpoint that <strong>the</strong> debug software does not know about, because <strong>the</strong> SEMIHOST_VECTORaddress has moved to a place that cannot currently be reached.NoteIf semihosting is not used by your application, including <strong>the</strong> startup code, you can simplify thisprocess by setting SEMIHOST_ENABLED to zero.<strong>ARM</strong> DUI 0498F Copyright © 2010-2012 <strong>ARM</strong>. All rights reserved. 8-5ID021112Non-Confidential