Debian Codegraph @

grub-core/boot/mips/startup_raw.S

raw
1 /* startup.S - Startup code for the MIPS. */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009 Free Software Foundation, Inc.
5 *
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <grub/symbol.h>
21 #include <grub/offsets.h>
22 #include <grub/machine/memory.h>
23 #include <grub/machine/kernel.h>
24 #include <grub/offsets.h>
25 #include <grub/mips/asm.h>
26
27 #define BASE_ADDR 8
28
29 .extern __bss_start
30 .extern _end
31 .extern _edata
32
33 .globl __start, _start, start
34 .set noreorder
35 .set nomacro
36 __start:
37 _start:
38 start:
39
40 bal codestart
41 nop
42 base:
43 .org GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE
44 compressed_size:
45 .long 0
46 .org GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE
47 uncompressed_size:
48 .long 0
49 .org GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_ADDR
50 uncompressed_addr:
51 .long 0
52 codestart:
53 /* Save our base. */
54 move $s0, $ra
55
56 /* Parse arguments. Has to be done before relocation.
57 So need to do it in asm. */
58 #ifdef GRUB_MACHINE_MIPS_QEMU_MIPS
59 lui $t0, %hi (((16 << 20) - 264 + 4) | 0x80000000)
60 lw $t1, %lo (((16 << 20) - 264 + 4) | 0x80000000) ($t0)
61
62 lui $t2, 0x1234
63 ori $t2, 0x5678
64
65 bne $t1, $t2, 1f
66 nop
67
68 lui $t0, %hi (((16 << 20) - 264) | 0x80000000)
69 b 2f
70 lw $s4, %lo (((16 << 20) - 264) | 0x80000000) ($t0)
71
72 1:
73 li $s4, 0
74 2:
75 #endif
76
77 #ifdef GRUB_MACHINE_MIPS_LOONGSON
78 move $s2, $zero
79 move $s3, $zero
80 move $s4, $zero
81 move $s5, $zero
82 move $s7, $zero
83
84 /* $a2 has the environment. */
85 addiu $t0, $zero, -0x10
86 and $t1, $a2, $t0
87 beq $t0, $t1, argfw
88 nop
89 move $t0, $a2
90 argcont:
91 lw $t1, 0($t0)
92 beq $t1, $zero, argdone
93 nop
94 #define DO_PARSE(str, reg) \
95 addiu $t2, $s0, (str-base);\
96 bal parsestr;\
97 nop ;\
98 beq $v0, $zero, 1f;\
99 nop ;\
100 b 2f;\
101 move reg, $v0; \
102 1:
103 #define DO_CHECKT1(str, val) \
104 move $t6, $t1 ;\
105 addiu $t7, $s0, (str - base);\
106 bal do_check ;\
107 li $t2, val
108
109 DO_PARSE (busclockstr, $s2)
110 DO_PARSE (cpuclockstr, $s3)
111 DO_PARSE (memsizestr, $s4)
112 DO_PARSE (highmemsizestr, $s5)
113 DO_CHECKT1 (pmon_yeeloong_verstr, GRUB_ARCH_MACHINE_YEELOONG)
114 DO_CHECKT1 (pmon_fuloong2f_verstr, GRUB_ARCH_MACHINE_FULOONG2F)
115 2:
116 b argcont
117 addiu $t0, $t0, 4
118 parsestr:
119 move $v0, $zero
120 move $t3, $t1
121 3:
122 lb GRUB_ASM_T4, 0($t2)
123 lb GRUB_ASM_T5, 0($t3)
124 addiu $t2, $t2, 1
125 addiu $t3, $t3, 1
126 beq GRUB_ASM_T5, $zero, 1f
127 nop
128 beq GRUB_ASM_T5, GRUB_ASM_T4, 3b
129 nop
130 bne GRUB_ASM_T4, $zero, 1f
131 nop
132
133 addiu $t3, $t3, 0xffff
134 digcont:
135 lb GRUB_ASM_T5, 0($t3)
136 /* Substract '0' from digit. */
137 addiu GRUB_ASM_T5, GRUB_ASM_T5, 0xffd0
138 bltz GRUB_ASM_T5, 1f
139 nop
140 addiu GRUB_ASM_T4, GRUB_ASM_T5, 0xfff7
141 bgtz GRUB_ASM_T4, 1f
142 nop
143 /* Multiply $v0 by 10 with bitshifts. */
144 sll $v0, $v0, 1
145 sll GRUB_ASM_T4, $v0, 2
146 addu $v0, $v0, GRUB_ASM_T4
147 addu $v0, $v0, GRUB_ASM_T5
148 addiu $t3, $t3, 1
149 b digcont
150 nop
151 1:
152 jr $ra
153 nop
154 busclockstr: .asciz "busclock="
155 cpuclockstr: .asciz "cpuclock="
156 memsizestr: .asciz "memsize="
157 highmemsizestr: .asciz "highmemsize="
158 machtype_yeeloong_str1: .asciz "machtype=8.9"
159 machtype_yeeloong_str2: .asciz "machtype=lemote-yeeloong-"
160 machtype_fuloong2f_str: .asciz "machtype=lemote-fuloong-2f"
161 machtype_fuloong2e_str: .asciz "machtype=lemote-fuloong-2e"
162 pmon_yeeloong_str: .asciz "PMON_VER=LM8"
163 pmon_fuloong2f_str: .asciz "PMON_VER=LM6"
164 pmon_yeeloong_verstr: .asciz "Version=LM8"
165 pmon_fuloong2f_verstr: .asciz "Version=LM6"
166 .p2align 2
167
168 argdone:
169 beq $a0, $zero, cmdlinedone
170 nop
171 #define DO_CHECKA1(str, val) \
172 lw $t6, 0($a1) ;\
173 addiu $t7, $s0, (str - base);\
174 bal do_check ;\
175 li $t2, val
176 DO_CHECKA1 (machtype_yeeloong_str1, GRUB_ARCH_MACHINE_YEELOONG)
177 DO_CHECKA1 (machtype_yeeloong_str2, GRUB_ARCH_MACHINE_YEELOONG)
178 DO_CHECKA1 (pmon_yeeloong_str, GRUB_ARCH_MACHINE_YEELOONG)
179 DO_CHECKA1 (machtype_fuloong2f_str, GRUB_ARCH_MACHINE_FULOONG2F)
180 DO_CHECKA1 (machtype_fuloong2e_str, GRUB_ARCH_MACHINE_FULOONG2E)
181 DO_CHECKA1 (pmon_fuloong2f_str, GRUB_ARCH_MACHINE_FULOONG2F)
182 addiu $a0, $a0, -1
183 b argdone
184 addiu $a1, $a1, 4
185 do_check:
186 lb GRUB_ASM_T4, 0($t7)
187 beq GRUB_ASM_T4, $zero, 1f
188 lb $t3, 0($t6)
189 bne $t3, GRUB_ASM_T4, 2f
190 addiu $t6, $t6, 1
191 b do_check
192 addiu $t7, $t7, 1
193 1:
194 move $s7, $t2
195 2:
196 jr $ra
197 nop
198 argfw:
199 not $s7, $a2
200 cmdlinedone:
201 #endif
202 #ifdef GRUB_MACHINE_ARC
203 lui $t0, %hi(_start - 256)
204 addiu $t0, $t0, %lo(_start - 256)
205 addiu $t3, $t0, 255
206 lw $t1, 0($a1)
207 1:
208 bne $t0, $t3, 2f
209 lb $t2, 0($t1)
210 move $t2, $zero
211 2:
212 sb $t2, 0($t0)
213 addiu $t0, $t0, 1
214 bnez $t2, 1b
215 addiu $t1, $t1, 1
216 #endif
217 /* Copy the decompressor. */
218 lui $t1, %hi(base)
219 addiu $t1, $t1, %lo(base)
220 lui $t3, %hi(__bss_start)
221 addiu $t3, $t3, %lo(__bss_start)
222 move $t2, $s0
223
224 1:
225 beq $t1, $t3, 2f
226 lb GRUB_ASM_T4, 0($t2)
227 sb GRUB_ASM_T4, 0($t1)
228 addiu $t1, $t1, 1
229 b 1b
230 addiu $t2, $t2, 1
231 2:
232 /* Clean out its BSS. */
233 lui $t1, %hi(__bss_start)
234 addiu $t1, $t1, %lo(__bss_start)
235 lui $t2, %hi(_end)
236 addiu $t2, $t2, %lo(_end)
237 1:
238 beq $t1, $t2, 2f
239 nop
240 sb $zero, 0($t1)
241 b 1b
242 addiu $t1, $t1, 1
243 2:
244 lui $a0, %hi(base)
245 addiu $a0, $a0, %lo(base)
246 lui $a1, %hi(_end)
247 addiu $a1, %lo(_end)
248 subu $a1,$a1,$a0
249
250 #include "../../kern/mips/cache_flush.S"
251
252 /* Decompress the payload. */
253 lui $a0, %hi(_edata)
254 addiu $a0, $a0, %lo(_edata)
255
256 lui $t0, %hi(base)
257 addiu $t0, $t0, %lo(base)
258 subu $a0, $a0, $t0
259 addu $a0, $a0, $s0
260
261 lw $a1, (GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_ADDR - BASE_ADDR)($s0)
262 lw $a2, (GRUB_DECOMPRESSOR_MACHINE_COMPRESSED_SIZE - BASE_ADDR)($s0)
263 lw $a3, (GRUB_DECOMPRESSOR_MACHINE_UNCOMPRESSED_SIZE - BASE_ADDR)($s0)
264 move $s1, $a1
265
266 /* $a0 contains source compressed address, $a1 is destination,
267 $a2 is compressed size, $a3 is uncompressed size.
268 */
269 move $s6, $a3
270
271 lui $t9, %hi(EXT_C(grub_decompress_core))
272 addiu $t9, $t9, %lo(EXT_C(grub_decompress_core))
273
274 #ifdef GRUB_MACHINE_ARC
275 lui $sp, %hi(_start - 512)
276 jalr $t9
277 addiu $sp, $sp, %lo(_start - 512)
278 #else
279 lui $sp, %hi(_start - 256)
280 jalr $t9
281 addiu $sp, $sp, %lo(_start - 256)
282 #endif
283 move $a0, $s1
284 move $a1, $s6
285
286 #include "../../kern/mips/cache_flush.S"
287
288 lui $t1, %hi(GRUB_MACHINE_LINK_ADDR)
289 addiu $t1, %lo(GRUB_MACHINE_LINK_ADDR)
290
291 jr $t1
292 nop
293 /* Ensure that .data section is created. In code we suppose that _edata
294 is first location not in decompressor image. Strictly speaking it's
295 _edata only when .data is present and _etext otherwise. But checking
296 for .data presence would cost more in code than it is to ensure that
297 .data is created.
298 */
299 .data
300 .long 0