source: soft/giet_vm/giet_kernel/switch.s @ 818

Last change on this file since 818 was 818, checked in by cfuguet, 8 years ago

Optimization: When doing a context switch between threads of the
same vspace and cluster, do not rewrite the PTPR register.

  • Property svn:executable set to *
File size: 4.9 KB
Line 
1/******************************************************************************
2* This function receives two arguments that are the current thread context
3* (virtual) addresses and the next thread context (virtual) address.
4*
5* This function should be called in a critical section
6*
7* TODO (AG) Il semble possible de limiter le nombre de registres à sauver:
8* - s0 à s8 ($16 Ã  $23 + $30)
9* - sp ($29)
10* - ra ($31)
11* - hi et lo
12* - sr
13* - epc
14* - ptpr
15******************************************************************************/
16
17    .globl  _thread_switch
18    .func   _thread_switch
19    .type   _thread_switch, %function
20
21_thread_switch:
22
23    /* first step : save current thread context */
24    add     $27,    $4,     $0  /* $27 <= &context[current] */
25
26    .set noat
27    sw      $1,     1*4($27)    /* ctx[1] <= $1 */
28    .set at
29    sw      $2,     2*4($27)    /* ctx[2] <= $2 */
30    sw      $3,     3*4($27)    /* ctx[3] <= $3 */
31    sw      $4,     4*4($27)    /* ctx[4] <= $4 */
32    sw      $5,     5*4($27)    /* ctx[5] <= $5 */
33    sw      $6,     6*4($27)    /* ctx[6] <= $6 */
34    sw      $7,     7*4($27)    /* ctx[7] <= $7 */
35    sw      $8,     8*4($27)    /* ctx[8] <= $8 */
36    sw      $9,     9*4($27)    /* ctx[9] <= $9 */
37    sw      $10,    10*4($27)   /* ctx[10] <= $10 */
38    sw      $11,    11*4($27)   /* ctx[11] <= $11 */
39    sw      $12,    12*4($27)   /* ctx[12] <= $12 */
40    sw      $13,    13*4($27)   /* ctx[13] <= $13 */
41    sw      $14,    14*4($27)   /* ctx[14] <= $14 */
42    sw      $15,    15*4($27)   /* ctx[15] <= $15 */
43    sw      $16,    16*4($27)   /* ctx[16] <= $16 */
44    sw      $17,    17*4($27)   /* ctx[17] <= $17 */
45    sw      $18,    18*4($27)   /* ctx[18] <= $18 */
46    sw      $19,    19*4($27)   /* ctx[19] <= $19 */
47    sw      $20,    20*4($27)   /* ctx[20] <= $20 */
48    sw      $21,    21*4($27)   /* ctx[21] <= $21 */
49    sw      $22,    22*4($27)   /* ctx[22] <= $22 */
50    sw      $23,    23*4($27)   /* ctx[23] <= $23 */
51    sw      $24,    24*4($27)   /* ctx[24] <= $24 */
52    sw      $25,    25*4($27)   /* ctx[25] <= $25 */
53    mflo    $26
54    sw      $26,    26*4($27)   /* ctx[26] <= LO  */
55    mfhi    $26
56    sw      $26,    27*4($27)   /* ctx[27] <= H1  */
57    sw      $28,    28*4($27)   /* ctx[28] <= $28 */
58    sw      $29,    29*4($27)   /* ctx[29] <= $29 */
59    sw      $30,    30*4($27)   /* ctx[30] <= $30 */
60    sw      $31,    31*4($27)   /* ctx[31] <= $31 */
61    mfc0    $26,    $14
62    sw      $26,    32*4($27)   /* ctx[32] <= EPC */
63    mfc0    $26,    $13
64    sw      $26,    33*4($27)   /* ctx[33] <= CR  */
65    mfc0    $26,    $12
66    sw      $26,    34*4($27)   /* ctx[34] <= SR  */
67    mfc0    $26,    $8
68    sw      $26,    35*4($27)   /* ctx[34] <= BVAR */
69    mfc2    $26,    $0
70    sw      $26,    39*4($27)   /* ctx[35] <= PTPR */
71
72    /* second step : restore next thread context */
73    add     $27,    $5,     $0  /* $27<= &context[next] */
74
75    .set noat
76    lw      $1,     1*4($27)    /* restore $1 */
77    .set at
78    lw      $2,     2*4($27)    /* restore $2 */
79    lw      $3,     3*4($27)    /* restore $3 */
80    lw      $4,     4*4($27)    /* restore $4 */
81    lw      $5,     5*4($27)    /* restore $5 */
82    lw      $6,     6*4($27)    /* restore $6 */
83    lw      $7,     7*4($27)    /* restore $7 */
84    lw      $8,     8*4($27)    /* restore $8 */
85    lw      $9,     9*4($27)    /* restore $9 */
86    lw      $10,    10*4($27)   /* restore $10 */
87    lw      $11,    11*4($27)   /* restore $11 */
88    lw      $12,    12*4($27)   /* restore $12 */
89    lw      $13,    13*4($27)   /* restore $13 */
90    lw      $14,    14*4($27)   /* restore $14 */
91    lw      $15,    15*4($27)   /* restore $15 */
92    lw      $16,    16*4($27)   /* restore $16 */
93    lw      $17,    17*4($27)   /* restore $17 */
94    lw      $18,    18*4($27)   /* restore $18 */
95    lw      $19,    19*4($27)   /* restore $19 */
96    lw      $20,    20*4($27)   /* restore $20 */
97    lw      $21,    21*4($27)   /* restore $21 */
98    lw      $22,    22*4($27)   /* restore $22 */
99    lw      $23,    23*4($27)   /* restore $23 */
100    lw      $24,    24*4($27)   /* restore $24 */
101    lw      $25,    25*4($27)   /* restore $25 */
102    lw      $26,    26*4($27)
103    mtlo    $26                 /* restore LO */
104    lw      $26,    27*4($27)
105    mthi    $26                 /* restore HI */
106    lw      $28,    28*4($27)   /* restore $28 */
107    lw      $29,    29*4($27)   /* restore $29 */
108    lw      $30,    30*4($27)   /* restore $30 */
109    lw      $31,    31*4($27)   /* restore $31 */
110    lw      $26,    32*4($27)
111    mtc0    $26,    $14         /* restore EPC */
112    lw      $26,    33*4($27)
113    mtc0    $26,    $13         /* restore CR */
114    lw      $26,    34*4($27)
115    mtc0    $26,    $12         /* restore SR */
116    lw      $26,    35*4($27)
117    mtc0    $26,    $8          /* restore BVAR */
118
119    /* returns to caller */
120    jr      $31 
121
122    .endfunc
123    .size _thread_switch, .-_thread_switch
124
Note: See TracBrowser for help on using the repository browser.