1 /* $NetBSD: srt0.S,v 1.1 2002/02/27 21:02:27 scw Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <machine/asm.h>
33 #include <machine/psl.h>
34 #include <powerpc/spr.h>
36 #define STACK_SIZE 8192
39 * The main entry point when loaded by PPC-Bug.
41 * There are two possible entry conditions here:
43 * 1) We were booted in `PReP' mode, either from disk or the network.
44 * In this case, we have no control over the load address so we
45 * have to relocate ourselves to the appropriate place.
46 * The firmware passes us the following registers:
48 * r1 -> Temporary stack
50 * r4 -> The address we were loaded to
53 * 2) We were booted over the network in Non-PReP mode. In this case,
54 * the load address is usually set using PPC-Bug's "niot" command,
55 * but we won't depend on it so relocation may be required. The
56 * firmware passes us the following registers:
58 * r1 -> Temporary stack
59 * r3 -> CLUN of the network device we booted from
60 * r4 -> DLUN of the network device we booted from
62 * r6 -> Base address of network device
63 * r7 -> Execution address of loaded program
64 * r8 -> Address of IP-address data structure
65 * r9 -> Pointer to start of filename string
66 * r10 -> Pointer to end+1 of filename string
67 * r11 -> Pointer to start of argument string
68 * r12 -> Pointer to end+1 of argument string
70 * The obvious way to distinguish between the two boot modes is by
71 * checking the value of r5.
77 /* First, switch off Instruction and Data caches. */
79 LDCONST(r14, HID0_DCE|HID0_ICE)
86 * All registers now available. Let's see if we need to relocate
88 LDCONST(r13,_C_LABEL(_start)) /* Where we'd like to be */
89 LDCONST(r14,_C_LABEL(edata)) /* End of data section */
92 andc r14,r14,r15 /* Rounded up to the nearest 32-bits */
93 sub r15,r14,r13 /* Our size, in bytes */
94 mflr r16 /* Get address we were loaded to */
95 subi r16,r16,0x4 /* Correct for branch */
96 cmp cr0,r13,r16 /* Do we need to relocate? */
97 beq _ASM_LABEL(clrbss) /* No relocation necessary */
99 bgt 1f /* Relocate using forward copy? */
101 /* Nope. Need to copy in reverse in case of overlap */
102 mr r13,r14 /* dest -> end */
103 add r16,r16,r15 /* src + size */
104 subi r17,r17,0x8 /* Increment is -4 */
109 * r15 -> number of bytes
111 * r17 -> Increment (+4 or -4)
113 1: srwi r15,r15,0x2 /* Convert length to 32-bit words */
114 mtctr r15 /* Save in counter register */
122 /* Now do an absolute jump to the relocated code */
123 LDCONST(r13,_ASM_LABEL(clrbss))
128 LDCONST(r13,_C_LABEL(edata)) /* End of the data section */
129 LDCONST(r14,_C_LABEL(end)) /* End of BSS */
132 andc r14,r14,r15 /* Round-up end of BSS to 32-bits */
133 sub r15,r14,r13 /* r15 == length of BSS */
135 mtctr r15 /* CTR == # of 32-bit words in BSS */
136 1: stw r0,0(r13) /* Clear BSS */
140 /* Fix up our own stack */
142 addi r1,r1,STACK_SIZE-0x10
147 * Copy the arguments passed in from Bug into bug_bootinfo
149 * See bugsyscalls.h for details.
151 LDCONST(r13,_C_LABEL(bug_bootinfo))
164 bl _C_LABEL(main) /* void main(void) */
168 * Return to the debugger, either because main() returned or via panic().
177 * C code runs on this stack.
179 .comm stack,STACK_SIZE,4