Commit | Line | Data |
---|---|---|
88278ca2 | 1 | /* |
1da177e4 LT |
2 | * head.S: The initial boot code for the Sparc port of Linux. |
3 | * | |
4 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) | |
5 | * Copyright (C) 1995,1999 Pete Zaitcev (zaitcev@yahoo.com) | |
6 | * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx) | |
7 | * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) | |
8 | * Copyright (C) 1997 Michael A. Griffith (grif@acm.org) | |
9 | * | |
10 | * CompactPCI platform by Eric Brower, 1999. | |
11 | */ | |
12 | ||
13 | #include <linux/version.h> | |
1da177e4 LT |
14 | #include <linux/init.h> |
15 | ||
16 | #include <asm/head.h> | |
17 | #include <asm/asi.h> | |
18 | #include <asm/contregs.h> | |
19 | #include <asm/ptrace.h> | |
20 | #include <asm/psr.h> | |
21 | #include <asm/page.h> | |
19fce2b9 | 22 | #include <asm/kdebug.h> |
1da177e4 LT |
23 | #include <asm/winmacro.h> |
24 | #include <asm/thread_info.h> /* TI_UWINMASK */ | |
25 | #include <asm/errno.h> | |
26 | #include <asm/pgtsrmmu.h> /* SRMMU_PGDIR_SHIFT */ | |
27 | ||
28 | .data | |
eb06f476 SR |
29 | /* The following are used with the prom_vector node-ops to figure out |
30 | * the cpu-type | |
1da177e4 | 31 | */ |
1da177e4 | 32 | .align 4 |
1da177e4 LT |
33 | cputyp: |
34 | .word 1 | |
35 | ||
36 | .align 4 | |
37 | .globl cputypval | |
38 | cputypval: | |
eb06f476 | 39 | .asciz "sun4m" |
1da177e4 LT |
40 | .ascii " " |
41 | ||
eb06f476 | 42 | /* Tested on SS-5, SS-10 */ |
1da177e4 | 43 | .align 4 |
1da177e4 | 44 | cputypvar: |
1da177e4 LT |
45 | .asciz "compatible" |
46 | ||
47 | .align 4 | |
48 | ||
ec24158e SR |
49 | notsup: |
50 | .asciz "Sparc-Linux sun4/sun4c or MMU-less not supported\n\n" | |
1da177e4 | 51 | .align 4 |
1da177e4 LT |
52 | |
53 | sun4e_notsup: | |
54 | .asciz "Sparc-Linux sun4e support does not exist\n\n" | |
55 | .align 4 | |
56 | ||
c64d7524 SR |
57 | /* The trap-table - located in the __HEAD section */ |
58 | #include "ttable_32.S" | |
2c1cfb2d | 59 | |
1da177e4 LT |
60 | .align PAGE_SIZE |
61 | ||
62 | /* This was the only reasonable way I could think of to properly align | |
63 | * these page-table data structures. | |
64 | */ | |
1da177e4 LT |
65 | .globl swapper_pg_dir |
66 | swapper_pg_dir: .skip PAGE_SIZE | |
1b4cb70e | 67 | .globl empty_zero_page |
1da177e4 LT |
68 | empty_zero_page: .skip PAGE_SIZE |
69 | ||
70 | .global root_flags | |
71 | .global ram_flags | |
72 | .global root_dev | |
73 | .global sparc_ramdisk_image | |
74 | .global sparc_ramdisk_size | |
75 | ||
76 | /* This stuff has to be in sync with SILO and other potential boot loaders | |
77 | * Fields should be kept upward compatible and whenever any change is made, | |
78 | * HdrS version should be incremented. | |
79 | */ | |
80 | .ascii "HdrS" | |
81 | .word LINUX_VERSION_CODE | |
82 | .half 0x0203 /* HdrS version */ | |
83 | root_flags: | |
84 | .half 1 | |
85 | root_dev: | |
86 | .half 0 | |
87 | ram_flags: | |
88 | .half 0 | |
89 | sparc_ramdisk_image: | |
90 | .word 0 | |
91 | sparc_ramdisk_size: | |
92 | .word 0 | |
93 | .word reboot_command | |
94 | .word 0, 0, 0 | |
95 | .word _end | |
96 | ||
97 | /* Cool, here we go. Pick up the romvec pointer in %o0 and stash it in | |
98 | * %g7 and at prom_vector_p. And also quickly check whether we are on | |
99 | * a v0, v2, or v3 prom. | |
100 | */ | |
101 | gokernel: | |
102 | /* Ok, it's nice to know, as early as possible, if we | |
103 | * are already mapped where we expect to be in virtual | |
104 | * memory. The Solaris /boot elf format bootloader | |
105 | * will peek into our elf header and load us where | |
106 | * we want to be, otherwise we have to re-map. | |
107 | * | |
108 | * Some boot loaders don't place the jmp'rs address | |
109 | * in %o7, so we do a pc-relative call to a local | |
110 | * label, then see what %o7 has. | |
111 | */ | |
112 | ||
113 | mov %o7, %g4 ! Save %o7 | |
114 | ||
115 | /* Jump to it, and pray... */ | |
116 | current_pc: | |
117 | call 1f | |
118 | nop | |
119 | ||
120 | 1: | |
121 | mov %o7, %g3 | |
122 | ||
123 | tst %o0 | |
124 | be no_sun4u_here | |
125 | mov %g4, %o7 /* Previous %o7. */ | |
ec24158e | 126 | |
1da177e4 LT |
127 | mov %o0, %l0 ! stash away romvec |
128 | mov %o0, %g7 ! put it here too | |
129 | mov %o1, %l1 ! stash away debug_vec too | |
130 | ||
131 | /* Ok, let's check out our run time program counter. */ | |
132 | set current_pc, %g5 | |
133 | cmp %g3, %g5 | |
134 | be already_mapped | |
ec24158e | 135 | nop |
1da177e4 LT |
136 | |
137 | /* %l6 will hold the offset we have to subtract | |
138 | * from absolute symbols in order to access areas | |
139 | * in our own image. If already mapped this is | |
140 | * just plain zero, else it is KERNBASE. | |
141 | */ | |
142 | set KERNBASE, %l6 | |
143 | b copy_prom_lvl14 | |
144 | nop | |
145 | ||
146 | already_mapped: | |
147 | mov 0, %l6 | |
148 | ||
149 | /* Copy over the Prom's level 14 clock handler. */ | |
150 | copy_prom_lvl14: | |
151 | #if 1 | |
152 | /* DJHR | |
153 | * preserve our linked/calculated instructions | |
154 | */ | |
155 | set lvl14_save, %g1 | |
156 | set t_irq14, %g3 | |
157 | sub %g1, %l6, %g1 ! translate to physical | |
158 | sub %g3, %l6, %g3 ! translate to physical | |
159 | ldd [%g3], %g4 | |
160 | std %g4, [%g1] | |
161 | ldd [%g3+8], %g4 | |
162 | std %g4, [%g1+8] | |
163 | #endif | |
164 | rd %tbr, %g1 | |
165 | andn %g1, 0xfff, %g1 ! proms trap table base | |
166 | or %g0, (0x1e<<4), %g2 ! offset to lvl14 intr | |
167 | or %g1, %g2, %g2 | |
168 | set t_irq14, %g3 | |
169 | sub %g3, %l6, %g3 | |
170 | ldd [%g2], %g4 | |
171 | std %g4, [%g3] | |
172 | ldd [%g2 + 0x8], %g4 | |
173 | std %g4, [%g3 + 0x8] ! Copy proms handler | |
174 | ||
323206a1 SR |
175 | /* DON'T TOUCH %l0 thru %l5 in these remapping routines, |
176 | * we need their values afterwards! | |
1da177e4 | 177 | */ |
323206a1 | 178 | |
1da177e4 LT |
179 | /* Now check whether we are already mapped, if we |
180 | * are we can skip all this garbage coming up. | |
181 | */ | |
182 | copy_prom_done: | |
183 | cmp %l6, 0 | |
184 | be go_to_highmem ! this will be a nop then | |
185 | nop | |
186 | ||
9b4c514a DM |
187 | /* Validate that we are in fact running on an |
188 | * SRMMU based cpu. | |
189 | */ | |
190 | set 0x4000, %g6 | |
191 | cmp %g7, %g6 | |
192 | bne not_a_sun4 | |
193 | nop | |
194 | ||
7b372d65 | 195 | halt_notsup: |
9b4c514a | 196 | ld [%g7 + 0x68], %o1 |
ec24158e | 197 | set notsup, %o0 |
9b4c514a DM |
198 | sub %o0, %l6, %o0 |
199 | call %o1 | |
200 | nop | |
201 | ba halt_me | |
202 | nop | |
203 | ||
204 | not_a_sun4: | |
7b372d65 SR |
205 | /* It looks like this is a machine we support. |
206 | * Now find out what MMU we are dealing with | |
207 | * LEON - identified by the psr.impl field | |
208 | * Viking - identified by the psr.impl field | |
209 | * In all other cases a sun4m srmmu. | |
210 | * We check that the MMU is enabled in all cases. | |
211 | */ | |
212 | ||
213 | /* Check if this is a LEON CPU */ | |
214 | rd %psr, %g3 | |
215 | srl %g3, PSR_IMPL_SHIFT, %g3 | |
216 | and %g3, PSR_IMPL_SHIFTED_MASK, %g3 | |
217 | cmp %g3, PSR_IMPL_LEON | |
218 | be leon_remap /* It is a LEON - jump */ | |
219 | nop | |
220 | ||
221 | /* Sanity-check, is MMU enabled */ | |
9b4c514a DM |
222 | lda [%g0] ASI_M_MMUREGS, %g1 |
223 | andcc %g1, 1, %g0 | |
7b372d65 | 224 | be halt_notsup |
9b4c514a DM |
225 | nop |
226 | ||
7b372d65 SR |
227 | /* Check for a viking (TI) module. */ |
228 | cmp %g3, PSR_IMPL_TI | |
229 | bne srmmu_not_viking | |
1da177e4 LT |
230 | nop |
231 | ||
232 | /* Figure out what kind of viking we are on. | |
233 | * We need to know if we have to play with the | |
234 | * AC bit and disable traps or not. | |
235 | */ | |
236 | ||
237 | /* I've only seen MicroSparc's on SparcClassics with this | |
238 | * bit set. | |
239 | */ | |
240 | set 0x800, %g2 | |
241 | lda [%g0] ASI_M_MMUREGS, %g3 ! peek in the control reg | |
242 | and %g2, %g3, %g3 | |
243 | subcc %g3, 0x0, %g0 | |
7b372d65 | 244 | bnz srmmu_not_viking ! is in mbus mode |
1da177e4 | 245 | nop |
ec24158e | 246 | |
1da177e4 LT |
247 | rd %psr, %g3 ! DO NOT TOUCH %g3 |
248 | andn %g3, PSR_ET, %g2 | |
249 | wr %g2, 0x0, %psr | |
250 | WRITE_PAUSE | |
ec24158e | 251 | |
1da177e4 LT |
252 | /* Get context table pointer, then convert to |
253 | * a physical address, which is 36 bits. | |
254 | */ | |
255 | set AC_M_CTPR, %g4 | |
256 | lda [%g4] ASI_M_MMUREGS, %g4 | |
257 | sll %g4, 0x4, %g4 ! We use this below | |
258 | ! DO NOT TOUCH %g4 | |
259 | ||
260 | /* Set the AC bit in the Viking's MMU control reg. */ | |
261 | lda [%g0] ASI_M_MMUREGS, %g5 ! DO NOT TOUCH %g5 | |
262 | set 0x8000, %g6 ! AC bit mask | |
263 | or %g5, %g6, %g6 ! Or it in... | |
264 | sta %g6, [%g0] ASI_M_MMUREGS ! Close your eyes... | |
265 | ||
266 | /* Grrr, why does it seem like every other load/store | |
267 | * on the sun4m is in some ASI space... | |
268 | * Fine with me, let's get the pointer to the level 1 | |
269 | * page table directory and fetch its entry. | |
270 | */ | |
271 | lda [%g4] ASI_M_BYPASS, %o1 ! This is a level 1 ptr | |
272 | srl %o1, 0x4, %o1 ! Clear low 4 bits | |
273 | sll %o1, 0x8, %o1 ! Make physical | |
ec24158e | 274 | |
1da177e4 LT |
275 | /* Ok, pull in the PTD. */ |
276 | lda [%o1] ASI_M_BYPASS, %o2 ! This is the 0x0 16MB pgd | |
277 | ||
278 | /* Calculate to KERNBASE entry. */ | |
ec24158e | 279 | add %o1, KERNBASE >> (SRMMU_PGDIR_SHIFT - 2), %o3 |
1da177e4 LT |
280 | |
281 | /* Poke the entry into the calculated address. */ | |
282 | sta %o2, [%o3] ASI_M_BYPASS | |
283 | ||
284 | /* I don't get it Sun, if you engineered all these | |
285 | * boot loaders and the PROM (thank you for the debugging | |
286 | * features btw) why did you not have them load kernel | |
287 | * images up in high address space, since this is necessary | |
288 | * for ABI compliance anyways? Does this low-mapping provide | |
289 | * enhanced interoperability? | |
290 | * | |
291 | * "The PROM is the computer." | |
292 | */ | |
293 | ||
294 | /* Ok, restore the MMU control register we saved in %g5 */ | |
295 | sta %g5, [%g0] ASI_M_MMUREGS ! POW... ouch | |
296 | ||
297 | /* Turn traps back on. We saved it in %g3 earlier. */ | |
298 | wr %g3, 0x0, %psr ! tick tock, tick tock | |
299 | ||
300 | /* Now we burn precious CPU cycles due to bad engineering. */ | |
301 | WRITE_PAUSE | |
302 | ||
303 | /* Wow, all that just to move a 32-bit value from one | |
304 | * place to another... Jump to high memory. | |
305 | */ | |
306 | b go_to_highmem | |
307 | nop | |
308 | ||
7b372d65 | 309 | srmmu_not_viking: |
1da177e4 LT |
310 | /* This works on viking's in Mbus mode and all |
311 | * other MBUS modules. It is virtually the same as | |
312 | * the above madness sans turning traps off and flipping | |
313 | * the AC bit. | |
314 | */ | |
1da177e4 LT |
315 | set AC_M_CTPR, %g1 |
316 | lda [%g1] ASI_M_MMUREGS, %g1 ! get ctx table ptr | |
317 | sll %g1, 0x4, %g1 ! make physical addr | |
318 | lda [%g1] ASI_M_BYPASS, %g1 ! ptr to level 1 pg_table | |
319 | srl %g1, 0x4, %g1 | |
320 | sll %g1, 0x8, %g1 ! make phys addr for l1 tbl | |
321 | ||
322 | lda [%g1] ASI_M_BYPASS, %g2 ! get level1 entry for 0x0 | |
323 | add %g1, KERNBASE >> (SRMMU_PGDIR_SHIFT - 2), %g3 | |
324 | sta %g2, [%g3] ASI_M_BYPASS ! place at KERNBASE entry | |
325 | b go_to_highmem | |
326 | nop ! wheee.... | |
327 | ||
1da177e4 | 328 | |
7b372d65 SR |
329 | leon_remap: |
330 | /* Sanity-check, is MMU enabled */ | |
331 | lda [%g0] ASI_LEON_MMUREGS, %g1 | |
332 | andcc %g1, 1, %g0 | |
333 | be halt_notsup | |
334 | nop | |
335 | ||
336 | /* Same code as in the srmmu_not_viking case, | |
337 | * with the LEON ASI for mmuregs | |
338 | */ | |
339 | set AC_M_CTPR, %g1 | |
340 | lda [%g1] ASI_LEON_MMUREGS, %g1 ! get ctx table ptr | |
341 | sll %g1, 0x4, %g1 ! make physical addr | |
342 | lda [%g1] ASI_M_BYPASS, %g1 ! ptr to level 1 pg_table | |
343 | srl %g1, 0x4, %g1 | |
344 | sll %g1, 0x8, %g1 ! make phys addr for l1 tbl | |
345 | ||
346 | lda [%g1] ASI_M_BYPASS, %g2 ! get level1 entry for 0x0 | |
347 | add %g1, KERNBASE >> (SRMMU_PGDIR_SHIFT - 2), %g3 | |
348 | sta %g2, [%g3] ASI_M_BYPASS ! place at KERNBASE entry | |
349 | b go_to_highmem | |
350 | nop ! wheee.... | |
351 | ||
1da177e4 LT |
352 | /* Now do a non-relative jump so that PC is in high-memory */ |
353 | go_to_highmem: | |
354 | set execute_in_high_mem, %g1 | |
355 | jmpl %g1, %g0 | |
356 | nop | |
357 | ||
358 | /* The code above should be at beginning and we have to take care about | |
a0871e8c | 359 | * short jumps, as branching to .init.text section from .text is usually |
1da177e4 LT |
360 | * impossible */ |
361 | __INIT | |
362 | /* Acquire boot time privileged register values, this will help debugging. | |
363 | * I figure out and store nwindows and nwindowsm1 later on. | |
364 | */ | |
365 | execute_in_high_mem: | |
366 | mov %l0, %o0 ! put back romvec | |
367 | mov %l1, %o1 ! and debug_vec | |
368 | ||
369 | sethi %hi(prom_vector_p), %g1 | |
370 | st %o0, [%g1 + %lo(prom_vector_p)] | |
371 | ||
372 | sethi %hi(linux_dbvec), %g1 | |
373 | st %o1, [%g1 + %lo(linux_dbvec)] | |
374 | ||
30005efc SR |
375 | /* Check if this is a LEON CPU. |
376 | * Skip getprops call if it is | |
377 | */ | |
378 | srl %g3, PSR_IMPL_SHIFT, %g3 | |
379 | and %g3, PSR_IMPL_SHIFTED_MASK, %g3 | |
380 | cmp %g3, PSR_IMPL_LEON | |
381 | bne get_cputype | |
1da177e4 | 382 | |
8401707f | 383 | |
30005efc | 384 | /* LEON CPU - set boot_cpu_id */ |
01dae0f0 | 385 | sethi %hi(boot_cpu_id), %g2 ! boot-cpu index |
8401707f | 386 | |
01dae0f0 DH |
387 | #ifdef CONFIG_SMP |
388 | ldub [%g2 + %lo(boot_cpu_id)], %g1 | |
389 | cmp %g1, 0xff ! unset means first CPU | |
390 | bne leon_smp_cpu_startup ! continue only with master | |
391 | nop | |
392 | #endif | |
393 | /* Get CPU-ID from most significant 4-bit of ASR17 */ | |
394 | rd %asr17, %g1 | |
395 | srl %g1, 28, %g1 | |
8401707f | 396 | |
01dae0f0 DH |
397 | /* Update boot_cpu_id only on boot cpu */ |
398 | stub %g1, [%g2 + %lo(boot_cpu_id)] | |
8401707f | 399 | |
323206a1 | 400 | ba continue_boot |
0fd7ef1f | 401 | nop |
30005efc SR |
402 | |
403 | /* Get the machine type via the mysterious romvec node operations. */ | |
404 | get_cputype: | |
405 | add %g7, 0x1c, %l1 | |
406 | ld [%l1], %l0 | |
407 | ld [%l0], %l0 | |
408 | call %l0 | |
409 | or %g0, %g0, %o0 ! next_node(0) = first_node | |
410 | or %o0, %g0, %g6 | |
411 | ||
412 | sethi %hi(cputypvar), %o1 ! First node has cpu-arch | |
413 | or %o1, %lo(cputypvar), %o1 | |
414 | sethi %hi(cputypval), %o2 ! information, the string | |
415 | or %o2, %lo(cputypval), %o2 | |
416 | ld [%l1], %l0 ! 'compatible' tells | |
417 | ld [%l0 + 0xc], %l0 ! that we want 'sun4x' where | |
418 | call %l0 ! x is one of 'm', 'd' or 'e'. | |
419 | nop ! %o2 holds pointer | |
420 | ! to a buf where above string | |
421 | ! will get stored by the prom. | |
d6ea5573 SR |
422 | |
423 | /* Check to cputype. We may be booted on a sun4u (64 bit box), | |
424 | * and sun4d needs special treatment. | |
425 | */ | |
1da177e4 LT |
426 | set cputypval, %o2 |
427 | ldub [%o2 + 0x4], %l1 | |
428 | ||
d6ea5573 SR |
429 | cmp %l1, 'm' |
430 | be sun4m_init | |
1da177e4 | 431 | cmp %l1, 's' |
d6ea5573 | 432 | be sun4m_init |
1da177e4 | 433 | cmp %l1, 'd' |
d6ea5573 | 434 | be sun4d_init |
1da177e4 LT |
435 | cmp %l1, 'e' |
436 | be no_sun4e_here ! Could be a sun4e. | |
437 | nop | |
438 | b no_sun4u_here ! AIEEE, a V9 sun4u... Get our BIG BROTHER kernel :)) | |
439 | nop | |
440 | ||
1da177e4 LT |
441 | /* CPUID in bootbus can be found at PA 0xff0140000 */ |
442 | #define SUN4D_BOOTBUS_CPUID 0xf0140000 | |
443 | ||
444 | sun4d_init: | |
445 | /* Need to patch call to handler_irq */ | |
446 | set patch_handler_irq, %g4 | |
447 | set sun4d_handler_irq, %g5 | |
448 | sethi %hi(0x40000000), %g3 ! call | |
449 | sub %g5, %g4, %g5 | |
450 | srl %g5, 2, %g5 | |
451 | or %g5, %g3, %g5 | |
452 | st %g5, [%g4] | |
453 | ||
454 | #ifdef CONFIG_SMP | |
455 | /* Get our CPU id out of bootbus */ | |
456 | set SUN4D_BOOTBUS_CPUID, %g3 | |
457 | lduba [%g3] ASI_M_CTL, %g3 | |
458 | and %g3, 0xf8, %g3 | |
459 | srl %g3, 3, %g4 | |
460 | sta %g4, [%g0] ASI_M_VIKING_TMP1 | |
461 | sethi %hi(boot_cpu_id), %g5 | |
462 | stb %g4, [%g5 + %lo(boot_cpu_id)] | |
1da177e4 LT |
463 | #endif |
464 | ||
465 | /* Fall through to sun4m_init */ | |
466 | ||
467 | sun4m_init: | |
1da177e4 LT |
468 | /* Ok, the PROM could have done funny things and apple cider could still |
469 | * be sitting in the fault status/address registers. Read them all to | |
470 | * clear them so we don't get magic faults later on. | |
471 | */ | |
472 | /* This sucks, apparently this makes Vikings call prom panic, will fix later */ | |
473 | 2: | |
474 | rd %psr, %o1 | |
30005efc | 475 | srl %o1, PSR_IMPL_SHIFT, %o1 ! Get a type of the CPU |
1da177e4 | 476 | |
30005efc | 477 | subcc %o1, PSR_IMPL_TI, %g0 ! TI: Viking or MicroSPARC |
323206a1 | 478 | be continue_boot |
1da177e4 LT |
479 | nop |
480 | ||
481 | set AC_M_SFSR, %o0 | |
482 | lda [%o0] ASI_M_MMUREGS, %g0 | |
483 | set AC_M_SFAR, %o0 | |
484 | lda [%o0] ASI_M_MMUREGS, %g0 | |
485 | ||
486 | /* Fujitsu MicroSPARC-II has no asynchronous flavors of FARs */ | |
487 | subcc %o1, 0, %g0 | |
323206a1 | 488 | be continue_boot |
1da177e4 LT |
489 | nop |
490 | ||
491 | set AC_M_AFSR, %o0 | |
492 | lda [%o0] ASI_M_MMUREGS, %g0 | |
493 | set AC_M_AFAR, %o0 | |
494 | lda [%o0] ASI_M_MMUREGS, %g0 | |
495 | nop | |
496 | ||
497 | ||
323206a1 | 498 | continue_boot: |
1da177e4 LT |
499 | |
500 | /* Aieee, now set PC and nPC, enable traps, give ourselves a stack and it's | |
501 | * show-time! | |
502 | */ | |
503 | ||
504 | sethi %hi(cputyp), %o0 | |
505 | st %g4, [%o0 + %lo(cputyp)] | |
506 | ||
507 | /* Turn on Supervisor, EnableFloating, and all the PIL bits. | |
508 | * Also puts us in register window zero with traps off. | |
509 | */ | |
510 | set (PSR_PS | PSR_S | PSR_PIL | PSR_EF), %g2 | |
511 | wr %g2, 0x0, %psr | |
512 | WRITE_PAUSE | |
513 | ||
514 | /* I want a kernel stack NOW! */ | |
515 | set init_thread_union, %g1 | |
516 | set (THREAD_SIZE - STACKFRAME_SZ), %g2 | |
517 | add %g1, %g2, %sp | |
518 | mov 0, %fp /* And for good luck */ | |
519 | ||
520 | /* Zero out our BSS section. */ | |
521 | set __bss_start , %o0 ! First address of BSS | |
86ed40bd | 522 | set _end , %o1 ! Last address of BSS |
1da177e4 | 523 | add %o0, 0x1, %o0 |
ec24158e | 524 | 1: |
1da177e4 LT |
525 | stb %g0, [%o0] |
526 | subcc %o0, %o1, %g0 | |
527 | bl 1b | |
528 | add %o0, 0x1, %o0 | |
529 | ||
5fcafb7a DH |
530 | /* If boot_cpu_id has not been setup by machine specific |
531 | * init-code above we default it to zero. | |
532 | */ | |
533 | sethi %hi(boot_cpu_id), %g2 | |
534 | ldub [%g2 + %lo(boot_cpu_id)], %g3 | |
535 | cmp %g3, 0xff | |
536 | bne 1f | |
537 | nop | |
538 | mov %g0, %g3 | |
539 | stub %g3, [%g2 + %lo(boot_cpu_id)] | |
540 | ||
837ebf0e | 541 | 1: sll %g3, 2, %g3 |
5fcafb7a | 542 | |
1da177e4 LT |
543 | /* Initialize the uwinmask value for init task just in case. |
544 | * But first make current_set[boot_cpu_id] point to something useful. | |
545 | */ | |
546 | set init_thread_union, %g6 | |
547 | set current_set, %g2 | |
548 | #ifdef CONFIG_SMP | |
1da177e4 LT |
549 | st %g6, [%g2] |
550 | add %g2, %g3, %g2 | |
551 | #endif | |
552 | st %g6, [%g2] | |
553 | ||
554 | st %g0, [%g6 + TI_UWINMASK] | |
555 | ||
556 | /* Compute NWINDOWS and stash it away. Now uses %wim trick explained | |
557 | * in the V8 manual. Ok, this method seems to work, Sparc is cool... | |
558 | * No, it doesn't work, have to play the save/readCWP/restore trick. | |
559 | */ | |
560 | ||
561 | wr %g0, 0x0, %wim ! so we do not get a trap | |
562 | WRITE_PAUSE | |
563 | ||
564 | save | |
565 | ||
566 | rd %psr, %g3 | |
567 | ||
568 | restore | |
569 | ||
570 | and %g3, 0x1f, %g3 | |
571 | add %g3, 0x1, %g3 | |
572 | ||
573 | mov 2, %g1 | |
574 | wr %g1, 0x0, %wim ! make window 1 invalid | |
575 | WRITE_PAUSE | |
576 | ||
577 | cmp %g3, 0x7 | |
578 | bne 2f | |
579 | nop | |
580 | ||
581 | /* Adjust our window handling routines to | |
582 | * do things correctly on 7 window Sparcs. | |
583 | */ | |
584 | ||
585 | #define PATCH_INSN(src, dest) \ | |
586 | set src, %g5; \ | |
587 | set dest, %g2; \ | |
588 | ld [%g5], %g4; \ | |
589 | st %g4, [%g2]; | |
ec24158e | 590 | |
1da177e4 LT |
591 | /* Patch for window spills... */ |
592 | PATCH_INSN(spnwin_patch1_7win, spnwin_patch1) | |
593 | PATCH_INSN(spnwin_patch2_7win, spnwin_patch2) | |
594 | PATCH_INSN(spnwin_patch3_7win, spnwin_patch3) | |
595 | ||
596 | /* Patch for window fills... */ | |
597 | PATCH_INSN(fnwin_patch1_7win, fnwin_patch1) | |
598 | PATCH_INSN(fnwin_patch2_7win, fnwin_patch2) | |
599 | ||
600 | /* Patch for trap entry setup... */ | |
601 | PATCH_INSN(tsetup_7win_patch1, tsetup_patch1) | |
602 | PATCH_INSN(tsetup_7win_patch2, tsetup_patch2) | |
603 | PATCH_INSN(tsetup_7win_patch3, tsetup_patch3) | |
604 | PATCH_INSN(tsetup_7win_patch4, tsetup_patch4) | |
605 | PATCH_INSN(tsetup_7win_patch5, tsetup_patch5) | |
606 | PATCH_INSN(tsetup_7win_patch6, tsetup_patch6) | |
607 | ||
608 | /* Patch for returning from traps... */ | |
609 | PATCH_INSN(rtrap_7win_patch1, rtrap_patch1) | |
610 | PATCH_INSN(rtrap_7win_patch2, rtrap_patch2) | |
611 | PATCH_INSN(rtrap_7win_patch3, rtrap_patch3) | |
612 | PATCH_INSN(rtrap_7win_patch4, rtrap_patch4) | |
613 | PATCH_INSN(rtrap_7win_patch5, rtrap_patch5) | |
614 | ||
615 | /* Patch for killing user windows from the register file. */ | |
616 | PATCH_INSN(kuw_patch1_7win, kuw_patch1) | |
617 | ||
618 | /* Now patch the kernel window flush sequences. | |
619 | * This saves 2 traps on every switch and fork. | |
620 | */ | |
621 | set 0x01000000, %g4 | |
622 | set flush_patch_one, %g5 | |
623 | st %g4, [%g5 + 0x18] | |
624 | st %g4, [%g5 + 0x1c] | |
625 | set flush_patch_two, %g5 | |
626 | st %g4, [%g5 + 0x18] | |
627 | st %g4, [%g5 + 0x1c] | |
628 | set flush_patch_three, %g5 | |
629 | st %g4, [%g5 + 0x18] | |
630 | st %g4, [%g5 + 0x1c] | |
631 | set flush_patch_four, %g5 | |
632 | st %g4, [%g5 + 0x18] | |
633 | st %g4, [%g5 + 0x1c] | |
634 | set flush_patch_exception, %g5 | |
635 | st %g4, [%g5 + 0x18] | |
636 | st %g4, [%g5 + 0x1c] | |
637 | set flush_patch_switch, %g5 | |
638 | st %g4, [%g5 + 0x18] | |
639 | st %g4, [%g5 + 0x1c] | |
640 | ||
ec24158e | 641 | 2: |
1da177e4 LT |
642 | sethi %hi(nwindows), %g4 |
643 | st %g3, [%g4 + %lo(nwindows)] ! store final value | |
644 | sub %g3, 0x1, %g3 | |
645 | sethi %hi(nwindowsm1), %g4 | |
646 | st %g3, [%g4 + %lo(nwindowsm1)] | |
647 | ||
648 | /* Here we go, start using Linux's trap table... */ | |
649 | set trapbase, %g3 | |
650 | wr %g3, 0x0, %tbr | |
651 | WRITE_PAUSE | |
652 | ||
653 | /* Finally, turn on traps so that we can call c-code. */ | |
654 | rd %psr, %g3 | |
655 | wr %g3, 0x0, %psr | |
656 | WRITE_PAUSE | |
657 | ||
658 | wr %g3, PSR_ET, %psr | |
659 | WRITE_PAUSE | |
660 | ||
4efb55e6 | 661 | /* Call sparc32_start_kernel(struct linux_romvec *rp) */ |
1da177e4 LT |
662 | sethi %hi(prom_vector_p), %g5 |
663 | ld [%g5 + %lo(prom_vector_p)], %o0 | |
4efb55e6 | 664 | call sparc32_start_kernel |
1da177e4 | 665 | nop |
ec24158e | 666 | |
1da177e4 LT |
667 | /* We should not get here. */ |
668 | call halt_me | |
669 | nop | |
5110bd21 | 670 | |
1da177e4 LT |
671 | no_sun4e_here: |
672 | ld [%g7 + 0x68], %o1 | |
673 | set sun4e_notsup, %o0 | |
674 | call %o1 | |
675 | nop | |
676 | b halt_me | |
677 | nop | |
678 | ||
679 | __INITDATA | |
680 | ||
681 | sun4u_1: | |
682 | .asciz "finddevice" | |
683 | .align 4 | |
684 | sun4u_2: | |
685 | .asciz "/chosen" | |
686 | .align 4 | |
687 | sun4u_3: | |
688 | .asciz "getprop" | |
689 | .align 4 | |
690 | sun4u_4: | |
691 | .asciz "stdout" | |
692 | .align 4 | |
693 | sun4u_5: | |
694 | .asciz "write" | |
695 | .align 4 | |
696 | sun4u_6: | |
ec24158e | 697 | .asciz "\n\rOn sun4u you have to use sparc64 kernel\n\rand not a sparc32 version\n\r\n\r" |
1da177e4 LT |
698 | sun4u_6e: |
699 | .align 4 | |
700 | sun4u_7: | |
701 | .asciz "exit" | |
702 | .align 8 | |
703 | sun4u_a1: | |
704 | .word 0, sun4u_1, 0, 1, 0, 1, 0, sun4u_2, 0 | |
705 | sun4u_r1: | |
706 | .word 0 | |
707 | sun4u_a2: | |
708 | .word 0, sun4u_3, 0, 4, 0, 1, 0 | |
709 | sun4u_i2: | |
710 | .word 0, 0, sun4u_4, 0, sun4u_1, 0, 8, 0 | |
711 | sun4u_r2: | |
712 | .word 0 | |
713 | sun4u_a3: | |
714 | .word 0, sun4u_5, 0, 3, 0, 1, 0 | |
715 | sun4u_i3: | |
716 | .word 0, 0, sun4u_6, 0, sun4u_6e - sun4u_6 - 1, 0 | |
717 | sun4u_r3: | |
718 | .word 0 | |
719 | sun4u_a4: | |
720 | .word 0, sun4u_7, 0, 0, 0, 0 | |
721 | sun4u_r4: | |
722 | ||
723 | __INIT | |
724 | no_sun4u_here: | |
725 | set sun4u_a1, %o0 | |
726 | set current_pc, %l2 | |
727 | cmp %l2, %g3 | |
728 | be 1f | |
729 | mov %o4, %l0 | |
730 | sub %g3, %l2, %l6 | |
731 | add %o0, %l6, %o0 | |
732 | mov %o0, %l4 | |
733 | mov sun4u_r4 - sun4u_a1, %l3 | |
734 | ld [%l4], %l5 | |
735 | 2: | |
736 | add %l4, 4, %l4 | |
737 | cmp %l5, %l2 | |
738 | add %l5, %l6, %l5 | |
739 | bgeu,a 3f | |
740 | st %l5, [%l4 - 4] | |
741 | 3: | |
742 | subcc %l3, 4, %l3 | |
743 | bne 2b | |
744 | ld [%l4], %l5 | |
745 | 1: | |
746 | call %l0 | |
747 | mov %o0, %l1 | |
748 | ||
749 | ld [%l1 + (sun4u_r1 - sun4u_a1)], %o1 | |
750 | add %l1, (sun4u_a2 - sun4u_a1), %o0 | |
751 | call %l0 | |
752 | st %o1, [%o0 + (sun4u_i2 - sun4u_a2)] | |
753 | ||
754 | ld [%l1 + (sun4u_1 - sun4u_a1)], %o1 | |
755 | add %l1, (sun4u_a3 - sun4u_a1), %o0 | |
756 | call %l0 | |
757 | st %o1, [%o0 + (sun4u_i3 - sun4u_a3)] | |
758 | ||
759 | call %l0 | |
760 | add %l1, (sun4u_a4 - sun4u_a1), %o0 | |
761 | ||
762 | /* Not reached */ | |
763 | halt_me: | |
764 | ld [%g7 + 0x74], %o0 | |
765 | call %o0 ! Get us out of here... | |
766 | nop ! Apparently Solaris is better. | |
767 | ||
768 | /* Ok, now we continue in the .data/.text sections */ | |
769 | ||
770 | .data | |
771 | .align 4 | |
772 | ||
773 | /* | |
774 | * Fill up the prom vector, note in particular the kind first element, | |
775 | * no joke. I don't need all of them in here as the entire prom vector | |
776 | * gets initialized in c-code so all routines can use it. | |
777 | */ | |
778 | ||
1da177e4 LT |
779 | prom_vector_p: |
780 | .word 0 | |
781 | ||
782 | /* We calculate the following at boot time, window fills/spills and trap entry | |
783 | * code uses these to keep track of the register windows. | |
784 | */ | |
785 | ||
786 | .align 4 | |
787 | .globl nwindows | |
788 | .globl nwindowsm1 | |
789 | nwindows: | |
790 | .word 8 | |
791 | nwindowsm1: | |
792 | .word 7 | |
793 | ||
794 | /* Boot time debugger vector value. We need this later on. */ | |
795 | ||
796 | .align 4 | |
797 | .globl linux_dbvec | |
798 | linux_dbvec: | |
799 | .word 0 | |
800 | .word 0 | |
801 | ||
802 | .align 8 | |
803 | ||
804 | .globl lvl14_save | |
805 | lvl14_save: | |
806 | .word 0 | |
807 | .word 0 | |
808 | .word 0 | |
809 | .word 0 | |
810 | .word t_irq14 | |
811 | ||
812 | .section ".fixup",#alloc,#execinstr | |
813 | .globl __ret_efault | |
814 | __ret_efault: | |
815 | ret | |
816 | restore %g0, -EFAULT, %o0 |