1 | /* |
---|
2 | * hal_witch.S - CPU context switch function for TSAR-MIPS32 |
---|
3 | * |
---|
4 | * Author Alain Greiner (2016) |
---|
5 | * |
---|
6 | * Copyright (c) UPMC Sorbonne Universites |
---|
7 | * |
---|
8 | * This file is part of ALMOS-MKH. |
---|
9 | * |
---|
10 | * ALMOS-MKH.is free software; you can redistribute it and/or modify it |
---|
11 | * under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; version 2.0 of the License. |
---|
13 | * |
---|
14 | * ALMOS-MKH.is distributed in the hope that it will be useful, but |
---|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | * General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with ALMOS-MKH.; if not, write to the Free Software Foundation, |
---|
21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | */ |
---|
23 | |
---|
24 | #--------------------------------------------------------------------------------- |
---|
25 | # This code makes the following assumptions: |
---|
26 | # - register $4 contains a pointer on the old thread context. |
---|
27 | # - register $5 contains a pointer on the new thread context. |
---|
28 | # When the switch is completed, it jumps to address contained in register $31 |
---|
29 | # of the new context. |
---|
30 | #--------------------------------------------------------------------------------- |
---|
31 | |
---|
32 | .section .text , "ax" , @progbits |
---|
33 | |
---|
34 | .ent hal_do_switch |
---|
35 | .globl hal_do_switch |
---|
36 | |
---|
37 | .set noat |
---|
38 | .set noreorder |
---|
39 | |
---|
40 | hal_do_switch: |
---|
41 | |
---|
42 | move $26, $4 /* $26 <= ctx_old */ |
---|
43 | |
---|
44 | mfc0 $27, $14 |
---|
45 | sw $27, 0*4($26) /* save c0_epc to slot 0 */ |
---|
46 | |
---|
47 | sw $1, 1*4($26) |
---|
48 | sw $2, 2*4($26) |
---|
49 | sw $3, 3*4($26) |
---|
50 | sw $4, 4*4($26) |
---|
51 | sw $5, 5*4($26) |
---|
52 | sw $6, 6*4($26) |
---|
53 | sw $7, 7*4($26) |
---|
54 | |
---|
55 | sw $8, 8*4($26) |
---|
56 | sw $9, 9*4($26) |
---|
57 | sw $10, 10*4($26) |
---|
58 | sw $11, 11*4($26) |
---|
59 | sw $12, 12*4($26) |
---|
60 | sw $13, 13*4($26) |
---|
61 | sw $14, 14*4($26) |
---|
62 | sw $15, 15*4($26) |
---|
63 | |
---|
64 | sw $16, 16*4($26) |
---|
65 | sw $17, 17*4($26) |
---|
66 | sw $18, 18*4($26) |
---|
67 | sw $19, 19*4($26) |
---|
68 | sw $20, 20*4($26) |
---|
69 | sw $21, 21*4($26) |
---|
70 | sw $22, 22*4($26) |
---|
71 | sw $23, 23*4($26) |
---|
72 | |
---|
73 | sw $24, 24*4($26) |
---|
74 | sw $25, 25*4($26) |
---|
75 | |
---|
76 | mfhi $27 |
---|
77 | sw $27, 26*4($26) /* save hi to slot 26 */ |
---|
78 | mflo $27 |
---|
79 | sw $27, 27*4($26) /* save lo to slot 27 */ |
---|
80 | |
---|
81 | sw $28, 28*4($26) |
---|
82 | sw $29, 29*4($26) |
---|
83 | sw $30, 30*4($26) |
---|
84 | sw $31, 31*4($26) |
---|
85 | |
---|
86 | mfc2 $27, $0 |
---|
87 | sw $27, 32*4($26) /* save c2_ptpr to slot 32 */ |
---|
88 | mfc2 $27, $1 |
---|
89 | sw $27, 33*4($26) /* save c2_mode to slot 33 */ |
---|
90 | |
---|
91 | mfc0 $27, $12 |
---|
92 | sw $27, 34*4($26) /* save c0_sr to slot 34 */ |
---|
93 | mfc0 $27, $4, 2 |
---|
94 | sw $27, 35*4($26) /* save c0_th to slot 35 */ |
---|
95 | |
---|
96 | sync |
---|
97 | |
---|
98 | move $26, $5 /* $26 <= ctx_new */ |
---|
99 | |
---|
100 | lw $27, 0*4($26) |
---|
101 | mtc0 $27, $14 /* restore C0_epc from slot 0 */ |
---|
102 | |
---|
103 | lw $1, 1*4($26) |
---|
104 | lw $2, 2*4($26) |
---|
105 | lw $3, 3*4($26) |
---|
106 | lw $4, 4*4($26) |
---|
107 | lw $5, 5*4($26) |
---|
108 | lw $6, 6*4($26) |
---|
109 | lw $7, 7*4($26) |
---|
110 | |
---|
111 | lw $8, 8*4($26) |
---|
112 | lw $9, 9*4($26) |
---|
113 | lw $10, 10*4($26) |
---|
114 | lw $11, 11*4($26) |
---|
115 | lw $12, 12*4($26) |
---|
116 | lw $13, 13*4($26) |
---|
117 | lw $14, 14*4($26) |
---|
118 | lw $15, 15*4($26) |
---|
119 | |
---|
120 | lw $16, 16*4($26) |
---|
121 | lw $17, 17*4($26) |
---|
122 | lw $18, 18*4($26) |
---|
123 | lw $19, 19*4($26) |
---|
124 | lw $20, 20*4($26) |
---|
125 | lw $21, 21*4($26) |
---|
126 | lw $22, 22*4($26) |
---|
127 | lw $23, 23*4($26) |
---|
128 | |
---|
129 | lw $24, 24*4($26) |
---|
130 | lw $25, 25*4($26) |
---|
131 | |
---|
132 | lw $27, 26*4($26) |
---|
133 | mthi $27 /* restore hi from slot 26 */ |
---|
134 | lw $27, 27*4($26) |
---|
135 | mtlo $27 /* restote lo from slot 27 */ |
---|
136 | |
---|
137 | lw $28, 28*4($26) |
---|
138 | lw $29, 29*4($26) |
---|
139 | lw $30, 30*4($26) |
---|
140 | lw $31, 31*4($26) |
---|
141 | |
---|
142 | lw $27, 32*4($26) |
---|
143 | mtc2 $27, $0 /* restore c2_ptpr from slot 32 */ |
---|
144 | lw $27, 33*4($26) |
---|
145 | mtc2 $27, $1 /* restore c2_mode from slot 33 */ |
---|
146 | |
---|
147 | lw $27, 34*4($26) |
---|
148 | mtc0 $27, $12 /* restore c0_sr from slot 34 */ |
---|
149 | lw $27, 35*4($26) |
---|
150 | mtc0 $27, $4, 2 /* restore co_th from slot 35 */ |
---|
151 | |
---|
152 | jr $31 /* return to caller */ |
---|
153 | nop |
---|
154 | |
---|
155 | .set reorder |
---|
156 | .set at |
---|
157 | |
---|
158 | .end hal_do_switch |
---|
159 | |
---|