1 /* $NetBSD: ibm4xx_machdep.c,v 1.11 2009/11/26 00:19:20 matt Exp $ */
2 /* Original: ibm40x_machdep.c,v 1.3 2005/01/17 17:19:36 shige Exp $ */
5 * Copyright 2001, 2002 Wasabi Systems, Inc.
8 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed for the NetBSD Project by
21 * Wasabi Systems, Inc.
22 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior
26 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
40 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
41 * Copyright (C) 1995, 1996 TooLs GmbH.
42 * All rights reserved.
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by TooLs GmbH.
55 * 4. The name of TooLs GmbH may not be used to endorse or promote products
56 * derived from this software without specific prior written permission.
58 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
63 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
64 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
65 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
66 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
67 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
70 #include <sys/cdefs.h>
71 __KERNEL_RCSID(0, "$NetBSD: ibm4xx_machdep.c,v 1.11 2009/11/26 00:19:20 matt Exp $");
73 #include "opt_compat_netbsd.h"
76 #include "opt_ipkdb.h"
78 #include <sys/param.h>
79 #include <sys/msgbuf.h>
82 #include <uvm/uvm_extern.h>
85 #include <machine/db_machdep.h>
86 #include <ddb/db_extern.h>
94 #include <ipkdb/ipkdb.h>
97 #include <machine/powerpc.h>
98 #include <powerpc/spr.h>
99 #include <machine/trap.h>
102 * Global variables used here and there
104 paddr_t msgbuf_paddr
;
105 vaddr_t msgbuf_vaddr
;
106 char msgbuf
[MSGBUFSIZE
];
112 ibm4xx_init(void (*handler
)(void))
114 extern int defaulttrap
, defaultsize
;
115 extern int sctrap
, scsize
;
116 extern int alitrap
, alisize
;
117 extern int dsitrap
, dsisize
;
118 extern int isitrap
, isisize
;
119 extern int mchktrap
, mchksize
;
120 extern int tlbimiss4xx
, tlbim4size
;
121 extern int tlbdmiss4xx
, tlbdm4size
;
122 extern int pitfitwdog
, pitfitwdogsize
;
123 extern int debugtrap
, debugsize
;
124 extern int errata51handler
, errata51size
;
126 extern int ddblow
, ddbsize
;
129 extern int ipkdblow
, ipkdbsize
;
132 struct cpu_info
* const ci
= curcpu();
134 /* Initialize cache info for memcpy, etc. */
138 * Initialize lwp0 and current pcb and pmap pointers.
141 KASSERT(curcpu() == ci
);
144 curpcb
= lwp_getpcb(&lwp0
);
145 memset(curpcb
, 0, sizeof(struct pcb
));
147 curpcb
->pcb_pm
= pmap_kernel();
150 * Set up trap vectors
152 for (exc
= EXC_RSVD
; exc
<= EXC_LAST
; exc
+= 0x100)
155 memcpy((void *)exc
, &defaulttrap
, (size_t)&defaultsize
);
159 * This one is (potentially) installed during autoconf
163 memcpy((void *)EXC_SC
, &sctrap
, (size_t)&scsize
);
166 memcpy((void *)EXC_ALI
, &alitrap
, (size_t)&alisize
);
169 memcpy((void *)EXC_DSI
, &dsitrap
, (size_t)&dsisize
);
172 memcpy((void *)EXC_ISI
, &isitrap
, (size_t)&isisize
);
175 memcpy((void *)EXC_MCHK
, &mchktrap
, (size_t)&mchksize
);
178 memcpy((void *)EXC_ITMISS
, &tlbimiss4xx
,
179 (size_t)&tlbim4size
);
182 memcpy((void *)EXC_DTMISS
, &tlbdmiss4xx
,
183 (size_t)&tlbdm4size
);
186 * EXC_PIT, EXC_FIT, EXC_WDOG handlers
187 * are spaced by 0x10 bytes only..
190 memcpy((void *)EXC_PIT
, &pitfitwdog
,
191 (size_t)&pitfitwdogsize
);
194 memcpy((void *)EXC_DEBUG
, &debugtrap
,
197 case EXC_DTMISS
|EXC_ALI
:
198 /* PPC405GP Rev D errata item 51 */
199 memcpy((void *)(EXC_DTMISS
|EXC_ALI
), &errata51handler
,
200 (size_t)&errata51size
);
202 #if defined(DDB) || defined(IPKDB)
205 memcpy((void *)exc
, &ddblow
, (size_t)&ddbsize
);
207 memcpy((void *)exc
, &ipkdblow
, (size_t)&ipkdbsize
);
209 #endif /* DDB | IPKDB */
213 __syncicache((void *)EXC_RST
, EXC_LAST
- EXC_RST
+ 0x100);
214 mtspr(SPR_EVPR
, 0); /* Set Exception vector base */
218 /* Handle trap instruction as PGM exception */
221 __asm
volatile("mfspr %0,%1":"=r"(dbcr0
):"K"(SPR_DBCR0
));
222 __asm
volatile("mtspr %0,%1"::"K"(SPR_DBCR0
),"r"(dbcr0
& ~DBCR0_TDE
));
226 * external interrupt handler install
229 ibm4xx_install_extint(handler
);
232 * Now enable translation (and machine checks/recoverable interrupts).
234 __asm
volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
235 : : "r"(0), "K"(PSL_IR
|PSL_DR
));
236 /* XXXX PSL_ME - With ME set kernel gets stuck... */
238 KASSERT(curcpu() == ci
);
242 ibm4xx_install_extint(void (*handler
)(void))
244 extern int extint
, extsize
;
245 extern u_long extint_call
;
246 u_long offset
= (u_long
)handler
- (u_long
)&extint_call
;
250 if (offset
> 0x1ffffff)
251 panic("install_extint: too far away");
253 __asm
volatile ("mfmsr %0; wrteei 0" : "=r"(msr
));
254 extint_call
= (extint_call
& 0xfc000003) | offset
;
255 memcpy((void *)EXC_EXI
, &extint
, (size_t)&extsize
);
256 __syncicache((void *)&extint_call
, sizeof extint_call
);
257 __syncicache((void *)EXC_EXI
, (int)&extsize
);
258 __asm
volatile ("mtmsr %0" :: "r"(msr
));
262 * ibm4xx_cpu_startup:
263 * Machine dependent startup code.
266 ibm4xx_cpu_startup(const char *model
)
268 vaddr_t minaddr
, maxaddr
;
271 KASSERT(curcpu() != NULL
);
272 KASSERT(lwp0
.l_cpu
!= NULL
);
273 KASSERT(curcpu()->ci_intstk
!= 0);
274 KASSERT(curcpu()->ci_intrdepth
== -1);
277 * Initialize error message buffer (at end of core).
279 #if 0 /* For some reason this fails... --Artem
280 * Besides, do we really have to put it at the end of core?
281 * Let's use static buffer for now
283 if (!(msgbuf_vaddr
= uvm_km_alloc(kernel_map
, round_page(MSGBUFSIZE
),
285 panic("startup: no room for message buffer");
286 for (i
= 0; i
< btoc(MSGBUFSIZE
); i
++)
287 pmap_kenter_pa(msgbuf_vaddr
+ i
* PAGE_SIZE
,
288 msgbuf_paddr
+ i
* PAGE_SIZE
,
289 VM_PROT_READ
|VM_PROT_WRITE
, 0);
290 initmsgbuf((void *)msgbuf_vaddr
, round_page(MSGBUFSIZE
));
292 initmsgbuf((void *)msgbuf
, round_page(MSGBUFSIZE
));
295 printf("%s%s", copyright
, version
);
297 printf("Model: %s\n", model
);
299 format_bytes(pbuf
, sizeof(pbuf
), ctob(physmem
));
300 printf("total memory = %s\n", pbuf
);
304 * Allocate a submap for physio
306 phys_map
= uvm_km_suballoc(kernel_map
, &minaddr
, &maxaddr
,
307 VM_PHYS_SIZE
, 0, false, NULL
);
310 * No need to allocate an mbuf cluster submap. Mbuf clusters
311 * are allocated via the pool allocator, and we use direct-mapped
315 format_bytes(pbuf
, sizeof(pbuf
), ptoa(uvmexp
.free
));
316 printf("avail memory = %s\n", pbuf
);
321 * Crash dump handling.
327 printf("dumpsys: TBD\n");