System Calls cleanup, multiple Processes and context switch
[cortex-from-scratch] / lib / syscall.c
1 /* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL
2  * 
3  * $LOG$
4  * 2019/9/21 - ROBIN KRENS      
5  * Initial version 
6  * 
7  * $DESCRIPTION$
8  * System calls for various user functions
9  *
10  */
11
12 #include <stdbool.h>
13 #include <stddef.h>
14 #include <stdint.h>
15
16 #include <lib/syscall.h>
17
18 /* Arguments are placed in r0, r1, r2 by convention
19  * And "parsed" to the the kernel
20  * Right after the svc call, r0 contains status
21  * of call (ie. OK, SYSERR) */
22
23 int theos_uptime() {
24
25         asm volatile("svc 7");
26         int ret;
27         asm volatile("mov %0, r0" : "=r" (ret));        
28         return ret;
29 }
30
31         
32 int theos_init(uint32_t * p) {
33         asm volatile("svc 1");
34
35         return -1;
36 }
37
38 __attribute__ ((naked))
39 int theos_switch(uint32_t * p1, uint32_t * p2) {
40
41         asm volatile("push {lr}");
42         asm volatile("svc 4");
43         asm volatile("pop {lr}");
44         asm volatile("bx lr");
45         // should not be here
46         for(;;);
47         
48 }
49
50 int theos_test(int arg1, int arg2, int arg3) {
51         
52         asm volatile("svc 11");
53         int ret;
54         asm volatile("mov %0, r0" : "=r" (ret));        
55         return ret;
56 }