I have a function that I want to put into the SVC exception vector, but I can't seem to find the syntax necessary to put the function's address into that vector. Can anyone suggest a resource to help?
3 Answers
A good tutorial has been writen by valvers for bare metal raspberry pi programming. Despite the CPU is not the same, the underlying concept of exception, is the same. You should definitely have a look there.
A former colleague of mine has written an HAL for Cortex M4. In it, he sets interrupt handlers in C, without any assembly calls, just using symbol's location. You should also have a look on RFLPC.
Assuming you have a symbol called your_function_name
the following code would branch to it.
SVC_Handler
EXTERN your_function_name
ldr r0,=your_function_name
bx r0
As a rule though the handlers are usually weakly linked so having a function void SVC_Handler(void)
should end up linked rather than the handler defined in the startup file.
Too vague this is very specific to your code, and there are a number of ways to implement the cortex-m vector table and use GNU tools, so you have not provided enough information, and while finding that information for us it should become obvious where your table is. You can start by disassembling the elf version of your binary and find label names in the vector table area then grep your code base for those names. If you are riding on top of a bunch of someone elses libraries, etc it may be even more painful to deal with there may be function calls etc runtime that you use to register the handler.
There are a million ways to solve this and all may work, which one are you using?