__svc
Syntax
See Syntax for type attributes used on functions.
Description
32-bit mode:
The __svc keyword declares a software interrupt function. It inserts an SVC (formerly SWI) instruction and the specified software interrupt number to make a proper function call. A function declared __svc accepts arguments and returns values. The __svc keyword makes the compiler generate the correct return sequence for a specific software interrupt function. Software interrupt functions follow the same calling convention regarding parameters and return values as an ordinary function, except for the stack usage.
The __svc keyword also expects a software interrupt number which is specified with the #pragma svc_number=number directive. The svc_number is used as an argument to the generated assembler SVC instruction, and can be used by the SVC interrupt handler, for example SVC_Handler, to select one software interrupt function in a system that contains several such functions.
Note
The software interrupt number should only be specified in the function declaration—typically, in a header file that you include in the source code file that calls the interrupt function—not in the function definition.
Note
All interrupt functions must be compiled in Arm mode, except for Cortex-M. Use either the __arm keyword or the #pragma type_attribute=__arm directive to alter the default behavior if needed.
64-bit mode:
The __svc keyword makes a function usable in one of the exception vectors in the 64-bit Arm exception table. See Exception functions for 64-bit mode.
Example
To declare your software interrupt function, typically in a header file, write for example like this:
#pragma svc_number=0x23 __svc int svc0x23_function(int a, int b); ...
To call the function:
... int x = svc0x23_function(1, 2); /* Will be replaced by SVC 0x23, hence the linker will never try to locate the svc0x23_function */ ...
Somewhere in your application source code, you define your software interrupt function:
...
__svc __arm int the_actual_svc0x23_function(int a, int b)
{
...
return 42;
}See also
Software interrupts, Calling convention, and Exception functions for 64-bit mode.