841764b6ddc49180de164def39822b7735359650
[tpg/acess2.git] / Kernel / arch / armv7 / proc.S
1 /*
2  * Acess2 ARM
3  * - By John Hodge (thePowersGang)
4  *
5  * arch/arm7/proc.S
6  * - Process management assembly
7  */
8
9 #define PUSH_GPRS \
10         str r0, [sp,#-1*4];\
11         str r1, [sp,#-2*4];\
12         str r2, [sp,#-3*4];\
13         str r3, [sp,#-4*4];\
14         str r4, [sp,#-5*4];\
15         str r5, [sp,#-6*4];\
16         str r6, [sp,#-7*4];\
17         str r7, [sp,#-8*4];\
18         str r8, [sp,#-9*4];\
19         str r9, [sp,#-10*4];\
20         str r10, [sp,#-11*4];\
21         str r11, [sp,#-12*4];\
22         str r12, [sp,#-13*4];\
23         str sp, [sp,#-14*4];\
24         str lr, [sp,#-15*4];\
25         sub sp, #16*4
26
27 #define POP_GPRS add sp, #16*4; \
28         ldr r0, [sp,#-1*4]; \
29         ldr r1, [sp,#-2*4]; \
30         ldr r2, [sp,#-3*4]; \
31         ldr r3, [sp,#-4*4]; \
32         ldr r4, [sp,#-5*4]; \
33         ldr r5, [sp,#-6*4]; \
34         ldr r6, [sp,#-7*4]; \
35         ldr r7, [sp,#-8*4]; \
36         ldr r8, [sp,#-9*4]; \
37         ldr r9, [sp,#-10*4]; \
38         ldr r10, [sp,#-11*4]; \
39         ldr r11, [sp,#-12*4]; \
40         ldr r12, [sp,#-13*4]; \
41         ldr lr, [sp,#-15*4];
42
43 .globl KernelThreadHeader
44 @ SP+12: Argument 1
45 @ SP+8: Argument Count
46 @ SP+4: Function
47 @ SP+0: Thread Pointer
48 KernelThreadHeader:
49         ldr r0, [sp],#4
50         @ TODO: Do something with the thread pointer
51         
52         ldr r4, [sp],#4 @ Function
53         ldr r5, [sp],#4
54         @ Get arguments
55         sub r5, #1
56         ldrhs r0, [sp],#4
57         sub r5, #1
58         ldrhs r1, [sp],#4
59         sub r5, #1
60         ldrhs r2, [sp],#4
61         sub r5, #1
62         ldrhs r3, [sp],#4
63
64         mov lr, pc
65         mov pc, r4
66         
67         ldr r0, =0
68         bl Threads_Exit
69         b .
70
71 .globl SwitchTask
72 @ R0: New stack
73 @ R1: Pointer to where to save old stack
74 @ R2: New IP
75 @ R3: Pointer to save old IP
76 @ SP+0: New address space
77 SwitchTask:
78         PUSH_GPRS
79         
80         ldr r4, =.return
81         str r4, [r3]
82         str sp, [r1]
83         mov r0, sp
84         
85         @ Only update TTBR0 if the task has an explicit address space
86         ldr r0, [sp,#0x40]
87         tst r0, r0
88         mcrne p15, 0, r0, c2, c0, 0     @ Set TTBR0 to r0
89
90         mov pc, r2
91
92 .return:
93         POP_GPRS
94         bx lr
95

UCC git Repository :: git.ucc.asn.au