Rev 317 | Rev 320 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 317 | Rev 319 | ||
---|---|---|---|
1 | # |
1 | # |
2 | # Copyright (C) 2001-2004 Jakub Jermar |
2 | # Copyright (C) 2003-2004 Jakub Jermar |
3 | # All rights reserved. |
3 | # All rights reserved. |
4 | # |
4 | # |
5 | # Redistribution and use in source and binary forms, with or without |
5 | # Redistribution and use in source and binary forms, with or without |
6 | # modification, are permitted provided that the following conditions |
6 | # modification, are permitted provided that the following conditions |
7 | # are met: |
7 | # are met: |
8 | # |
8 | # |
9 | # - Redistributions of source code must retain the above copyright |
9 | # - Redistributions of source code must retain the above copyright |
10 | # notice, this list of conditions and the following disclaimer. |
10 | # notice, this list of conditions and the following disclaimer. |
11 | # - Redistributions in binary form must reproduce the above copyright |
11 | # - Redistributions in binary form must reproduce the above copyright |
12 | # notice, this list of conditions and the following disclaimer in the |
12 | # notice, this list of conditions and the following disclaimer in the |
13 | # documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | # derived from this software without specific prior written permission. |
16 | # |
16 | # |
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | # |
27 | # |
28 | 28 | ||
29 | #define __ASM__ |
29 | #define __ASM__ |
30 | 30 | ||
31 | #include <arch/asm/regname.h> |
31 | #include <arch/asm/regname.h> |
32 | #include <arch/mm/page.h> |
32 | #include <arch/mm/page.h> |
33 | #include <arch/asm/boot.h> |
33 | #include <arch/asm/boot.h> |
34 | #include <arch/context_offset.h> |
34 | #include <arch/context_offset.h> |
35 | 35 | ||
36 | .text |
36 | .text |
37 | 37 | ||
38 | .set noat |
38 | .set noat |
39 | .set noreorder |
39 | .set noreorder |
40 | .set nomacro |
40 | .set nomacro |
41 | 41 | ||
42 | .global kernel_image_start |
42 | .global kernel_image_start |
43 | .global tlb_refill_entry |
43 | .global tlb_refill_entry |
44 | .global cache_error_entry |
44 | .global cache_error_entry |
45 | .global exception_entry |
45 | .global exception_entry |
46 | .global userspace_asm |
46 | .global userspace_asm |
47 | 47 | ||
48 | # Save registers to space defined by \r |
48 | # Save registers to space defined by \r |
49 | # We will change $at on the way |
49 | # We will change $at on the way |
50 | .macro REGISTERS_STORE r |
50 | .macro REGISTERS_STORE r |
51 | sw $at,EOFFSET_AT(\r) |
51 | sw $at,EOFFSET_AT(\r) |
52 | sw $v0,EOFFSET_V0(\r) |
52 | sw $v0,EOFFSET_V0(\r) |
53 | sw $v1,EOFFSET_V1(\r) |
53 | sw $v1,EOFFSET_V1(\r) |
54 | sw $a0,EOFFSET_A0(\r) |
54 | sw $a0,EOFFSET_A0(\r) |
55 | sw $a1,EOFFSET_A1(\r) |
55 | sw $a1,EOFFSET_A1(\r) |
56 | sw $a2,EOFFSET_A2(\r) |
56 | sw $a2,EOFFSET_A2(\r) |
57 | sw $a3,EOFFSET_A3(\r) |
57 | sw $a3,EOFFSET_A3(\r) |
58 | sw $t0,EOFFSET_T0(\r) |
58 | sw $t0,EOFFSET_T0(\r) |
59 | sw $t1,EOFFSET_T1(\r) |
59 | sw $t1,EOFFSET_T1(\r) |
60 | sw $t2,EOFFSET_T2(\r) |
60 | sw $t2,EOFFSET_T2(\r) |
61 | sw $t3,EOFFSET_T3(\r) |
61 | sw $t3,EOFFSET_T3(\r) |
62 | sw $t4,EOFFSET_T4(\r) |
62 | sw $t4,EOFFSET_T4(\r) |
63 | sw $t5,EOFFSET_T5(\r) |
63 | sw $t5,EOFFSET_T5(\r) |
64 | sw $t6,EOFFSET_T6(\r) |
64 | sw $t6,EOFFSET_T6(\r) |
65 | sw $t7,EOFFSET_T7(\r) |
65 | sw $t7,EOFFSET_T7(\r) |
66 | sw $t8,EOFFSET_T8(\r) |
66 | sw $t8,EOFFSET_T8(\r) |
67 | sw $t9,EOFFSET_T9(\r) |
67 | sw $t9,EOFFSET_T9(\r) |
68 | 68 | ||
69 | mflo $at |
69 | mflo $at |
70 | sw $at, EOFFSET_LO(\r) |
70 | sw $at, EOFFSET_LO(\r) |
71 | mfhi $at |
71 | mfhi $at |
72 | sw $at, EOFFSET_HI(\r) |
72 | sw $at, EOFFSET_HI(\r) |
73 | 73 | ||
74 | sw $s0,EOFFSET_S0(\r) |
74 | sw $s0,EOFFSET_S0(\r) |
75 | sw $s1,EOFFSET_S1(\r) |
75 | sw $s1,EOFFSET_S1(\r) |
76 | sw $s2,EOFFSET_S2(\r) |
76 | sw $s2,EOFFSET_S2(\r) |
77 | sw $s3,EOFFSET_S3(\r) |
77 | sw $s3,EOFFSET_S3(\r) |
78 | sw $s4,EOFFSET_S4(\r) |
78 | sw $s4,EOFFSET_S4(\r) |
79 | sw $s5,EOFFSET_S5(\r) |
79 | sw $s5,EOFFSET_S5(\r) |
80 | sw $s6,EOFFSET_S6(\r) |
80 | sw $s6,EOFFSET_S6(\r) |
81 | sw $s7,EOFFSET_S7(\r) |
81 | sw $s7,EOFFSET_S7(\r) |
82 | sw $s8,EOFFSET_S8(\r) |
82 | sw $s8,EOFFSET_S8(\r) |
83 | sw $gp,EOFFSET_GP(\r) |
83 | sw $gp,EOFFSET_GP(\r) |
84 | sw $ra,EOFFSET_RA(\r) |
84 | sw $ra,EOFFSET_RA(\r) |
85 | sw $sp,EOFFSET_SP(\r) |
85 | sw $sp,EOFFSET_SP(\r) |
86 | 86 | ||
87 | mfc0 $at, $status |
87 | mfc0 $at, $status |
88 | sw $at,EOFFSET_STATUS(\r) |
88 | sw $at,EOFFSET_STATUS(\r) |
89 | mfc0 $at, $epc |
89 | mfc0 $at, $epc |
90 | sw $at,EOFFSET_EPC(\r) |
90 | sw $at,EOFFSET_EPC(\r) |
91 | .endm |
91 | .endm |
92 | 92 | ||
93 | .macro REGISTERS_LOAD r |
93 | .macro REGISTERS_LOAD r |
94 | lw $v0,EOFFSET_V0(\r) |
94 | lw $v0,EOFFSET_V0(\r) |
95 | lw $v1,EOFFSET_V1(\r) |
95 | lw $v1,EOFFSET_V1(\r) |
96 | lw $a0,EOFFSET_A0(\r) |
96 | lw $a0,EOFFSET_A0(\r) |
97 | lw $a1,EOFFSET_A1(\r) |
97 | lw $a1,EOFFSET_A1(\r) |
98 | lw $a2,EOFFSET_A2(\r) |
98 | lw $a2,EOFFSET_A2(\r) |
99 | lw $a3,EOFFSET_A3(\r) |
99 | lw $a3,EOFFSET_A3(\r) |
100 | lw $t0,EOFFSET_T0(\r) |
100 | lw $t0,EOFFSET_T0(\r) |
101 | lw $t1,EOFFSET_T1(\r) |
101 | lw $t1,EOFFSET_T1(\r) |
102 | lw $t2,EOFFSET_T2(\r) |
102 | lw $t2,EOFFSET_T2(\r) |
103 | lw $t3,EOFFSET_T3(\r) |
103 | lw $t3,EOFFSET_T3(\r) |
104 | lw $t4,EOFFSET_T4(\r) |
104 | lw $t4,EOFFSET_T4(\r) |
105 | lw $t5,EOFFSET_T5(\r) |
105 | lw $t5,EOFFSET_T5(\r) |
106 | lw $t6,EOFFSET_T6(\r) |
106 | lw $t6,EOFFSET_T6(\r) |
107 | lw $t7,EOFFSET_T7(\r) |
107 | lw $t7,EOFFSET_T7(\r) |
108 | lw $t8,EOFFSET_T8(\r) |
108 | lw $t8,EOFFSET_T8(\r) |
109 | lw $t9,EOFFSET_T9(\r) |
109 | lw $t9,EOFFSET_T9(\r) |
110 | lw $s0,EOFFSET_S0(\r) |
110 | lw $s0,EOFFSET_S0(\r) |
111 | lw $s1,EOFFSET_S1(\r) |
111 | lw $s1,EOFFSET_S1(\r) |
112 | lw $s2,EOFFSET_S2(\r) |
112 | lw $s2,EOFFSET_S2(\r) |
113 | lw $s3,EOFFSET_S3(\r) |
113 | lw $s3,EOFFSET_S3(\r) |
114 | lw $s4,EOFFSET_S4(\r) |
114 | lw $s4,EOFFSET_S4(\r) |
115 | lw $s5,EOFFSET_S5(\r) |
115 | lw $s5,EOFFSET_S5(\r) |
116 | lw $s6,EOFFSET_S6(\r) |
116 | lw $s6,EOFFSET_S6(\r) |
117 | lw $s7,EOFFSET_S7(\r) |
117 | lw $s7,EOFFSET_S7(\r) |
118 | lw $s8,EOFFSET_S8(\r) |
118 | lw $s8,EOFFSET_S8(\r) |
119 | lw $gp,EOFFSET_GP(\r) |
119 | lw $gp,EOFFSET_GP(\r) |
120 | lw $ra,EOFFSET_RA(\r) |
120 | lw $ra,EOFFSET_RA(\r) |
121 | 121 | ||
122 | lw $at,EOFFSET_LO(\r) |
122 | lw $at,EOFFSET_LO(\r) |
123 | mtlo $at |
123 | mtlo $at |
124 | lw $at,EOFFSET_HI(\r) |
124 | lw $at,EOFFSET_HI(\r) |
125 | mthi $at |
125 | mthi $at |
126 | 126 | ||
127 | lw $at,EOFFSET_STATUS(\r) |
127 | lw $at,EOFFSET_STATUS(\r) |
128 | mtc0 $at, $status |
128 | mtc0 $at, $status |
129 | lw $at,EOFFSET_EPC(\r) |
129 | lw $at,EOFFSET_EPC(\r) |
130 | mtc0 $at, $epc |
130 | mtc0 $at, $epc |
131 | 131 | ||
132 | lw $at,EOFFSET_AT(\r) |
132 | lw $at,EOFFSET_AT(\r) |
133 | lw $sp,EOFFSET_SP(\r) |
133 | lw $sp,EOFFSET_SP(\r) |
134 | .endm |
134 | .endm |
135 | 135 | ||
136 | # Move kernel stack pointer address to register K0 |
136 | # Move kernel stack pointer address to register K0 |
137 | # - if we are in user mode, load the appropriate stack |
137 | # - if we are in user mode, load the appropriate stack |
138 | # address |
138 | # address |
139 | .macro KERNEL_STACK_TO_K0 |
139 | .macro KERNEL_STACK_TO_K0 |
140 | # If we are in user mode |
140 | # If we are in user mode |
141 | mfc0 $k0, $status |
141 | mfc0 $k0, $status |
142 | andi $k0, 0x10 |
142 | andi $k0, 0x10 |
143 | 143 | ||
144 | beq $k0, $0, 1f |
144 | beq $k0, $0, 1f |
145 | add $k0, $sp, 0 |
145 | add $k0, $sp, 0 |
146 | 146 | ||
147 | # Move $k0 pointer to kernel stack |
147 | # Move $k0 pointer to kernel stack |
148 | lui $k0, %hi(supervisor_sp) |
148 | lui $k0, %hi(supervisor_sp) |
149 | ori $k0, %lo(supervisor_sp) |
149 | ori $k0, %lo(supervisor_sp) |
150 | # Move $k0 (superveisor_sp) |
150 | # Move $k0 (superveisor_sp) |
151 | lw $k0, 0($k0) |
151 | lw $k0, 0($k0) |
152 | 1: |
152 | 1: |
153 | .endm |
153 | .endm |
154 | 154 | ||
155 | .org 0x0 |
155 | .org 0x0 |
156 | tlb_refill_entry: |
156 | tlb_refill_entry: |
157 | j tlb_refill_handler |
157 | j tlb_refill_handler |
158 | nop |
158 | nop |
159 | 159 | ||
160 | .org 0x100 |
160 | .org 0x100 |
161 | cache_error_entry: |
161 | cache_error_entry: |
162 | j cache_error_handler |
162 | j cache_error_handler |
163 | nop |
163 | nop |
164 | 164 | ||
165 | .org 0x180 |
165 | .org 0x180 |
166 | norm_exception: |
166 | norm_exception: |
167 | j exception_handler |
167 | j exception_handler |
168 | nop |
168 | nop |
169 | 169 | ||
170 | .org 0x200 |
170 | .org 0x200 |
171 | iv_exception: |
171 | iv_exception: |
172 | j exception_handler |
172 | j exception_handler |
173 | nop |
173 | nop |
174 | 174 | ||
175 | .org KA2PA(KERNEL_STARTUP_ADDRESS) |
175 | .org KA2PA(KERNEL_STARTUP_ADDRESS) |
176 | kernel_image_start: |
176 | kernel_image_start: |
177 | /* Load temporary stack */ |
177 | /* Load temporary stack */ |
178 | lui $sp, %hi(end_stack) |
178 | lui $sp, %hi(end_stack) |
179 | ori $sp, $0, %lo(end_stack) |
179 | ori $sp, $0, %lo(end_stack) |
180 | 180 | ||
181 | /* Not sure about this, but might be needed for PIC code???? */ |
181 | /* Not sure about this, but might be needed for PIC code???? */ |
182 | lui $gp, 0x8000 |
182 | lui $gp, 0x8000 |
183 | 183 | ||
184 | jal main_bsp |
184 | jal main_bsp |
185 | nop |
185 | nop |
186 | 186 | ||
187 | 187 | ||
188 | .space TEMP_STACK_SIZE |
188 | .space TEMP_STACK_SIZE |
189 | end_stack: |
189 | end_stack: |
190 | 190 | ||
191 | exception_handler: |
191 | exception_handler: |
192 | exception_entry: |
192 | exception_entry: |
193 | KERNEL_STACK_TO_K0 |
193 | KERNEL_STACK_TO_K0 |
194 | sub $k0, REGISTER_SPACE |
194 | sub $k0, REGISTER_SPACE |
195 | REGISTERS_STORE $k0 |
195 | REGISTERS_STORE $k0 |
196 | add $sp, $k0, 0 |
196 | add $sp, $k0, 0 |
197 | 197 | ||
198 | add $a0, $sp, 0 |
198 | add $a0, $sp, 0 |
199 | jal exception /* exception(register_space) */ |
199 | jal exception /* exception(register_space) */ |
200 | nop |
200 | nop |
201 | 201 | ||
202 | REGISTERS_LOAD $sp |
202 | REGISTERS_LOAD $sp |
203 | # The $sp is automatically restored to former value |
203 | # The $sp is automatically restored to former value |
204 | eret |
204 | eret |
205 | nop |
205 | nop |
206 | 206 | ||
207 | tlb_refill_handler: |
207 | tlb_refill_handler: |
208 | KERNEL_STACK_TO_K0 |
208 | KERNEL_STACK_TO_K0 |
209 | sub $k0, REGISTER_SPACE |
209 | sub $k0, REGISTER_SPACE |
210 | REGISTERS_STORE $k0 |
210 | REGISTERS_STORE $k0 |
211 | add $sp, $k0, 0 |
211 | add $sp, $k0, 0 |
212 | 212 | ||
213 | add $a0, $sp, 0 |
213 | add $a0, $sp, 0 |
214 | jal tlb_refill /* tlb_refill(register_space) */ |
214 | jal tlb_refill /* tlb_refill(register_space) */ |
215 | nop |
215 | nop |
216 | 216 | ||
217 | REGISTERS_LOAD $sp |
217 | REGISTERS_LOAD $sp |
218 | 218 | ||
219 | eret |
219 | eret |
220 | nop |
220 | nop |
221 | 221 | ||
222 | cache_error_handler: |
222 | cache_error_handler: |
223 | KERNEL_STACK_TO_K0 |
223 | KERNEL_STACK_TO_K0 |
224 | sub $sp, REGISTER_SPACE |
224 | sub $sp, REGISTER_SPACE |
225 | REGISTERS_STORE $sp |
225 | REGISTERS_STORE $sp |
226 | add $sp, $k0, 0 |
226 | add $sp, $k0, 0 |
227 | 227 | ||
228 | jal cache_error |
228 | jal cache_error |
229 | nop |
229 | nop |
230 | 230 | ||
231 | REGISTERS_LOAD $sp |
231 | REGISTERS_LOAD $sp |
232 | 232 | ||
233 | eret |
233 | eret |
234 | nop |
234 | nop |
235 | 235 | ||
236 | userspace_asm: |
236 | userspace_asm: |
237 | add $sp, $a0, 0 |
237 | add $sp, $a0, 0 |
238 | eret |
238 | eret |
239 | nop |
239 | nop |
240 | 240 | ||
241 | 241 |