source: mainline/arch/mips32/src/start.S@ fe050b7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fe050b7 was 2ccd275, checked in by Jakub Jermar <jakub@…>, 20 years ago

Changes in build system.
For .S targets, always do -DASM.
Remove unnecessary #define ASM from various *.S files.
At the end of build, generate disassembler dump for kernel.raw.

ia64 work.
Better General Exception handler.

  • Property mode set to 100644
File size: 4.9 KB
RevLine 
[a5d1331]1#
[178ec7b]2# Copyright (C) 2003-2004 Jakub Jermar
[f761f1eb]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
[e84439a]29#include <arch/asm/regname.h>
30#include <arch/mm/page.h>
31#include <arch/asm/boot.h>
[909c6e3]32#include <arch/context_offset.h>
[e84439a]33
[f761f1eb]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
[2bd4fdf]44.global userspace_asm
[f761f1eb]45
[2bd4fdf]46# Save registers to space defined by \r
47# We will change $at on the way
[e84439a]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)
[909c6e3]56 sw $t0,EOFFSET_T0(\r)
[e84439a]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)
[2bd4fdf]66
67 mflo $at
68 sw $at, EOFFSET_LO(\r)
69 mfhi $at
70 sw $at, EOFFSET_HI(\r)
71
[e84439a]72 sw $s0,EOFFSET_S0(\r)
73 sw $s1,EOFFSET_S1(\r)
74 sw $s2,EOFFSET_S2(\r)
75 sw $s3,EOFFSET_S3(\r)
76 sw $s4,EOFFSET_S4(\r)
77 sw $s5,EOFFSET_S5(\r)
78 sw $s6,EOFFSET_S6(\r)
79 sw $s7,EOFFSET_S7(\r)
80 sw $s8,EOFFSET_S8(\r)
81 sw $gp,EOFFSET_GP(\r)
82 sw $ra,EOFFSET_RA(\r)
[2bd4fdf]83 sw $sp,EOFFSET_SP(\r)
84
85 mfc0 $at, $status
86 sw $at,EOFFSET_STATUS(\r)
[909c6e3]87 mfc0 $at, $epc
88 sw $at,EOFFSET_EPC(\r)
[e84439a]89.endm
90
91.macro REGISTERS_LOAD r
92 lw $v0,EOFFSET_V0(\r)
93 lw $v1,EOFFSET_V1(\r)
94 lw $a0,EOFFSET_A0(\r)
95 lw $a1,EOFFSET_A1(\r)
96 lw $a2,EOFFSET_A2(\r)
97 lw $a3,EOFFSET_A3(\r)
[909c6e3]98 lw $t0,EOFFSET_T0(\r)
[e84439a]99 lw $t1,EOFFSET_T1(\r)
100 lw $t2,EOFFSET_T2(\r)
101 lw $t3,EOFFSET_T3(\r)
102 lw $t4,EOFFSET_T4(\r)
103 lw $t5,EOFFSET_T5(\r)
104 lw $t6,EOFFSET_T6(\r)
105 lw $t7,EOFFSET_T7(\r)
106 lw $t8,EOFFSET_T8(\r)
107 lw $t9,EOFFSET_T9(\r)
108 lw $s0,EOFFSET_S0(\r)
109 lw $s1,EOFFSET_S1(\r)
110 lw $s2,EOFFSET_S2(\r)
111 lw $s3,EOFFSET_S3(\r)
112 lw $s4,EOFFSET_S4(\r)
113 lw $s5,EOFFSET_S5(\r)
114 lw $s6,EOFFSET_S6(\r)
115 lw $s7,EOFFSET_S7(\r)
116 lw $s8,EOFFSET_S8(\r)
117 lw $gp,EOFFSET_GP(\r)
118 lw $ra,EOFFSET_RA(\r)
119
[2bd4fdf]120 lw $at,EOFFSET_LO(\r)
121 mtlo $at
122 lw $at,EOFFSET_HI(\r)
123 mthi $at
124
125 lw $at,EOFFSET_STATUS(\r)
126 mtc0 $at, $status
[909c6e3]127 lw $at,EOFFSET_EPC(\r)
128 mtc0 $at, $epc
[2bd4fdf]129
130 lw $at,EOFFSET_AT(\r)
131 lw $sp,EOFFSET_SP(\r)
[e84439a]132.endm
133
[2bd4fdf]134# Move kernel stack pointer address to register K0
135# - if we are in user mode, load the appropriate stack
136# address
137.macro KERNEL_STACK_TO_K0
138 # If we are in user mode
139 mfc0 $k0, $status
140 andi $k0, 0x10
141
142 beq $k0, $0, 1f
143 add $k0, $sp, 0
[e84439a]144
[2bd4fdf]145 # Move $k0 pointer to kernel stack
146 lui $k0, %hi(supervisor_sp)
[85ddc05]147 ori $k0, $k0, %lo(supervisor_sp)
[2bd4fdf]148 # Move $k0 (superveisor_sp)
149 lw $k0, 0($k0)
1501:
151.endm
152
[f761f1eb]153.org 0x0
[e84439a]154kernel_image_start:
155 /* Load temporary stack */
[2bd4fdf]156 lui $sp, %hi(end_stack)
[85ddc05]157 ori $sp, $sp, %lo(end_stack)
[e84439a]158
159 /* Not sure about this, but might be needed for PIC code???? */
160 lui $gp, 0x8000
161
162 jal main_bsp
163 nop
164
[2bd4fdf]165
[e84439a]166 .space TEMP_STACK_SIZE
[ffc277e]167end_stack:
168
169tlb_refill_entry:
170 j tlb_refill_handler
171 nop
172
173cache_error_entry:
174 j cache_error_handler
175 nop
176
177exception_entry:
178 j exception_handler
179 nop
180
181
[2bd4fdf]182
183exception_handler:
184 KERNEL_STACK_TO_K0
185 sub $k0, REGISTER_SPACE
186 REGISTERS_STORE $k0
187 add $sp, $k0, 0
188
[909c6e3]189 add $a0, $sp, 0
190 jal exception /* exception(register_space) */
[2bd4fdf]191 nop
192
193 REGISTERS_LOAD $sp
194 # The $sp is automatically restored to former value
195 eret
196 nop
[e84439a]197
[f761f1eb]198tlb_refill_handler:
[2bd4fdf]199 KERNEL_STACK_TO_K0
200 sub $k0, REGISTER_SPACE
201 REGISTERS_STORE $k0
202 add $sp, $k0, 0
[76cec1e]203
[909c6e3]204 add $a0, $sp, 0
205 jal tlb_refill /* tlb_refill(register_space) */
[4e1d008]206 nop
[76cec1e]207
[e84439a]208 REGISTERS_LOAD $sp
[76cec1e]209
[4e1d008]210 eret
[e84439a]211 nop
[f761f1eb]212
213cache_error_handler:
[2bd4fdf]214 KERNEL_STACK_TO_K0
[e84439a]215 sub $sp, REGISTER_SPACE
216 REGISTERS_STORE $sp
[2bd4fdf]217 add $sp, $k0, 0
[f761f1eb]218
[4e1d008]219 jal cache_error
220 nop
[76cec1e]221
[e84439a]222 REGISTERS_LOAD $sp
[f761f1eb]223
[4e1d008]224 eret
[a5d1331]225 nop
[2bd4fdf]226
227userspace_asm:
228 add $sp, $a0, 0
229 eret
230 nop
231
Note: See TracBrowser for help on using the repository browser.