2 * Copyright (C) 2010 Nathan Whitehorn
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <machine/trap.h>
33 * KBoot and simulators will start this program from the _start symbol, with
34 * r3 pointing to a flattened device tree (kexec), r4 the physical address
35 * at which we were loaded, and r5 0 (kexec) or a pointer to Open Firmware
36 * (simulator). If r4 is non-zero, the first order of business is relocating
37 * ourselves to 0. In the kboot case, the PPE secondary thread will enter
40 * If started directly by the LV1 hypervisor, we are loaded to address 0
41 * and execution on both threads begins at 0x100 (EXC_RST).
44 #define CACHELINE_SIZE 128
47 /* KBoot thread 0 entry -- do relocation, then jump to main */
61 .global secondary_spin_sem
72 ba thread1_start /* kboot copies the first 256 bytes to
73 * address 0, so we are safe to jump
77 li %r3,secondary_spin_sem@l
78 1: lwz %r1,0(%r3) /* Spin on SECONDARY_SPIN_SEM_ADDRESS */
80 beq 1b /* If the semaphore is still zero, spin again */
82 /* We have been woken up by thread 0 */
83 li %r0,0x100 /* Invalidate reset vector cache line */
87 ba 0x100 /* Jump to the reset vector */
97 /* The first two bits of r0 are 01 (thread 1) or 10 (thread 0) */
98 cntlzw %r3,%r3 /* Now 0 for thread 0, 1 for thread 1 */
101 bne thread1_start /* Send thread 1 to wait */
103 b relocated_start /* Main entry point for thread 0 */
105 #define EXCEPTION_HANDLER(exc) \
116 EXCEPTION_HANDLER(EXC_MCHK)
117 EXCEPTION_HANDLER(EXC_DSI)
118 EXCEPTION_HANDLER(EXC_DSE)
119 EXCEPTION_HANDLER(EXC_ISI)
120 EXCEPTION_HANDLER(EXC_ISE)
121 EXCEPTION_HANDLER(EXC_EXI)
122 EXCEPTION_HANDLER(EXC_ALI)
123 EXCEPTION_HANDLER(EXC_PGM)
124 EXCEPTION_HANDLER(EXC_FPU)
125 EXCEPTION_HANDLER(EXC_DECR)
126 EXCEPTION_HANDLER(EXC_SC)
129 /* We enter this with r4 the physical offset for our relocation */
130 lis %r8,_end@ha /* r8: copy length */
132 li %r5,0x100 /* r5: dest address */
133 1: add %r6,%r4,%r5 /* r6: source address */
141 * Now invalidate the cacheline with the second half of relocate_self,
142 * and do an absolute branch there in case we overwrote part of
146 lis %r9,relocate_self_cache@ha
147 addi %r9,%r9,relocate_self_cache@l
153 ba relocate_self_cache
156 /* Now invalidate the icache */
164 addi %r5,%r5,CACHELINE_SIZE
167 /* All done: absolute jump to relocated entry point */