blob: 5a418d32d94c93fa5ea353d5b961d05c4eb8c59c [file] [log] [blame]
Adrian Bunk88278ca2008-05-19 16:53:02 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#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>
Robert Reif19fce2b2007-05-14 03:22:08 -070022#include <asm/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#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
Sam Ravnborgeb06f472012-05-12 01:43:48 +000029/* The following are used with the prom_vector node-ops to figure out
30 * the cpu-type
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 .align 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070033cputyp:
34 .word 1
35
36 .align 4
37 .globl cputypval
38cputypval:
Sam Ravnborgeb06f472012-05-12 01:43:48 +000039 .asciz "sun4m"
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 .ascii " "
41
Sam Ravnborgeb06f472012-05-12 01:43:48 +000042/* Tested on SS-5, SS-10 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 .align 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070044cputypvar:
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 .asciz "compatible"
46
47 .align 4
48
Sam Ravnborgec241582012-05-25 21:20:05 +000049notsup:
50 .asciz "Sparc-Linux sun4/sun4c or MMU-less not supported\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 .align 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53sun4e_notsup:
54 .asciz "Sparc-Linux sun4e support does not exist\n\n"
55 .align 4
56
Sam Ravnborgc64d7522012-05-19 20:02:45 +000057/* The trap-table - located in the __HEAD section */
58#include "ttable_32.S"
Sam Ravnborg2c1cfb22012-05-11 11:35:04 +000059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 .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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 .globl swapper_pg_dir
66swapper_pg_dir: .skip PAGE_SIZE
Sam Ravnborg1b4cb702012-05-12 01:43:46 +000067 .globl empty_zero_page
Linus Torvalds1da177e2005-04-16 15:20:36 -070068empty_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 */
83root_flags:
84 .half 1
85root_dev:
86 .half 0
87ram_flags:
88 .half 0
89sparc_ramdisk_image:
90 .word 0
91sparc_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 */
101gokernel:
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... */
116current_pc:
117 call 1f
118 nop
119
1201:
121 mov %o7, %g3
122
123 tst %o0
124 be no_sun4u_here
125 mov %g4, %o7 /* Previous %o7. */
Sam Ravnborgec241582012-05-25 21:20:05 +0000126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 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
Sam Ravnborgec241582012-05-25 21:20:05 +0000135 nop
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
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
146already_mapped:
147 mov 0, %l6
148
149 /* Copy over the Prom's level 14 clock handler. */
150copy_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
Sam Ravnborg323206a2012-05-11 11:35:15 +0000175/* DON'T TOUCH %l0 thru %l5 in these remapping routines,
176 * we need their values afterwards!
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 */
Sam Ravnborg323206a2012-05-11 11:35:15 +0000178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 /* Now check whether we are already mapped, if we
180 * are we can skip all this garbage coming up.
181 */
182copy_prom_done:
183 cmp %l6, 0
184 be go_to_highmem ! this will be a nop then
185 nop
186
David S. Miller9b4c5142012-05-12 01:02:11 -0700187 /* 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
Sam Ravnborg7b372d62012-05-25 21:20:06 +0000195halt_notsup:
David S. Miller9b4c5142012-05-12 01:02:11 -0700196 ld [%g7 + 0x68], %o1
Sam Ravnborgec241582012-05-25 21:20:05 +0000197 set notsup, %o0
David S. Miller9b4c5142012-05-12 01:02:11 -0700198 sub %o0, %l6, %o0
199 call %o1
200 nop
201 ba halt_me
202 nop
203
204not_a_sun4:
Sam Ravnborg7b372d62012-05-25 21:20:06 +0000205 /* 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 */
David S. Miller9b4c5142012-05-12 01:02:11 -0700219 nop
220
Sam Ravnborg7b372d62012-05-25 21:20:06 +0000221 /* Sanity-check, is MMU enabled */
222 lda [%g0] ASI_M_MMUREGS, %g1
223 andcc %g1, 1, %g0
224 be halt_notsup
225 nop
226
227 /* Check for a viking (TI) module. */
228 cmp %g3, PSR_IMPL_TI
229 bne srmmu_not_viking
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 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
Sam Ravnborg7b372d62012-05-25 21:20:06 +0000244 bnz srmmu_not_viking ! is in mbus mode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 nop
Sam Ravnborgec241582012-05-25 21:20:05 +0000246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 rd %psr, %g3 ! DO NOT TOUCH %g3
248 andn %g3, PSR_ET, %g2
249 wr %g2, 0x0, %psr
250 WRITE_PAUSE
Sam Ravnborgec241582012-05-25 21:20:05 +0000251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 /* 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
Sam Ravnborgec241582012-05-25 21:20:05 +0000274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 /* Ok, pull in the PTD. */
276 lda [%o1] ASI_M_BYPASS, %o2 ! This is the 0x0 16MB pgd
277
278 /* Calculate to KERNBASE entry. */
Sam Ravnborgec241582012-05-25 21:20:05 +0000279 add %o1, KERNBASE >> (SRMMU_PGDIR_SHIFT - 2), %o3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
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
Sam Ravnborg7b372d62012-05-25 21:20:06 +0000309srmmu_not_viking:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 /* 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Sam Ravnborg7b372d62012-05-25 21:20:06 +0000329leon_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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352/* Now do a non-relative jump so that PC is in high-memory */
353go_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
Tim Abbotta0871e82009-04-27 14:02:26 -0400359 * short jumps, as branching to .init.text section from .text is usually
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 * 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 */
365execute_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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375/* Get the machine type via the mysterious romvec node operations. */
376
Sam Ravnborgeb06f472012-05-12 01:43:48 +0000377 add %g7, 0x1c, %l1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 ld [%l1], %l0
379 ld [%l0], %l0
Sam Ravnborgeb06f472012-05-12 01:43:48 +0000380 call %l0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 or %g0, %g0, %o0 ! next_node(0) = first_node
382 or %o0, %g0, %g6
383
384 sethi %hi(cputypvar), %o1 ! First node has cpu-arch
385 or %o1, %lo(cputypvar), %o1
386 sethi %hi(cputypval), %o2 ! information, the string
387 or %o2, %lo(cputypval), %o2
Sam Ravnborgeb06f472012-05-12 01:43:48 +0000388 ld [%l1], %l0 ! 'compatible' tells
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 ld [%l0 + 0xc], %l0 ! that we want 'sun4x' where
Sam Ravnborgeb06f472012-05-12 01:43:48 +0000390 call %l0 ! x is one of 'm', 'd' or 'e'.
391 nop ! %o2 holds pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 ! to a buf where above string
393 ! will get stored by the prom.
394
Konrad Eisele0fd7ef12009-08-17 00:13:31 +0000395#ifdef CONFIG_SPARC_LEON
396 /* no cpu-type check is needed, it is a SPARC-LEON */
Daniel Hellstrom01dae0f2011-04-21 04:20:24 +0000397
398 sethi %hi(boot_cpu_id), %g2 ! boot-cpu index
399
Konrad Eisele84017072009-08-31 22:08:13 +0000400#ifdef CONFIG_SMP
Daniel Hellstrom01dae0f2011-04-21 04:20:24 +0000401 ldub [%g2 + %lo(boot_cpu_id)], %g1
402 cmp %g1, 0xff ! unset means first CPU
403 bne leon_smp_cpu_startup ! continue only with master
Konrad Eisele0fd7ef12009-08-17 00:13:31 +0000404 nop
405#endif
Daniel Hellstrom01dae0f2011-04-21 04:20:24 +0000406 /* Get CPU-ID from most significant 4-bit of ASR17 */
407 rd %asr17, %g1
408 srl %g1, 28, %g1
409
410 /* Update boot_cpu_id only on boot cpu */
411 stub %g1, [%g2 + %lo(boot_cpu_id)]
412
Sam Ravnborg323206a2012-05-11 11:35:15 +0000413 ba continue_boot
Daniel Hellstrom01dae0f2011-04-21 04:20:24 +0000414 nop
Konrad Eisele84017072009-08-31 22:08:13 +0000415#endif
Sam Ravnborgd6ea5572012-05-12 01:43:49 +0000416
417/* Check to cputype. We may be booted on a sun4u (64 bit box),
418 * and sun4d needs special treatment.
419 */
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 set cputypval, %o2
422 ldub [%o2 + 0x4], %l1
423
Sam Ravnborgd6ea5572012-05-12 01:43:49 +0000424 cmp %l1, 'm'
425 be sun4m_init
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 cmp %l1, 's'
Sam Ravnborgd6ea5572012-05-12 01:43:49 +0000427 be sun4m_init
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 cmp %l1, 'd'
Sam Ravnborgd6ea5572012-05-12 01:43:49 +0000429 be sun4d_init
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 cmp %l1, 'e'
431 be no_sun4e_here ! Could be a sun4e.
432 nop
433 b no_sun4u_here ! AIEEE, a V9 sun4u... Get our BIG BROTHER kernel :))
434 nop
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436/* CPUID in bootbus can be found at PA 0xff0140000 */
437#define SUN4D_BOOTBUS_CPUID 0xf0140000
438
439sun4d_init:
440 /* Need to patch call to handler_irq */
441 set patch_handler_irq, %g4
442 set sun4d_handler_irq, %g5
443 sethi %hi(0x40000000), %g3 ! call
444 sub %g5, %g4, %g5
445 srl %g5, 2, %g5
446 or %g5, %g3, %g5
447 st %g5, [%g4]
448
449#ifdef CONFIG_SMP
450 /* Get our CPU id out of bootbus */
451 set SUN4D_BOOTBUS_CPUID, %g3
452 lduba [%g3] ASI_M_CTL, %g3
453 and %g3, 0xf8, %g3
454 srl %g3, 3, %g4
455 sta %g4, [%g0] ASI_M_VIKING_TMP1
456 sethi %hi(boot_cpu_id), %g5
457 stb %g4, [%g5 + %lo(boot_cpu_id)]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#endif
459
460 /* Fall through to sun4m_init */
461
462sun4m_init:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463/* Ok, the PROM could have done funny things and apple cider could still
464 * be sitting in the fault status/address registers. Read them all to
465 * clear them so we don't get magic faults later on.
466 */
467/* This sucks, apparently this makes Vikings call prom panic, will fix later */
4682:
469 rd %psr, %o1
470 srl %o1, 28, %o1 ! Get a type of the CPU
471
472 subcc %o1, 4, %g0 ! TI: Viking or MicroSPARC
Sam Ravnborg323206a2012-05-11 11:35:15 +0000473 be continue_boot
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 nop
475
476 set AC_M_SFSR, %o0
477 lda [%o0] ASI_M_MMUREGS, %g0
478 set AC_M_SFAR, %o0
479 lda [%o0] ASI_M_MMUREGS, %g0
480
481 /* Fujitsu MicroSPARC-II has no asynchronous flavors of FARs */
482 subcc %o1, 0, %g0
Sam Ravnborg323206a2012-05-11 11:35:15 +0000483 be continue_boot
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 nop
485
486 set AC_M_AFSR, %o0
487 lda [%o0] ASI_M_MMUREGS, %g0
488 set AC_M_AFAR, %o0
489 lda [%o0] ASI_M_MMUREGS, %g0
490 nop
491
492
Sam Ravnborg323206a2012-05-11 11:35:15 +0000493continue_boot:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495/* Aieee, now set PC and nPC, enable traps, give ourselves a stack and it's
496 * show-time!
497 */
498
499 sethi %hi(cputyp), %o0
500 st %g4, [%o0 + %lo(cputyp)]
501
502 /* Turn on Supervisor, EnableFloating, and all the PIL bits.
503 * Also puts us in register window zero with traps off.
504 */
505 set (PSR_PS | PSR_S | PSR_PIL | PSR_EF), %g2
506 wr %g2, 0x0, %psr
507 WRITE_PAUSE
508
509 /* I want a kernel stack NOW! */
510 set init_thread_union, %g1
511 set (THREAD_SIZE - STACKFRAME_SZ), %g2
512 add %g1, %g2, %sp
513 mov 0, %fp /* And for good luck */
514
515 /* Zero out our BSS section. */
516 set __bss_start , %o0 ! First address of BSS
Sam Ravnborg86ed40b2008-12-27 00:35:12 -0800517 set _end , %o1 ! Last address of BSS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 add %o0, 0x1, %o0
Sam Ravnborgec241582012-05-25 21:20:05 +00005191:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 stb %g0, [%o0]
521 subcc %o0, %o1, %g0
522 bl 1b
523 add %o0, 0x1, %o0
524
Daniel Hellstrom5fcafb72011-04-21 04:20:23 +0000525 /* If boot_cpu_id has not been setup by machine specific
526 * init-code above we default it to zero.
527 */
528 sethi %hi(boot_cpu_id), %g2
529 ldub [%g2 + %lo(boot_cpu_id)], %g3
530 cmp %g3, 0xff
531 bne 1f
532 nop
533 mov %g0, %g3
534 stub %g3, [%g2 + %lo(boot_cpu_id)]
535
David S. Miller837ebf02012-05-19 21:40:50 -07005361: sll %g3, 2, %g3
Daniel Hellstrom5fcafb72011-04-21 04:20:23 +0000537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 /* Initialize the uwinmask value for init task just in case.
539 * But first make current_set[boot_cpu_id] point to something useful.
540 */
541 set init_thread_union, %g6
542 set current_set, %g2
543#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 st %g6, [%g2]
545 add %g2, %g3, %g2
546#endif
547 st %g6, [%g2]
548
549 st %g0, [%g6 + TI_UWINMASK]
550
551/* Compute NWINDOWS and stash it away. Now uses %wim trick explained
552 * in the V8 manual. Ok, this method seems to work, Sparc is cool...
553 * No, it doesn't work, have to play the save/readCWP/restore trick.
554 */
555
556 wr %g0, 0x0, %wim ! so we do not get a trap
557 WRITE_PAUSE
558
559 save
560
561 rd %psr, %g3
562
563 restore
564
565 and %g3, 0x1f, %g3
566 add %g3, 0x1, %g3
567
568 mov 2, %g1
569 wr %g1, 0x0, %wim ! make window 1 invalid
570 WRITE_PAUSE
571
572 cmp %g3, 0x7
573 bne 2f
574 nop
575
576 /* Adjust our window handling routines to
577 * do things correctly on 7 window Sparcs.
578 */
579
580#define PATCH_INSN(src, dest) \
581 set src, %g5; \
582 set dest, %g2; \
583 ld [%g5], %g4; \
584 st %g4, [%g2];
Sam Ravnborgec241582012-05-25 21:20:05 +0000585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 /* Patch for window spills... */
587 PATCH_INSN(spnwin_patch1_7win, spnwin_patch1)
588 PATCH_INSN(spnwin_patch2_7win, spnwin_patch2)
589 PATCH_INSN(spnwin_patch3_7win, spnwin_patch3)
590
591 /* Patch for window fills... */
592 PATCH_INSN(fnwin_patch1_7win, fnwin_patch1)
593 PATCH_INSN(fnwin_patch2_7win, fnwin_patch2)
594
595 /* Patch for trap entry setup... */
596 PATCH_INSN(tsetup_7win_patch1, tsetup_patch1)
597 PATCH_INSN(tsetup_7win_patch2, tsetup_patch2)
598 PATCH_INSN(tsetup_7win_patch3, tsetup_patch3)
599 PATCH_INSN(tsetup_7win_patch4, tsetup_patch4)
600 PATCH_INSN(tsetup_7win_patch5, tsetup_patch5)
601 PATCH_INSN(tsetup_7win_patch6, tsetup_patch6)
602
603 /* Patch for returning from traps... */
604 PATCH_INSN(rtrap_7win_patch1, rtrap_patch1)
605 PATCH_INSN(rtrap_7win_patch2, rtrap_patch2)
606 PATCH_INSN(rtrap_7win_patch3, rtrap_patch3)
607 PATCH_INSN(rtrap_7win_patch4, rtrap_patch4)
608 PATCH_INSN(rtrap_7win_patch5, rtrap_patch5)
609
610 /* Patch for killing user windows from the register file. */
611 PATCH_INSN(kuw_patch1_7win, kuw_patch1)
612
613 /* Now patch the kernel window flush sequences.
614 * This saves 2 traps on every switch and fork.
615 */
616 set 0x01000000, %g4
617 set flush_patch_one, %g5
618 st %g4, [%g5 + 0x18]
619 st %g4, [%g5 + 0x1c]
620 set flush_patch_two, %g5
621 st %g4, [%g5 + 0x18]
622 st %g4, [%g5 + 0x1c]
623 set flush_patch_three, %g5
624 st %g4, [%g5 + 0x18]
625 st %g4, [%g5 + 0x1c]
626 set flush_patch_four, %g5
627 st %g4, [%g5 + 0x18]
628 st %g4, [%g5 + 0x1c]
629 set flush_patch_exception, %g5
630 st %g4, [%g5 + 0x18]
631 st %g4, [%g5 + 0x1c]
632 set flush_patch_switch, %g5
633 st %g4, [%g5 + 0x18]
634 st %g4, [%g5 + 0x1c]
635
Sam Ravnborgec241582012-05-25 21:20:05 +00006362:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 sethi %hi(nwindows), %g4
638 st %g3, [%g4 + %lo(nwindows)] ! store final value
639 sub %g3, 0x1, %g3
640 sethi %hi(nwindowsm1), %g4
641 st %g3, [%g4 + %lo(nwindowsm1)]
642
643 /* Here we go, start using Linux's trap table... */
644 set trapbase, %g3
645 wr %g3, 0x0, %tbr
646 WRITE_PAUSE
647
648 /* Finally, turn on traps so that we can call c-code. */
649 rd %psr, %g3
650 wr %g3, 0x0, %psr
651 WRITE_PAUSE
652
653 wr %g3, PSR_ET, %psr
654 WRITE_PAUSE
655
656 /* First we call prom_init() to set up PROMLIB, then
657 * off to start_kernel().
658 */
659
660 sethi %hi(prom_vector_p), %g5
661 ld [%g5 + %lo(prom_vector_p)], %o0
662 call prom_init
663 nop
664
Sam Ravnborgec241582012-05-25 21:20:05 +0000665 call start_kernel
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 nop
Sam Ravnborgec241582012-05-25 21:20:05 +0000667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 /* We should not get here. */
669 call halt_me
670 nop
Adrian Bunk5110bd22008-08-31 20:59:37 -0700671
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672no_sun4e_here:
673 ld [%g7 + 0x68], %o1
674 set sun4e_notsup, %o0
675 call %o1
676 nop
677 b halt_me
678 nop
679
680 __INITDATA
681
682sun4u_1:
683 .asciz "finddevice"
684 .align 4
685sun4u_2:
686 .asciz "/chosen"
687 .align 4
688sun4u_3:
689 .asciz "getprop"
690 .align 4
691sun4u_4:
692 .asciz "stdout"
693 .align 4
694sun4u_5:
695 .asciz "write"
696 .align 4
697sun4u_6:
Sam Ravnborgec241582012-05-25 21:20:05 +0000698 .asciz "\n\rOn sun4u you have to use sparc64 kernel\n\rand not a sparc32 version\n\r\n\r"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699sun4u_6e:
700 .align 4
701sun4u_7:
702 .asciz "exit"
703 .align 8
704sun4u_a1:
705 .word 0, sun4u_1, 0, 1, 0, 1, 0, sun4u_2, 0
706sun4u_r1:
707 .word 0
708sun4u_a2:
709 .word 0, sun4u_3, 0, 4, 0, 1, 0
710sun4u_i2:
711 .word 0, 0, sun4u_4, 0, sun4u_1, 0, 8, 0
712sun4u_r2:
713 .word 0
714sun4u_a3:
715 .word 0, sun4u_5, 0, 3, 0, 1, 0
716sun4u_i3:
717 .word 0, 0, sun4u_6, 0, sun4u_6e - sun4u_6 - 1, 0
718sun4u_r3:
719 .word 0
720sun4u_a4:
721 .word 0, sun4u_7, 0, 0, 0, 0
722sun4u_r4:
723
724 __INIT
725no_sun4u_here:
726 set sun4u_a1, %o0
727 set current_pc, %l2
728 cmp %l2, %g3
729 be 1f
730 mov %o4, %l0
731 sub %g3, %l2, %l6
732 add %o0, %l6, %o0
733 mov %o0, %l4
734 mov sun4u_r4 - sun4u_a1, %l3
735 ld [%l4], %l5
7362:
737 add %l4, 4, %l4
738 cmp %l5, %l2
739 add %l5, %l6, %l5
740 bgeu,a 3f
741 st %l5, [%l4 - 4]
7423:
743 subcc %l3, 4, %l3
744 bne 2b
745 ld [%l4], %l5
7461:
747 call %l0
748 mov %o0, %l1
749
750 ld [%l1 + (sun4u_r1 - sun4u_a1)], %o1
751 add %l1, (sun4u_a2 - sun4u_a1), %o0
752 call %l0
753 st %o1, [%o0 + (sun4u_i2 - sun4u_a2)]
754
755 ld [%l1 + (sun4u_1 - sun4u_a1)], %o1
756 add %l1, (sun4u_a3 - sun4u_a1), %o0
757 call %l0
758 st %o1, [%o0 + (sun4u_i3 - sun4u_a3)]
759
760 call %l0
761 add %l1, (sun4u_a4 - sun4u_a1), %o0
762
763 /* Not reached */
764halt_me:
765 ld [%g7 + 0x74], %o0
766 call %o0 ! Get us out of here...
767 nop ! Apparently Solaris is better.
768
769/* Ok, now we continue in the .data/.text sections */
770
771 .data
772 .align 4
773
774/*
775 * Fill up the prom vector, note in particular the kind first element,
776 * no joke. I don't need all of them in here as the entire prom vector
777 * gets initialized in c-code so all routines can use it.
778 */
779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780prom_vector_p:
781 .word 0
782
783/* We calculate the following at boot time, window fills/spills and trap entry
784 * code uses these to keep track of the register windows.
785 */
786
787 .align 4
788 .globl nwindows
789 .globl nwindowsm1
790nwindows:
791 .word 8
792nwindowsm1:
793 .word 7
794
795/* Boot time debugger vector value. We need this later on. */
796
797 .align 4
798 .globl linux_dbvec
799linux_dbvec:
800 .word 0
801 .word 0
802
803 .align 8
804
805 .globl lvl14_save
806lvl14_save:
807 .word 0
808 .word 0
809 .word 0
810 .word 0
811 .word t_irq14
812
813 .section ".fixup",#alloc,#execinstr
814 .globl __ret_efault
815__ret_efault:
816 ret
817 restore %g0, -EFAULT, %o0