virtex_start.S revision 1.6 1 1.6 kiyohara /* $NetBSD: virtex_start.S,v 1.6 2010/03/18 14:04:07 kiyohara Exp $ */
2 1.1 freza
3 1.1 freza /*
4 1.1 freza * Copyright (c) 2006 Jachym Holecek
5 1.1 freza * All rights reserved.
6 1.1 freza *
7 1.1 freza * Written for DFC Design, s.r.o.
8 1.1 freza *
9 1.1 freza * Redistribution and use in source and binary forms, with or without
10 1.1 freza * modification, are permitted provided that the following conditions
11 1.1 freza * are met:
12 1.1 freza *
13 1.1 freza * 1. Redistributions of source code must retain the above copyright
14 1.1 freza * notice, this list of conditions and the following disclaimer.
15 1.1 freza *
16 1.1 freza * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 freza * notice, this list of conditions and the following disclaimer in the
18 1.1 freza * documentation and/or other materials provided with the distribution.
19 1.1 freza *
20 1.1 freza * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 freza * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 freza * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 freza * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 freza * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 freza * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 freza * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 freza * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 freza * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 freza * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 freza */
31 1.1 freza
32 1.1 freza /*
33 1.1 freza * This file is based on startup code of Walnut and Explora boards.
34 1.1 freza */
35 1.1 freza
36 1.1 freza #define _NOREGNAMES
37 1.1 freza
38 1.1 freza #include "opt_ddb.h"
39 1.1 freza #include "opt_ipkdb.h"
40 1.1 freza #include "opt_lockdebug.h"
41 1.3 apb #include "opt_modular.h"
42 1.1 freza #include "opt_multiprocessor.h"
43 1.1 freza #include "opt_ppcarch.h"
44 1.1 freza #include "opt_ppcparam.h"
45 1.1 freza #include "opt_virtex.h"
46 1.1 freza #include "assym.h"
47 1.1 freza #include "ksyms.h"
48 1.1 freza
49 1.1 freza #include <sys/syscall.h>
50 1.1 freza
51 1.1 freza #include <machine/param.h>
52 1.1 freza #include <machine/psl.h>
53 1.1 freza #include <machine/trap.h>
54 1.1 freza #include <machine/asm.h>
55 1.1 freza
56 1.1 freza #include <powerpc/spr.h>
57 1.5 matt #include <powerpc/ibm4xx/spr.h>
58 1.6 kiyohara #include <powerpc/ibm4xx/dcr4xx.h>
59 1.1 freza #include <powerpc/ibm4xx/pmap.h>
60 1.1 freza
61 1.1 freza
62 1.1 freza /* N megabytes. */
63 1.1 freza #define MB(n) ((n)*1024*1024)
64 1.1 freza
65 1.1 freza /* Set bit (beginning with MSB) for each 128MB of RAM. */
66 1.1 freza #define PHYSMEM_REGIONS_MASK ~((1 << (32 - MB(PHYSMEM)/MB(128))) - 1)
67 1.1 freza
68 1.1 freza /* For kvm_mkdb, supposed to mark the start of kernel text. */
69 1.1 freza .text
70 1.1 freza .globl _C_LABEL(kernel_text)
71 1.1 freza _C_LABEL(kernel_text):
72 1.1 freza
73 1.1 freza /* Startup entry. This must be the first thing in the text segment! */
74 1.1 freza .text
75 1.1 freza .globl __start
76 1.1 freza __start:
77 1.1 freza /* Disable MMU/exceptions */
78 1.1 freza lis %r0, 0
79 1.1 freza mtmsr %r0
80 1.1 freza
81 1.1 freza /* Disable timers */
82 1.1 freza lis %r0, 0
83 1.1 freza mttcr %r0
84 1.1 freza
85 1.1 freza sync
86 1.1 freza isync
87 1.1 freza
88 1.1 freza /* Disable caches */
89 1.1 freza mtdccr %r0
90 1.1 freza mticcr %r0
91 1.1 freza sync
92 1.1 freza isync
93 1.1 freza
94 1.1 freza /* Invalidate I$, operands ignored on the 405 */
95 1.1 freza li %r0,0 /* just in case... */
96 1.1 freza iccci %r0,%r0
97 1.1 freza
98 1.1 freza /* Invalidate D$, hardcoded for 16KB size, 32B line */
99 1.1 freza li %r7,256 /* # of congruence classes */
100 1.1 freza mtctr %r7
101 1.1 freza li %r6,0
102 1.1 freza 1:
103 1.1 freza dccci %r0,%r6 /* invalidates both ways */
104 1.1 freza addi %r6,%r6,32
105 1.1 freza bdnz 1b
106 1.1 freza
107 1.1 freza /*
108 1.1 freza * Errata 213: Incorrect data may be flushed from the data cache.
109 1.1 freza * Cores: PPC405D5X1, PPC405D5X2
110 1.1 freza * Workaround: #1, CCR0 modification sequence #2
111 1.1 freza * Note: Meaning of bits we need to set is undocumented.
112 1.1 freza */
113 1.1 freza sync
114 1.1 freza mfccr0 %r0
115 1.1 freza oris %r0,%r0,0x50000000@h
116 1.1 freza mtccr0 %r0
117 1.1 freza isync
118 1.1 freza
119 1.1 freza /*
120 1.1 freza * Errata 58: Load string instructions may write incorrect
121 1.1 freza * data into the last GPR targeted in operation.
122 1.1 freza * Cores: PPC405GP
123 1.1 freza * Workaround: set OCM0_DSCNTL[DSEN]=0 and OCM0_DSCNTL[DOF]=0
124 1.1 freza */
125 1.1 freza mtdcr DCR_OCM0_DSCNTL,%r0 /* Disable Data access to OCM */
126 1.1 freza
127 1.1 freza #if 0
128 1.1 freza /* Allow cacheing for whole RAM. */
129 1.1 freza lis %r0,PHYSMEM_REGIONS_MASK@ha
130 1.1 freza ori %r0,%r0,PHYSMEM_REGIONS_MASK@l
131 1.1 freza #else
132 1.1 freza #ifndef PPC_4XX_NOCACHE
133 1.1 freza /* Allow cacheing for only the first 1GB of RAM */
134 1.1 freza lis %r0,0xff00
135 1.1 freza mtdccr %r0
136 1.1 freza mticcr %r0
137 1.1 freza #endif /* PPC_4XX_NOCACHE */
138 1.1 freza #endif
139 1.1 freza
140 1.1 freza /* Invalidate all TLB entries */
141 1.1 freza tlbia
142 1.1 freza sync
143 1.1 freza isync
144 1.1 freza
145 1.1 freza /* Set kernel MMU context, we'll enable MMU in initppc() */
146 1.1 freza li %r0,KERNEL_PID
147 1.1 freza mtpid %r0
148 1.1 freza sync
149 1.1 freza isync
150 1.1 freza
151 1.1 freza /* Setup endkernel argument for initppc() and INIT_CPUINFO */
152 1.1 freza lis %r4,_C_LABEL(end)@h
153 1.1 freza ori %r4,%r4,_C_LABEL(end)@l
154 1.1 freza
155 1.1 freza /* Clear .bss segment */
156 1.1 freza lis %r7,_C_LABEL(edata)-4@h
157 1.1 freza ori %r7,%r7,_C_LABEL(edata)-4@l
158 1.1 freza li %r3,0
159 1.1 freza 2: stwu %r3,4(%r7)
160 1.1 freza cmpw %r7,%r4
161 1.1 freza bne+ 2b
162 1.1 freza
163 1.2 ad #if NKSYMS || defined(DDB) || defined(MODULAR)
164 1.1 freza /* We don't have a symbol table, so set startsym = endsym = end */
165 1.1 freza lis %r7,_C_LABEL(startsym)@ha
166 1.1 freza ori %r7,%r7,_C_LABEL(startsym)@l
167 1.1 freza stw %r4,0(%r7)
168 1.1 freza lis %r7,_C_LABEL(endsym)@ha
169 1.1 freza ori %r7,%r7,_C_LABEL(endsym)@l
170 1.1 freza stw %r4,0(%r7)
171 1.1 freza #endif
172 1.1 freza
173 1.1 freza /* INIT_CPUINFO will 'addi', so clean up. */
174 1.1 freza lis %r1,0
175 1.1 freza
176 1.1 freza INIT_CPUINFO(4,1,9,0)
177 1.1 freza
178 1.1 freza /* startkernel argument for initppc */
179 1.1 freza lis %r3,__start@h
180 1.1 freza addi %r3,%r3,__start@l
181 1.1 freza
182 1.1 freza bl _C_LABEL(initppc)
183 1.1 freza bl _C_LABEL(main)
184 1.1 freza
185 1.1 freza loop: /* UNREACHED */
186 1.1 freza b loop
187 1.1 freza
188 1.1 freza #include <powerpc/ibm4xx/4xx_locore.S>
189