Rev 1078 | Rev 1096 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
308 | jermar | 1 | # |
319 | jermar | 2 | # Copyright (C) 2003-2004 Jakub Jermar |
1 | 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 | |||
306 | palkovsky | 29 | #include <arch/asm/regname.h> |
30 | #include <arch/mm/page.h> |
||
31 | #include <arch/asm/boot.h> |
||
317 | palkovsky | 32 | #include <arch/context_offset.h> |
306 | palkovsky | 33 | |
1 | jermar | 34 | .text |
35 | |||
36 | .set noat |
||
37 | .set noreorder |
||
38 | .set nomacro |
||
39 | |||
40 | .global kernel_image_start |
||
41 | .global tlb_refill_entry |
||
42 | .global cache_error_entry |
||
43 | .global exception_entry |
||
313 | palkovsky | 44 | .global userspace_asm |
1 | jermar | 45 | |
313 | palkovsky | 46 | # Save registers to space defined by \r |
47 | # We will change $at on the way |
||
306 | palkovsky | 48 | .macro REGISTERS_STORE r |
49 | sw $at,EOFFSET_AT(\r) |
||
50 | sw $v0,EOFFSET_V0(\r) |
||
51 | sw $v1,EOFFSET_V1(\r) |
||
52 | sw $a0,EOFFSET_A0(\r) |
||
53 | sw $a1,EOFFSET_A1(\r) |
||
54 | sw $a2,EOFFSET_A2(\r) |
||
55 | sw $a3,EOFFSET_A3(\r) |
||
317 | palkovsky | 56 | sw $t0,EOFFSET_T0(\r) |
306 | palkovsky | 57 | sw $t1,EOFFSET_T1(\r) |
58 | sw $t2,EOFFSET_T2(\r) |
||
59 | sw $t3,EOFFSET_T3(\r) |
||
60 | sw $t4,EOFFSET_T4(\r) |
||
61 | sw $t5,EOFFSET_T5(\r) |
||
62 | sw $t6,EOFFSET_T6(\r) |
||
63 | sw $t7,EOFFSET_T7(\r) |
||
64 | sw $t8,EOFFSET_T8(\r) |
||
65 | sw $t9,EOFFSET_T9(\r) |
||
313 | palkovsky | 66 | |
67 | mflo $at |
||
68 | sw $at, EOFFSET_LO(\r) |
||
69 | mfhi $at |
||
70 | sw $at, EOFFSET_HI(\r) |
||
71 | |||
1094 | palkovsky | 72 | #ifdef CONFIG_DEBUG_ALLREGS |
306 | palkovsky | 73 | sw $s0,EOFFSET_S0(\r) |
74 | sw $s1,EOFFSET_S1(\r) |
||
75 | sw $s2,EOFFSET_S2(\r) |
||
76 | sw $s3,EOFFSET_S3(\r) |
||
77 | sw $s4,EOFFSET_S4(\r) |
||
78 | sw $s5,EOFFSET_S5(\r) |
||
79 | sw $s6,EOFFSET_S6(\r) |
||
80 | sw $s7,EOFFSET_S7(\r) |
||
1094 | palkovsky | 81 | sw $s8,EOFFSET_S8(\r) |
82 | #endif |
||
83 | |||
306 | palkovsky | 84 | sw $gp,EOFFSET_GP(\r) |
85 | sw $ra,EOFFSET_RA(\r) |
||
313 | palkovsky | 86 | sw $sp,EOFFSET_SP(\r) |
87 | |||
88 | mfc0 $at, $status |
||
89 | sw $at,EOFFSET_STATUS(\r) |
||
317 | palkovsky | 90 | mfc0 $at, $epc |
91 | sw $at,EOFFSET_EPC(\r) |
||
306 | palkovsky | 92 | .endm |
93 | |||
94 | .macro REGISTERS_LOAD r |
||
95 | lw $v0,EOFFSET_V0(\r) |
||
96 | lw $v1,EOFFSET_V1(\r) |
||
97 | lw $a0,EOFFSET_A0(\r) |
||
98 | lw $a1,EOFFSET_A1(\r) |
||
99 | lw $a2,EOFFSET_A2(\r) |
||
100 | lw $a3,EOFFSET_A3(\r) |
||
317 | palkovsky | 101 | lw $t0,EOFFSET_T0(\r) |
306 | palkovsky | 102 | lw $t1,EOFFSET_T1(\r) |
103 | lw $t2,EOFFSET_T2(\r) |
||
104 | lw $t3,EOFFSET_T3(\r) |
||
105 | lw $t4,EOFFSET_T4(\r) |
||
106 | lw $t5,EOFFSET_T5(\r) |
||
107 | lw $t6,EOFFSET_T6(\r) |
||
108 | lw $t7,EOFFSET_T7(\r) |
||
109 | lw $t8,EOFFSET_T8(\r) |
||
110 | lw $t9,EOFFSET_T9(\r) |
||
1094 | palkovsky | 111 | |
112 | #ifdef CONFIG_DEBUG_ALLREGS |
||
306 | palkovsky | 113 | lw $s0,EOFFSET_S0(\r) |
114 | lw $s1,EOFFSET_S1(\r) |
||
115 | lw $s2,EOFFSET_S2(\r) |
||
116 | lw $s3,EOFFSET_S3(\r) |
||
117 | lw $s4,EOFFSET_S4(\r) |
||
118 | lw $s5,EOFFSET_S5(\r) |
||
119 | lw $s6,EOFFSET_S6(\r) |
||
120 | lw $s7,EOFFSET_S7(\r) |
||
121 | lw $s8,EOFFSET_S8(\r) |
||
1094 | palkovsky | 122 | #endif |
306 | palkovsky | 123 | lw $gp,EOFFSET_GP(\r) |
124 | lw $ra,EOFFSET_RA(\r) |
||
125 | |||
313 | palkovsky | 126 | lw $at,EOFFSET_LO(\r) |
127 | mtlo $at |
||
128 | lw $at,EOFFSET_HI(\r) |
||
129 | mthi $at |
||
130 | |||
131 | lw $at,EOFFSET_STATUS(\r) |
||
132 | mtc0 $at, $status |
||
317 | palkovsky | 133 | lw $at,EOFFSET_EPC(\r) |
134 | mtc0 $at, $epc |
||
313 | palkovsky | 135 | |
136 | lw $at,EOFFSET_AT(\r) |
||
137 | lw $sp,EOFFSET_SP(\r) |
||
306 | palkovsky | 138 | .endm |
139 | |||
313 | palkovsky | 140 | # Move kernel stack pointer address to register K0 |
141 | # - if we are in user mode, load the appropriate stack |
||
142 | # address |
||
143 | .macro KERNEL_STACK_TO_K0 |
||
144 | # If we are in user mode |
||
145 | mfc0 $k0, $status |
||
146 | andi $k0, 0x10 |
||
306 | palkovsky | 147 | |
313 | palkovsky | 148 | beq $k0, $0, 1f |
149 | add $k0, $sp, 0 |
||
150 | |||
151 | # Move $k0 pointer to kernel stack |
||
152 | lui $k0, %hi(supervisor_sp) |
||
320 | palkovsky | 153 | ori $k0, $k0, %lo(supervisor_sp) |
313 | palkovsky | 154 | # Move $k0 (superveisor_sp) |
155 | lw $k0, 0($k0) |
||
156 | 1: |
||
157 | .endm |
||
158 | |||
1 | jermar | 159 | .org 0x0 |
306 | palkovsky | 160 | kernel_image_start: |
161 | /* Load temporary stack */ |
||
313 | palkovsky | 162 | lui $sp, %hi(end_stack) |
320 | palkovsky | 163 | ori $sp, $sp, %lo(end_stack) |
306 | palkovsky | 164 | |
165 | /* Not sure about this, but might be needed for PIC code???? */ |
||
166 | lui $gp, 0x8000 |
||
167 | |||
168 | jal main_bsp |
||
169 | nop |
||
170 | |||
313 | palkovsky | 171 | |
306 | palkovsky | 172 | .space TEMP_STACK_SIZE |
326 | palkovsky | 173 | end_stack: |
174 | |||
175 | tlb_refill_entry: |
||
176 | j tlb_refill_handler |
||
177 | nop |
||
178 | |||
179 | cache_error_entry: |
||
180 | j cache_error_handler |
||
181 | nop |
||
182 | |||
183 | exception_entry: |
||
184 | j exception_handler |
||
185 | nop |
||
186 | |||
306 | palkovsky | 187 | |
326 | palkovsky | 188 | |
313 | palkovsky | 189 | exception_handler: |
190 | KERNEL_STACK_TO_K0 |
||
191 | sub $k0, REGISTER_SPACE |
||
192 | REGISTERS_STORE $k0 |
||
193 | add $sp, $k0, 0 |
||
194 | |||
317 | palkovsky | 195 | add $a0, $sp, 0 |
196 | jal exception /* exception(register_space) */ |
||
313 | palkovsky | 197 | nop |
198 | |||
199 | REGISTERS_LOAD $sp |
||
200 | # The $sp is automatically restored to former value |
||
201 | eret |
||
202 | nop |
||
203 | |||
1 | jermar | 204 | tlb_refill_handler: |
313 | palkovsky | 205 | KERNEL_STACK_TO_K0 |
206 | sub $k0, REGISTER_SPACE |
||
207 | REGISTERS_STORE $k0 |
||
208 | add $sp, $k0, 0 |
||
125 | jermar | 209 | |
317 | palkovsky | 210 | add $a0, $sp, 0 |
211 | jal tlb_refill /* tlb_refill(register_space) */ |
||
50 | jermar | 212 | nop |
125 | jermar | 213 | |
306 | palkovsky | 214 | REGISTERS_LOAD $sp |
125 | jermar | 215 | |
50 | jermar | 216 | eret |
306 | palkovsky | 217 | nop |
1 | jermar | 218 | |
219 | cache_error_handler: |
||
313 | palkovsky | 220 | KERNEL_STACK_TO_K0 |
306 | palkovsky | 221 | sub $sp, REGISTER_SPACE |
222 | REGISTERS_STORE $sp |
||
313 | palkovsky | 223 | add $sp, $k0, 0 |
1 | jermar | 224 | |
50 | jermar | 225 | jal cache_error |
226 | nop |
||
125 | jermar | 227 | |
306 | palkovsky | 228 | REGISTERS_LOAD $sp |
1 | jermar | 229 | |
50 | jermar | 230 | eret |
308 | jermar | 231 | nop |
313 | palkovsky | 232 | |
233 | userspace_asm: |
||
234 | add $sp, $a0, 0 |
||
1078 | jermar | 235 | add $v0, $a1, 0 |
313 | palkovsky | 236 | eret |
237 | nop |
||
238 |