source: trunk/hal/tsar_mips32/core/hal_switch.S @ 407

Last change on this file since 407 was 407, checked in by alain, 6 years ago

First implementation of fork/exec.

File size: 7.6 KB
RevLine 
[367]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
[406]24    .section   .switch , "ax" , @progbits
[367]25
[407]26    .global  hal_do_cpu_switch
27    .global  hal_do_cpu_save
[367]28
[406]29    .set     noat
30    .set     noreorder
[367]31
[407]32#---------------------------------------------------------------------------------
33# The hal_do_cpu_switch() function makes the following assumptions:
34# - register $4 contains a pointer on the old thread context.
35# - register $5 contains a pointer on the new thread context.
36#---------------------------------------------------------------------------------
37hal_do_cpu_switch:
[367]38
39    move    $26,   $4                  /* $26 <= ctx_old */
40
41    mfc0    $27,   $14             
42    sw      $27,   0*4($26)            /* save c0_epc to slot 0 */
43 
44    sw      $1,    1*4($26)         
45    sw      $2,    2*4($26)         
46    sw      $3,    3*4($26)         
47    sw      $4,    4*4($26)         
48    sw      $5,    5*4($26)         
49    sw      $6,    6*4($26)         
50    sw      $7,    7*4($26)         
51
52    sw      $8,    8*4($26)         
53    sw      $9,    9*4($26)         
54    sw      $10,  10*4($26)         
55    sw      $11,  11*4($26)         
56    sw      $12,  12*4($26)         
57    sw      $13,  13*4($26)         
58    sw      $14,  14*4($26)         
59    sw      $15,  15*4($26)         
60
61    sw      $16,  16*4($26)         
62    sw      $17,  17*4($26)         
63    sw      $18,  18*4($26)         
64    sw      $19,  19*4($26)         
65    sw      $20,  20*4($26)         
66    sw      $21,  21*4($26)         
67    sw      $22,  22*4($26)         
68    sw      $23,  23*4($26)         
69
70    sw      $24,  24*4($26)         
71    sw      $25,  25*4($26)         
72
73    mfhi    $27                     
74    sw      $27,  26*4($26)            /* save hi to slot 26 */
75    mflo    $27                     
76    sw      $27,  27*4($26)            /* save lo to slot 27 */
77
78    sw      $28,  28*4($26)         
79    sw      $29,  29*4($26)         
80    sw      $30,  30*4($26)         
81    sw      $31,  31*4($26)         
82
[406]83    mfc0    $27,  $12               
84        sw      $27,  34*4($26)           /* save c0_sr to slot 34 */
85    mfc0    $27,  $4, 2             
86        sw      $27,  35*4($26)           /* save c0_th to slot 35 */
87
[367]88        mfc2    $27,  $0               
89        sw      $27,  32*4($26)           /* save c2_ptpr to slot 32 */
90        mfc2    $27,  $1               
91        sw      $27,  33*4($26)           /* save c2_mode to slot 33 */
92
93    sync                           
94
95    move    $26,   $5                  /* $26 <= ctx_new */
96
97    lw      $27,   0*4($26)         
98    mtc0    $27,   $14                 /* restore C0_epc from slot 0 */
99
100    lw      $1,    1*4($26)         
101    lw      $2,    2*4($26)         
102    lw      $3,    3*4($26)         
103    lw      $4,    4*4($26)         
104    lw      $5,    5*4($26)         
105    lw      $6,    6*4($26)         
106    lw      $7,    7*4($26)         
107
108    lw      $8,    8*4($26)         
109    lw      $9,    9*4($26)         
110    lw      $10,  10*4($26)         
111    lw      $11,  11*4($26)         
112    lw      $12,  12*4($26)         
113    lw      $13,  13*4($26)         
114    lw      $14,  14*4($26)         
115    lw      $15,  15*4($26)         
116
117        lw      $16,  16*4($26)         
118        lw      $17,  17*4($26)         
119    lw      $18,  18*4($26)         
120    lw      $19,  19*4($26)         
121    lw      $20,  20*4($26)         
122    lw      $21,  21*4($26)         
123    lw      $22,  22*4($26)         
124    lw      $23,  23*4($26)         
125
126    lw      $24,  24*4($26)         
127    lw      $25,  25*4($26)         
128
129    lw      $27,  26*4($26)         
130    mthi    $27                        /* restore hi from slot 26 */
131    lw      $27,  27*4($26)         
[407]132    mtlo    $27                        /* restore lo from slot 27 */
[367]133
134        lw      $28,  28*4($26)         
135        lw      $29,  29*4($26)         
136        lw      $30,  30*4($26)         
[407]137        lw      $31,  31*4($26)            /* restore ra from slot 31 */
[367]138
[407]139        lw      $27,  32*4($26)
[367]140        mtc2    $27,  $0                   /* restore c2_ptpr from slot 32 */
[406]141
[407]142        lw      $27,  35*4($26)     
[406]143    mtc0        $27,  $4, 2                /* restore c0_th from slot 35 */
144
[407]145        lw      $27,  33*4($26)
146        lw      $26,  34*4($26)
[406]147
[367]148        mtc2    $27,  $1                   /* restore c2_mode from slot 33 */
[406]149    mtc0        $26,  $12                  /* restore c0_sr from slot 34 */
[367]150
151    jr      $31                        /* return to caller */
152    nop
153
[407]154#---------------------------------------------------------------------------------
155# The hal_do_cpu_save()function makes the following assumptions:
156# - register $4 contains a pointer on the target thread context.
157# - register $5 contains the target thread descriptor pointer.
158# - register $6 contains the offset to add to stack pointer.
159#---------------------------------------------------------------------------------
160hal_do_cpu_save:
161
162    move    $26,  $4                  /* $26 <= context */
163
164    move    $27,  $5
165        sw      $27,  35*4($26)           /* save child thread to slot 35 */
166
167    add     $27,  $6,  $29
168    sw      $27,  29*4($26)           /* save (sp_29 + offset) to slot 29 */
169
170    mfc0    $27,  $12               
171        sw      $27,  34*4($26)           /* save c0_sr to slot 34 */
172
173        mfc2    $27,  $0               
174        sw      $27,  32*4($26)           /* save c2_ptpr to slot 32 */
175
176        mfc2    $27,  $1               
177        sw      $27,  33*4($26)           /* save c2_mode to slot 33 */
178
179    mfc0    $27,   $14             
180    sw      $27,   0*4($26)           /* save c0_epc to slot 0 */
181 
182    sw      $1,    1*4($26)         
183    sw      $2,    2*4($26)         
184    sw      $3,    3*4($26)         
185    sw      $4,    4*4($26)         
186    sw      $5,    5*4($26)         
187    sw      $6,    6*4($26)         
188    sw      $7,    7*4($26)         
189
190    sw      $8,    8*4($26)         
191    sw      $9,    9*4($26)         
192    sw      $10,  10*4($26)         
193    sw      $11,  11*4($26)         
194    sw      $12,  12*4($26)         
195    sw      $13,  13*4($26)         
196    sw      $14,  14*4($26)         
197    sw      $15,  15*4($26)         
198
199    sw      $16,  16*4($26)         
200    sw      $17,  17*4($26)         
201    sw      $18,  18*4($26)         
202    sw      $19,  19*4($26)         
203    sw      $20,  20*4($26)         
204    sw      $21,  21*4($26)         
205    sw      $22,  22*4($26)         
206    sw      $23,  23*4($26)         
207
208    sw      $24,  24*4($26)         
209    sw      $25,  25*4($26)         
210
211    mfhi    $27                     
212    sw      $27,  26*4($26)           /* save hi to slot 26 */
213
214    mflo    $27                     
215    sw      $27,  27*4($26)           /* save lo to slot 27 */
216
217    sw      $28,  28*4($26)           /* save gp to slot 28 */
218
219    sw      $30,  30*4($26)           /* save s8 to slot 30 */
220    sw      $31,  31*4($26)           /* save ra to slot 31 */
221
222    sync
223
224    jr      $31                       /* return to caller */
225    nop
226
[367]227        .set reorder                   
228    .set at                         
229
Note: See TracBrowser for help on using the repository browser.