Hello everyone,
So I am constructing my simple kernel on an ARM CortexM3. To system calls I have created a macro that can take the SVC immediate and arguments.
#define syscall_1(code, args) { \ asm volatile ("MOV %%r0, %0 " \ : \ : "r" (args) \ : "%r0"); \ asm volatile ("svc %[immediate]" \ : \ :[immediate] "I" (code) \ : ); \}#define syscall_2(code, args1, args2) { \ asm volatile ("MOV %%r0, %0\n\t" \ "MOV %%r1, %1\n\t" \ : \ : "r" (args1), \ "r" (args2) \ : "%r0", \ "%r1"); \ asm volatile ("svc %[immediate]" \ : \ :[immediate] "I" (code) \ : ); \}
So I use a C wrapper to manage the callbacks as widely documented around, like on the ARM Cortex M3 Guide and other manuals. But first and most importantly, how would I get a return for this system call? I am storing it at a global, but I would like to be able to do something like ret = syscall(....).
And also, any way to create a single macro to adapt to the number of arguments?
The RTX kernel from ARM has svc macros that achieve something very similar to what you want/need. I did post on this thread several weeks ago but my post was deleted, after being flagged as abusive, which I couldn't fathom. It may have been because I linked so certain files, so I won't do that again. let's just say
in the CMSIS_5 arm repo on github, if you traverse to the CMSIS / RTOS / RTX / Source directory, see rtx_core_cm.h. It has svc macros for several different compilers.
I use these macros in my own code. I added some svc calls to RTX with the goal of achieving a somewhat posix i/o model, e.g. open,close,read,write and in particular select. being able to wait for input data from many devices at same time without having to resort to a multi-threaded model is a big win, IMHO.
Sorry, make that the RTOS2 directory, not RTOS, which is present also.