44ce9eeaca1bc8bcc4e2f0a703a035d3098ccdf5
[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         mov r1, #0
58         mcrne p15, 0, r1, c8, c7, 0     @ Invalidate all (HACK! But it fixes things)
59
60         @ Restore SP
61         mov sp, r0
62
63         bx r2
64
65 .return:
66         pop {r4-r12,pc}
67
68 .extern MM_Clone
69 .extern MM_DumpTables
70 .globl Proc_CloneInt
71 Proc_CloneInt:
72         @ R0: SP Destination
73         @ R1: Mem Destination
74         push {r4-r12,lr}
75         mov r4, r1      @ Save mem destination
76         str sp, [r0]    @ Save SP to SP dest
77
78         bl MM_Clone
79         str r0, [r4]    @ Save clone return to Mem Dest
80
81         ldr r0, =Proc_CloneInt_new
82         pop {r4-r12,pc}
83 Proc_CloneInt_new:
84 @       cps #18
85                 
86 @       mov r0, #0
87 @       mvn r1, #0
88 @       bl MM_DumpTables
89
90 @       ldr r0, =csProc_CloneInt_NewTaskMessage
91 @       bl Log
92         
93 @       cps #19
94         mov r0, #0
95         pop {r4-r12,pc}
96
97
98 .section .rodata
99 csProc_CloneInt_NewTaskMessage:
100         .asciz "New task"

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