The number of system calls needs to support the sizeof(uintptr_t)

arch: armv7m
I need to add a custom SystemCall instruction to execute a custom function.
However, the maximum number of system call instructions is 255.

this is my solution:

....
#define SYSTEM_CALL_User   80
#define SYSTEM_CALL_xUartSend   10001 
....
PRIVILEGED_DATA UBaseType_t uxSystemCallImplementations[ NUM_SYSTEM_CALLS ] =
{
 ...
 xUartSendImpl,
}


...
BaseType_t MPU_xUartSend(..... )
{
__asm volatile
(
    " .syntax unified                                       \n"
                " .extern MPU_xUartSendImpl                            \n"
                "                                                       \n"
                " push {r0}                                             \n"
                " mrs r0, control                                       \n"
                " tst r0, #1                                            \n"
                " pop {r0}                                              \n"
                " bne MPU_xUartSend_Unpriv                             \n"
                " MPU_xUartSend_Priv:                                  \n"
                "     b MPU_xUartSendImpl                              \n"
                " MPU_xUartSend_Unpriv                                 \n"
                "     svc %0                                            \n"
                "                                                       \n"
               pc+x : "i" ( SYSTEM_CALL_User ) : "memory" 
                pc+y : "i" ( .word SYSTEM_CALL_xUartSend   ) : "memory"  //define a word :system call id I am not familiar with assembly syntax.
);
} 
...
void vSystemCallEnter( uint32_t * pulTaskStack,
                           uint32_t ulLR,
                           uint8_t ucSystemCallNumber ) 
{
....
ulSystemCallLocation = pulTaskStack[ portOFFSET_TO_PC ];
if( ( ulSystemCallLocation >= ( uint32_t ) __syscalls_flash_start__ ) &&
            ( ulSystemCallLocation <= ( uint32_t ) __syscalls_flash_end__ ) &&
            ( pxMpuSettings->xSystemCallStackInfo.pulTaskStack == NULL ) &&
           //// ( uxSystemCallImplementations[ ucSystemCallNumber ] != ( UBaseType_t ) 0 ) )
{
...
if( ucSystemCallNumber >=SYSTEM_CALL_User )
{
    ucSystemCallNumber =*(pulTaskStack[ portOFFSET_TO_PC ]+y); 
}
if(uxSystemCallImplementations[ ucSystemCallNumber ] !=0)
{
...
}
.....
 ......
...
}
....
}

Would you please describe your usecase - like what problem are you trying to solve?

How many system calls do you want to add?

This depends on the user and should not restrict the user…

like:uart send,uart config,can send ,can config, eth…

BaseType_t MPU_xUartSend(… )
{
__asm volatile
(
" .syntax unified \n"
" .extern MPU_xUartSendImpl \n"
" \n"
" push {r0} \n"
" mrs r0, control \n"
" tst r0, #1 \n"
" pop {r0} \n"
" bne MPU_xUartSend_Unpriv \n"
" MPU_xUartSend_Priv: \n"
" b MPU_xUartSendImpl \n"
" MPU_xUartSend_Unpriv \n"
" svc %0 \n"
" \n"
pc+x : “i” ( SYSTEM_CALL_User ) : “memory”
pc+y : “i” ( .word SYSTEM_CALL_xUartSend ) : “memory” //define a word :system call id. I am not familiar with assembly syntax.
);

I would probably add a single “User” system call, with just a single ID number (maybe 255), and take as a parameter a “function” that the user system call could vector on.

(edit): The problem with adding additional parameters after the sys call instruction is that the sys call handler will need assembly instructions to advance the return pointer past them, and the debugger disassembler won’t understand what is happening.

If you don’t understand how to write the assembly syntax, then this tasks gets harder.

1 Like

Can you not have a task for managing a peripheral and explicitly grant it permission to access the peripheral it manages?