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