srt0.S revision 1.1.2.2 1 1.1.2.2 nathanw /* $NetBSD: srt0.S,v 1.1.2.2 2002/02/28 04:11:12 nathanw Exp $ */
2 1.1.2.2 nathanw
3 1.1.2.2 nathanw /*-
4 1.1.2.2 nathanw * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.1.2.2 nathanw * All rights reserved.
6 1.1.2.2 nathanw *
7 1.1.2.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 nathanw * by Steve C. Woodford.
9 1.1.2.2 nathanw *
10 1.1.2.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 nathanw * modification, are permitted provided that the following conditions
12 1.1.2.2 nathanw * are met:
13 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.1.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 nathanw * must display the following acknowledgement:
20 1.1.2.2 nathanw * This product includes software developed by the NetBSD
21 1.1.2.2 nathanw * Foundation, Inc. and its contributors.
22 1.1.2.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.2 nathanw * contributors may be used to endorse or promote products derived
24 1.1.2.2 nathanw * from this software without specific prior written permission.
25 1.1.2.2 nathanw *
26 1.1.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.2 nathanw */
38 1.1.2.2 nathanw
39 1.1.2.2 nathanw #include <machine/asm.h>
40 1.1.2.2 nathanw #include <machine/psl.h>
41 1.1.2.2 nathanw #include <powerpc/spr.h>
42 1.1.2.2 nathanw
43 1.1.2.2 nathanw #define STACK_SIZE 8192
44 1.1.2.2 nathanw
45 1.1.2.2 nathanw /*
46 1.1.2.2 nathanw * The main entry point when loaded by PPC-Bug.
47 1.1.2.2 nathanw *
48 1.1.2.2 nathanw * There are two possible entry conditions here:
49 1.1.2.2 nathanw *
50 1.1.2.2 nathanw * 1) We were booted in `PReP' mode, either from disk or the network.
51 1.1.2.2 nathanw * In this case, we have no control over the load address so we
52 1.1.2.2 nathanw * have to relocate ourselves to the appropriate place.
53 1.1.2.2 nathanw * The firmware passes us the following registers:
54 1.1.2.2 nathanw *
55 1.1.2.2 nathanw * r1 -> Temporary stack
56 1.1.2.2 nathanw * r3 -> Residual Data
57 1.1.2.2 nathanw * r4 -> The address we were loaded to
58 1.1.2.2 nathanw * r5 -> Zero
59 1.1.2.2 nathanw *
60 1.1.2.2 nathanw * 2) We were booted over the network in Non-PReP mode. In this case,
61 1.1.2.2 nathanw * the load address is usually set using PPC-Bug's "niot" command,
62 1.1.2.2 nathanw * but we won't depend on it so relocation may be required. The
63 1.1.2.2 nathanw * firmware passes us the following registers:
64 1.1.2.2 nathanw *
65 1.1.2.2 nathanw * r1 -> Temporary stack
66 1.1.2.2 nathanw * r3 -> CLUN of the network device we booted from
67 1.1.2.2 nathanw * r4 -> DLUN of the network device we booted from
68 1.1.2.2 nathanw * r5 -> Non-zero
69 1.1.2.2 nathanw * r6 -> Base address of network device
70 1.1.2.2 nathanw * r7 -> Execution address of loaded program
71 1.1.2.2 nathanw * r8 -> Address of IP-address data structure
72 1.1.2.2 nathanw * r9 -> Pointer to start of filename string
73 1.1.2.2 nathanw * r10 -> Pointer to end+1 of filename string
74 1.1.2.2 nathanw * r11 -> Pointer to start of argument string
75 1.1.2.2 nathanw * r12 -> Pointer to end+1 of argument string
76 1.1.2.2 nathanw *
77 1.1.2.2 nathanw * The obvious way to distinguish between the two boot modes is by
78 1.1.2.2 nathanw * checking the value of r5.
79 1.1.2.2 nathanw */
80 1.1.2.2 nathanw ENTRY(_start)
81 1.1.2.2 nathanw bl 1f
82 1.1.2.2 nathanw 1: xor r0,r0,r0
83 1.1.2.2 nathanw
84 1.1.2.2 nathanw /* First, switch off Instruction and Data caches. */
85 1.1.2.2 nathanw mfspr r13,SPR_HID0
86 1.1.2.2 nathanw LDCONST(r14, HID0_DCE|HID0_ICE)
87 1.1.2.2 nathanw andc r13,r13,r14
88 1.1.2.2 nathanw sync
89 1.1.2.2 nathanw mtspr SPR_HID0,r13
90 1.1.2.2 nathanw
91 1.1.2.2 nathanw
92 1.1.2.2 nathanw /*
93 1.1.2.2 nathanw * All registers now available. Let's see if we need to relocate
94 1.1.2.2 nathanw */
95 1.1.2.2 nathanw LDCONST(r13,_C_LABEL(_start)) /* Where we'd like to be */
96 1.1.2.2 nathanw LDCONST(r14,_C_LABEL(edata)) /* End of data section */
97 1.1.2.2 nathanw LDCONST(r15,0x3)
98 1.1.2.2 nathanw add r14,r14,r15
99 1.1.2.2 nathanw andc r14,r14,r15 /* Rounded up to the nearest 32-bits */
100 1.1.2.2 nathanw sub r15,r14,r13 /* Our size, in bytes */
101 1.1.2.2 nathanw mflr r16 /* Get address we were loaded to */
102 1.1.2.2 nathanw subi r16,r16,0x4 /* Correct for branch */
103 1.1.2.2 nathanw cmp cr0,r13,r16 /* Do we need to relocate? */
104 1.1.2.2 nathanw beq _ASM_LABEL(clrbss) /* No relocation necessary */
105 1.1.2.2 nathanw li r17,0x4
106 1.1.2.2 nathanw bgt 1f /* Relocate using forward copy? */
107 1.1.2.2 nathanw
108 1.1.2.2 nathanw /* Nope. Need to copy in reverse in case of overlap */
109 1.1.2.2 nathanw mr r13,r14 /* dest -> end */
110 1.1.2.2 nathanw add r16,r16,r15 /* src + size */
111 1.1.2.2 nathanw subi r17,r17,0x8 /* Increment is -4 */
112 1.1.2.2 nathanw
113 1.1.2.2 nathanw /*
114 1.1.2.2 nathanw * Do the relocation
115 1.1.2.2 nathanw * r13 -> dest
116 1.1.2.2 nathanw * r15 -> number of bytes
117 1.1.2.2 nathanw * r16 -> src
118 1.1.2.2 nathanw * r17 -> Increment (+4 or -4)
119 1.1.2.2 nathanw */
120 1.1.2.2 nathanw 1: srwi r15,r15,0x2 /* Convert length to 32-bit words */
121 1.1.2.2 nathanw mtctr r15 /* Save in counter register */
122 1.1.2.2 nathanw
123 1.1.2.2 nathanw 2: lwz r15,0(r16)
124 1.1.2.2 nathanw stw r15,0(r13)
125 1.1.2.2 nathanw add r16,r16,r17
126 1.1.2.2 nathanw add r13,r13,r17
127 1.1.2.2 nathanw bdnz 2b
128 1.1.2.2 nathanw
129 1.1.2.2 nathanw /* Now do an absolute jump to the relocated code */
130 1.1.2.2 nathanw LDCONST(r13,_ASM_LABEL(clrbss))
131 1.1.2.2 nathanw mtlr r13
132 1.1.2.2 nathanw blr
133 1.1.2.2 nathanw
134 1.1.2.2 nathanw ASENTRY(clrbss)
135 1.1.2.2 nathanw LDCONST(r13,_C_LABEL(edata)) /* End of the data section */
136 1.1.2.2 nathanw LDCONST(r14,_C_LABEL(end)) /* End of BSS */
137 1.1.2.2 nathanw LDCONST(r15,0x3)
138 1.1.2.2 nathanw add r14,r14,r15
139 1.1.2.2 nathanw andc r14,r14,r15 /* Round-up end of BSS to 32-bits */
140 1.1.2.2 nathanw sub r15,r14,r13 /* r15 == length of BSS */
141 1.1.2.2 nathanw srwi r15,r15,0x2
142 1.1.2.2 nathanw mtctr r15 /* CTR == # of 32-bit words in BSS */
143 1.1.2.2 nathanw 1: stw r0,0(r13) /* Clear BSS */
144 1.1.2.2 nathanw addi r13,r13,4
145 1.1.2.2 nathanw bdnz 1b
146 1.1.2.2 nathanw
147 1.1.2.2 nathanw /* Fix up our own stack */
148 1.1.2.2 nathanw LDCONST(r1,stack)
149 1.1.2.2 nathanw addi r1,r1,STACK_SIZE-0x10
150 1.1.2.2 nathanw LDCONST(r13,0x0f)
151 1.1.2.2 nathanw andc r1,r1,r13
152 1.1.2.2 nathanw
153 1.1.2.2 nathanw /*
154 1.1.2.2 nathanw * Copy the arguments passed in from Bug into bug_bootinfo
155 1.1.2.2 nathanw *
156 1.1.2.2 nathanw * See bugsyscalls.h for details.
157 1.1.2.2 nathanw */
158 1.1.2.2 nathanw LDCONST(r13,_C_LABEL(bug_bootinfo))
159 1.1.2.2 nathanw stw r5,0x00(r13)
160 1.1.2.2 nathanw stw r3,0x04(r13)
161 1.1.2.2 nathanw stw r4,0x08(r13)
162 1.1.2.2 nathanw stw r6,0x0c(r13)
163 1.1.2.2 nathanw stw r7,0x10(r13)
164 1.1.2.2 nathanw stw r8,0x14(r13)
165 1.1.2.2 nathanw stw r9,0x18(r13)
166 1.1.2.2 nathanw stw r10,0x1c(r13)
167 1.1.2.2 nathanw stw r11,0x20(r13)
168 1.1.2.2 nathanw stw r12,0x24(r13)
169 1.1.2.2 nathanw
170 1.1.2.2 nathanw mr r3,r13
171 1.1.2.2 nathanw bl _C_LABEL(main) /* void main(void) */
172 1.1.2.2 nathanw /* FALLTHROUGH */
173 1.1.2.2 nathanw
174 1.1.2.2 nathanw /*
175 1.1.2.2 nathanw * Return to the debugger, either because main() returned or via panic().
176 1.1.2.2 nathanw */
177 1.1.2.2 nathanw ENTRY(_rtt)
178 1.1.2.2 nathanw addi r10,0,0x0063
179 1.1.2.2 nathanw sc
180 1.1.2.2 nathanw 1: nop
181 1.1.2.2 nathanw b 1b
182 1.1.2.2 nathanw
183 1.1.2.2 nathanw /*
184 1.1.2.2 nathanw * C code runs on this stack.
185 1.1.2.2 nathanw */
186 1.1.2.2 nathanw .comm stack,STACK_SIZE,4
187 1.1.2.2 nathanw .comm errno,4,4
188 1.1.2.2 nathanw .comm debug,4,4
189