4acc751f6b128879b4961f2ec9fb86e1589a28b8
[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 #include "include/assembly.h"
10
11 .globl KernelThreadHeader
12 @ SP+12: Argument 1
13 @ SP+8: Argument Count
14 @ SP+4: Function
15 @ SP+0: Thread Pointer
16 KernelThreadHeader:
17         ldr r0, [sp],#4
18         @ TODO: Do something with the thread pointer
19         
20         ldr r4, [sp],#4 @ Function
21         @ Get argument
22         ldr r0, [sp],#4
23
24         blx r4
25         
26         ldr r0, =0
27         bl Threads_Exit
28         b .
29
30 .globl Proc_int_DropToUser
31 @ R0: User IP
32 @ R1: User SP
33 Proc_int_DropToUser:
34         cps #16
35         mov sp, r1
36         mov pc, r0
37
38 .globl SwitchTask
39 @ R0: New stack
40 @ R1: Pointer to where to save old stack
41 @ R2: New IP
42 @ R3: Pointer to save old IP
43 @ SP+0: New address space
44 SwitchTask:
45         push {r4-r12,lr}
46
47         @ Save IP       
48         ldr r4, =.return
49         str r4, [r3]
50         @ Save SP
51         str sp, [r1]
52
53         @ Only update TTBR0 if the task has an explicit address space
54         ldr r1, [sp,#4*10]
55         tst r1, r1
56         mcrne p15, 0, r1, c2, c0, 0     @ Set TTBR0 to r0
57
58         @ Restore SP
59         mov sp, r0
60
61         bx r2
62
63 .return:
64         pop {r4-r12,pc}
65
66 .extern MM_Clone
67 .extern MM_DumpTables
68 .globl Proc_CloneInt
69 Proc_CloneInt:
70         @ R0: SP Destination
71         @ R1: Mem Destination
72         push {r4-r12,lr}
73         mov r4, r1      @ Save mem destination
74         str sp, [r0]    @ Save SP to SP dest
75
76         bl MM_Clone
77         str r0, [r4]    @ Save clone return to Mem Dest
78
79         ldr r0, =Proc_CloneInt_new
80         pop {r4-r12,pc}
81 Proc_CloneInt_new:
82 @       cps #18
83                 
84         mov r0, #0
85         mvn r1, #0
86         bl MM_DumpTables
87
88         ldr r0, =csProc_CloneInt_NewTaskMessage
89         bl Log
90         
91 @       cps #19
92         mov r0, #0
93         pop {r4-r12,pc}
94
95
96 .section .rodata
97 csProc_CloneInt_NewTaskMessage:
98         .asciz "New task"

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