| 1 | #
|
|---|
| 2 | # Copyright (c) 2003-2004 Jakub Jermar
|
|---|
| 3 | # All rights reserved.
|
|---|
| 4 | #
|
|---|
| 5 | # Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | # modification, are permitted provided that the following conditions
|
|---|
| 7 | # are met:
|
|---|
| 8 | #
|
|---|
| 9 | # - Redistributions of source code must retain the above copyright
|
|---|
| 10 | # notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | # - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | # notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | # documentation and/or other materials provided with the distribution.
|
|---|
| 14 | # - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | # derived from this software without specific prior written permission.
|
|---|
| 16 | #
|
|---|
| 17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | #
|
|---|
| 28 |
|
|---|
| 29 | .text
|
|---|
| 30 |
|
|---|
| 31 | .set noat
|
|---|
| 32 | .set noreorder
|
|---|
| 33 |
|
|---|
| 34 | #include <libarch/fibril_context.h>
|
|---|
| 35 |
|
|---|
| 36 | .global context_save
|
|---|
| 37 | .global context_restore
|
|---|
| 38 |
|
|---|
| 39 | context_save:
|
|---|
| 40 | sw $s0, CONTEXT_OFFSET_S0($a0)
|
|---|
| 41 | sw $s1, CONTEXT_OFFSET_S1($a0)
|
|---|
| 42 | sw $s2, CONTEXT_OFFSET_S2($a0)
|
|---|
| 43 | sw $s3, CONTEXT_OFFSET_S3($a0)
|
|---|
| 44 | sw $s4, CONTEXT_OFFSET_S4($a0)
|
|---|
| 45 | sw $s5, CONTEXT_OFFSET_S5($a0)
|
|---|
| 46 | sw $s6, CONTEXT_OFFSET_S6($a0)
|
|---|
| 47 | sw $s7, CONTEXT_OFFSET_S7($a0)
|
|---|
| 48 | sw $s8, CONTEXT_OFFSET_S8($a0)
|
|---|
| 49 | sw $gp, CONTEXT_OFFSET_GP($a0)
|
|---|
| 50 |
|
|---|
| 51 | sw $k1, CONTEXT_OFFSET_TLS($a0)
|
|---|
| 52 |
|
|---|
| 53 | #ifdef CONFIG_FPU
|
|---|
| 54 | mfc1 $t0, $20
|
|---|
| 55 | sw $t0, CONTEXT_OFFSET_F20($a0)
|
|---|
| 56 |
|
|---|
| 57 | mfc1 $t0, $21
|
|---|
| 58 | sw $t0, CONTEXT_OFFSET_F21($a0)
|
|---|
| 59 |
|
|---|
| 60 | mfc1 $t0, $22
|
|---|
| 61 | sw $t0, CONTEXT_OFFSET_F22($a0)
|
|---|
| 62 |
|
|---|
| 63 | mfc1 $t0, $23
|
|---|
| 64 | sw $t0, CONTEXT_OFFSET_F23($a0)
|
|---|
| 65 |
|
|---|
| 66 | mfc1 $t0, $24
|
|---|
| 67 | sw $t0, CONTEXT_OFFSET_F24($a0)
|
|---|
| 68 |
|
|---|
| 69 | mfc1 $t0, $25
|
|---|
| 70 | sw $t0, CONTEXT_OFFSET_F25($a0)
|
|---|
| 71 |
|
|---|
| 72 | mfc1 $t0, $26
|
|---|
| 73 | sw $t0, CONTEXT_OFFSET_F26($a0)
|
|---|
| 74 |
|
|---|
| 75 | mfc1 $t0, $27
|
|---|
| 76 | sw $t0, CONTEXT_OFFSET_F27($a0)
|
|---|
| 77 |
|
|---|
| 78 | mfc1 $t0, $28
|
|---|
| 79 | sw $t0, CONTEXT_OFFSET_F28($a0)
|
|---|
| 80 |
|
|---|
| 81 | mfc1 $t0, $29
|
|---|
| 82 | sw $t0, CONTEXT_OFFSET_F29($a0)
|
|---|
| 83 |
|
|---|
| 84 | mfc1 $t0, $30
|
|---|
| 85 | sw $t0, CONTEXT_OFFSET_F30($a0)
|
|---|
| 86 | #endif /* CONFIG_FPU */
|
|---|
| 87 |
|
|---|
| 88 | sw $ra, CONTEXT_OFFSET_PC($a0)
|
|---|
| 89 | sw $sp, CONTEXT_OFFSET_SP($a0)
|
|---|
| 90 |
|
|---|
| 91 | # context_save returns 1
|
|---|
| 92 | j $ra
|
|---|
| 93 | li $v0, 1
|
|---|
| 94 |
|
|---|
| 95 | context_restore:
|
|---|
| 96 | lw $s0, CONTEXT_OFFSET_S0($a0)
|
|---|
| 97 | lw $s1, CONTEXT_OFFSET_S1($a0)
|
|---|
| 98 | lw $s2, CONTEXT_OFFSET_S2($a0)
|
|---|
| 99 | lw $s3, CONTEXT_OFFSET_S3($a0)
|
|---|
| 100 | lw $s4, CONTEXT_OFFSET_S4($a0)
|
|---|
| 101 | lw $s5, CONTEXT_OFFSET_S5($a0)
|
|---|
| 102 | lw $s6, CONTEXT_OFFSET_S6($a0)
|
|---|
| 103 | lw $s7, CONTEXT_OFFSET_S7($a0)
|
|---|
| 104 | lw $s8, CONTEXT_OFFSET_S8($a0)
|
|---|
| 105 | lw $gp, CONTEXT_OFFSET_GP($a0)
|
|---|
| 106 | lw $k1, CONTEXT_OFFSET_TLS($a0)
|
|---|
| 107 |
|
|---|
| 108 | #ifdef CONFIG_FPU
|
|---|
| 109 | lw $t0, CONTEXT_OFFSET_F20($a0)
|
|---|
| 110 | mtc1 $t0, $20
|
|---|
| 111 |
|
|---|
| 112 | lw $t0, CONTEXT_OFFSET_F21($a0)
|
|---|
| 113 | mtc1 $t0, $21
|
|---|
| 114 |
|
|---|
| 115 | lw $t0, CONTEXT_OFFSET_F22($a0)
|
|---|
| 116 | mtc1 $t0, $22
|
|---|
| 117 |
|
|---|
| 118 | lw $t0, CONTEXT_OFFSET_F23($a0)
|
|---|
| 119 | mtc1 $t0, $23
|
|---|
| 120 |
|
|---|
| 121 | lw $t0, CONTEXT_OFFSET_F24($a0)
|
|---|
| 122 | mtc1 $t0, $24
|
|---|
| 123 |
|
|---|
| 124 | lw $t0, CONTEXT_OFFSET_F25($a0)
|
|---|
| 125 | mtc1 $t0, $25
|
|---|
| 126 |
|
|---|
| 127 | lw $t0, CONTEXT_OFFSET_F26($a0)
|
|---|
| 128 | mtc1 $t0, $26
|
|---|
| 129 |
|
|---|
| 130 | lw $t0, CONTEXT_OFFSET_F27($a0)
|
|---|
| 131 | mtc1 $t0, $27
|
|---|
| 132 |
|
|---|
| 133 | lw $t0, CONTEXT_OFFSET_F28($a0)
|
|---|
| 134 | mtc1 $t0, $28
|
|---|
| 135 |
|
|---|
| 136 | lw $t0, CONTEXT_OFFSET_F29($a0)
|
|---|
| 137 | mtc1 $t0, $29
|
|---|
| 138 |
|
|---|
| 139 | lw $t0, CONTEXT_OFFSET_F30($a0)
|
|---|
| 140 | mtc1 $t0, $30
|
|---|
| 141 | #endif /* CONFIG_FPU */
|
|---|
| 142 |
|
|---|
| 143 | lw $ra, CONTEXT_OFFSET_PC($a0)
|
|---|
| 144 | lw $sp, CONTEXT_OFFSET_SP($a0)
|
|---|
| 145 |
|
|---|
| 146 | # Just for the jump into first function,
|
|---|
| 147 | # but one instruction should not bother us
|
|---|
| 148 | move $t9, $ra
|
|---|
| 149 |
|
|---|
| 150 | # context_restore returns 0
|
|---|
| 151 | j $ra
|
|---|
| 152 | xor $v0, $v0
|
|---|