1 | /****************************************************************************** |
---|
2 | * This function receives two arguments that are the current task context |
---|
3 | * (virtual) addresses and the next task context (virtual) address. |
---|
4 | ******************************************************************************/ |
---|
5 | |
---|
6 | .globl _task_switch |
---|
7 | .func _task_switch |
---|
8 | .type _task_switch, %function |
---|
9 | |
---|
10 | _task_switch: |
---|
11 | |
---|
12 | /* enter critical section */ |
---|
13 | li $2, 0xFFFFFFFE |
---|
14 | mfc0 $3, $12 |
---|
15 | and $3, $3, $2 |
---|
16 | mtc0 $3, $12 |
---|
17 | |
---|
18 | /* save _current task context */ |
---|
19 | add $27, $4, $0 /* $27 <= &context[curr_task_id] */ |
---|
20 | |
---|
21 | .set noat |
---|
22 | sw $1, 1*4($27) /* ctx[1] <= $1 */ |
---|
23 | .set at |
---|
24 | sw $2, 2*4($27) /* ctx[2] <= $2 */ |
---|
25 | sw $3, 3*4($27) /* ctx[3] <= $3 */ |
---|
26 | sw $4, 4*4($27) /* ctx[4] <= $4 */ |
---|
27 | sw $5, 5*4($27) /* ctx[5] <= $5 */ |
---|
28 | sw $6, 6*4($27) /* ctx[6] <= $6 */ |
---|
29 | sw $7, 7*4($27) /* ctx[7] <= $7 */ |
---|
30 | sw $8, 8*4($27) /* ctx[8] <= $8 */ |
---|
31 | sw $9, 9*4($27) /* ctx[9] <= $9 */ |
---|
32 | sw $10, 10*4($27) /* ctx[10] <= $10 */ |
---|
33 | sw $11, 11*4($27) /* ctx[11] <= $11 */ |
---|
34 | sw $12, 12*4($27) /* ctx[12] <= $12 */ |
---|
35 | sw $13, 13*4($27) /* ctx[13] <= $13 */ |
---|
36 | sw $14, 14*4($27) /* ctx[14] <= $14 */ |
---|
37 | sw $15, 15*4($27) /* ctx[15] <= $15 */ |
---|
38 | sw $16, 16*4($27) /* ctx[16] <= $16 */ |
---|
39 | sw $17, 17*4($27) /* ctx[17] <= $17 */ |
---|
40 | sw $18, 18*4($27) /* ctx[18] <= $18 */ |
---|
41 | sw $19, 19*4($27) /* ctx[19] <= $19 */ |
---|
42 | sw $20, 20*4($27) /* ctx[20] <= $20 */ |
---|
43 | sw $21, 21*4($27) /* ctx[21] <= $21 */ |
---|
44 | sw $22, 22*4($27) /* ctx[22] <= $22 */ |
---|
45 | sw $23, 23*4($27) /* ctx[23] <= $23 */ |
---|
46 | sw $24, 24*4($27) /* ctx[24] <= $24 */ |
---|
47 | sw $25, 25*4($27) /* ctx[25] <= $25 */ |
---|
48 | mflo $26 |
---|
49 | sw $26, 26*4($27) /* ctx[26] <= LO */ |
---|
50 | mfhi $26 |
---|
51 | sw $26, 27*4($27) /* ctx[27] <= H1 */ |
---|
52 | sw $28, 28*4($27) /* ctx[28] <= $28 */ |
---|
53 | sw $29, 29*4($27) /* ctx[29] <= $29 */ |
---|
54 | sw $30, 30*4($27) /* ctx[30] <= $30 */ |
---|
55 | sw $31, 31*4($27) /* ctx[31] <= $31 */ |
---|
56 | mfc0 $26, $14 |
---|
57 | sw $26, 32*4($27) /* ctx[32] <= EPC */ |
---|
58 | mfc0 $26, $13 |
---|
59 | sw $26, 33*4($27) /* ctx[33] <= CR */ |
---|
60 | mfc0 $26, $12 |
---|
61 | sw $26, 34*4($27) /* ctx[34] <= SR */ |
---|
62 | mfc0 $26, $8 |
---|
63 | sw $26, 35*4($27) /* ctx[34] <= BVAR */ |
---|
64 | mfc2 $26, $0 |
---|
65 | sw $26, 39*4($27) /* ctx[35] <= PTPR */ |
---|
66 | |
---|
67 | /* restore next task context */ |
---|
68 | add $27, $5, $0 /* $27<= &context[next_task_id] */ |
---|
69 | |
---|
70 | .set noat |
---|
71 | lw $1, 1*4($27) /* restore $1 */ |
---|
72 | .set at |
---|
73 | lw $2, 2*4($27) /* restore $2 */ |
---|
74 | lw $3, 3*4($27) /* restore $3 */ |
---|
75 | lw $4, 4*4($27) /* restore $4 */ |
---|
76 | lw $5, 5*4($27) /* restore $5 */ |
---|
77 | lw $6, 6*4($27) /* restore $6 */ |
---|
78 | lw $7, 7*4($27) /* restore $7 */ |
---|
79 | lw $8, 8*4($27) /* restore $8 */ |
---|
80 | lw $9, 9*4($27) /* restore $9 */ |
---|
81 | lw $10, 10*4($27) /* restore $10 */ |
---|
82 | lw $11, 11*4($27) /* restore $11 */ |
---|
83 | lw $12, 12*4($27) /* restore $12 */ |
---|
84 | lw $13, 13*4($27) /* restore $13 */ |
---|
85 | lw $14, 14*4($27) /* restore $14 */ |
---|
86 | lw $15, 15*4($27) /* restore $15 */ |
---|
87 | lw $16, 16*4($27) /* restore $16 */ |
---|
88 | lw $17, 17*4($27) /* restore $17 */ |
---|
89 | lw $18, 18*4($27) /* restore $18 */ |
---|
90 | lw $19, 19*4($27) /* restore $19 */ |
---|
91 | lw $20, 20*4($27) /* restore $20 */ |
---|
92 | lw $21, 21*4($27) /* restore $21 */ |
---|
93 | lw $22, 22*4($27) /* restore $22 */ |
---|
94 | lw $23, 23*4($27) /* restore $23 */ |
---|
95 | lw $24, 24*4($27) /* restore $24 */ |
---|
96 | lw $25, 25*4($27) /* restore $25 */ |
---|
97 | lw $26, 26*4($27) |
---|
98 | mtlo $26 /* restore LO */ |
---|
99 | lw $26, 27*4($27) |
---|
100 | mthi $26 /* restore HI */ |
---|
101 | lw $28, 28*4($27) /* restore $28 */ |
---|
102 | lw $29, 29*4($27) /* restore $29 */ |
---|
103 | lw $30, 30*4($27) /* restore $30 */ |
---|
104 | lw $31, 31*4($27) /* restore $31 */ |
---|
105 | lw $26, 32*4($27) |
---|
106 | mtc0 $26, $14 /* restore EPC */ |
---|
107 | lw $26, 33*4($27) |
---|
108 | mtc0 $26, $13 /* restore CR */ |
---|
109 | lw $26, 34*4($27) |
---|
110 | mtc0 $26, $12 /* restore SR */ |
---|
111 | lw $26, 35*4($27) |
---|
112 | mtc0 $26, $8 /* restore BVAR */ |
---|
113 | lw $26, 39*4($27) |
---|
114 | mtc2 $26, $0 /* restore PTPR */ |
---|
115 | |
---|
116 | /* exit critical section */ |
---|
117 | li $2, 0x00000001 |
---|
118 | mfc0 $3, $12 |
---|
119 | or $3, $3, $2 |
---|
120 | mtc0 $3, $12 |
---|
121 | |
---|
122 | /* returns to caller */ |
---|
123 | jr $31 |
---|
124 | |
---|
125 | .endfunc |
---|
126 | .size _task_switch, .-_task_switch |
---|
127 | |
---|