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