xref: /netbsd/sys/arch/evbppc/mpc85xx/mpc85xx_start.S (revision 361e68bb)
1*361e68bbSmaxv/*	$NetBSD: mpc85xx_start.S,v 1.10 2018/07/15 05:16:42 maxv Exp $	*/
24c283b4cSmatt/*-
34c283b4cSmatt * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
44c283b4cSmatt * All rights reserved.
54c283b4cSmatt *
64c283b4cSmatt * This code is derived from software contributed to The NetBSD Foundation
74c283b4cSmatt * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
84c283b4cSmatt * Agency and which was developed by Matt Thomas of 3am Software Foundry.
94c283b4cSmatt *
104c283b4cSmatt * This material is based upon work supported by the Defense Advanced Research
114c283b4cSmatt * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
124c283b4cSmatt * Contract No. N66001-09-C-2073.
134c283b4cSmatt * Approved for Public Release, Distribution Unlimited
144c283b4cSmatt *
154c283b4cSmatt * Redistribution and use in source and binary forms, with or without
164c283b4cSmatt * modification, are permitted provided that the following conditions
174c283b4cSmatt * are met:
184c283b4cSmatt * 1. Redistributions of source code must retain the above copyright
194c283b4cSmatt *    notice, this list of conditions and the following disclaimer.
204c283b4cSmatt * 2. Redistributions in binary form must reproduce the above copyright
214c283b4cSmatt *    notice, this list of conditions and the following disclaimer in the
224c283b4cSmatt *    documentation and/or other materials provided with the distribution.
234c283b4cSmatt *
244c283b4cSmatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
254c283b4cSmatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
264c283b4cSmatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
274c283b4cSmatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
284c283b4cSmatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
294c283b4cSmatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
304c283b4cSmatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
314c283b4cSmatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
324c283b4cSmatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
334c283b4cSmatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
344c283b4cSmatt * POSSIBILITY OF SUCH DAMAGE.
354c283b4cSmatt */
364c283b4cSmatt
374c283b4cSmatt#include <sys/cdefs.h>
384c283b4cSmatt#include <powerpc/asm.h>
394c283b4cSmatt
40*361e68bbSmaxvRCSID("$NetBSD: mpc85xx_start.S,v 1.10 2018/07/15 05:16:42 maxv Exp $")
414c283b4cSmatt
424c283b4cSmatt#include "opt_altivec.h"
434c283b4cSmatt#include "opt_ddb.h"
444c283b4cSmatt#include "opt_lockdebug.h"
454c283b4cSmatt#include "opt_modular.h"
464c283b4cSmatt#include "opt_multiprocessor.h"
474c283b4cSmatt#include "opt_ppcarch.h"
484c283b4cSmatt#include "opt_ppcparam.h"
494c283b4cSmatt
504c283b4cSmatt#include "ksyms.h"
514c283b4cSmatt
524c283b4cSmatt#include <sys/param.h>
534c283b4cSmatt
544c283b4cSmatt#include <powerpc/spr.h>
554c283b4cSmatt#include <powerpc/trap.h>
5684b283e8Smatt#include <powerpc/psl.h>
574c283b4cSmatt#include <powerpc/booke/pte.h>
584c283b4cSmatt#include <powerpc/booke/spr.h>
594c283b4cSmatt#define	LBC_PRIVATE
604c283b4cSmatt#include <powerpc/booke/e500reg.h>
614c283b4cSmatt
624c283b4cSmatt#include "assym.h"
634c283b4cSmatt
644c283b4cSmatt#define	INTSTK	0
654c283b4cSmatt
664c283b4cSmatt/*
674c283b4cSmatt * This symbol is here for the benefit of kvm_mkdb, and is supposed to
684c283b4cSmatt * mark the start of kernel text.
694c283b4cSmatt */
704c283b4cSmatt	.text
714c283b4cSmatt	.globl	_C_LABEL(kernel_text)
724c283b4cSmatt_C_LABEL(kernel_text):
734c283b4cSmatt        .globl  __start
744c283b4cSmatt__start:
754c283b4cSmatt
764c283b4cSmatt/*
774c283b4cSmatt * Startup entry.  Note, this must be the first thing in the text segment!
784c283b4cSmatt */
794a34c25dSmatt	mr	%r8,%r6		/* cmdline (char *) */
804a34c25dSmatt	mr	%r7,%r5		/* consdev (char *) */
814a34c25dSmatt	mr	%r6,%r4		/* os_hdr * */
824a34c25dSmatt	mr	%r5,%r3		/* board info * */
834c283b4cSmatt#ifdef DEBUG
844c283b4cSmatt	/*
854c283b4cSmatt	 * Set all the registers we don't care about to a known junk value.
864c283b4cSmatt	 */
8744aa6357Sjoerg	lis	%r2,0xdeadbeef@h
88ac32d478Sjoerg	ori	%r2,%r2,0xdeadbeef@l
894c283b4cSmatt	mr	%r9,%r2
904c283b4cSmatt	mr	%r10,%r9
914c283b4cSmatt	mr	%r11,%r9
924c283b4cSmatt	mr	%r12,%r9
934c283b4cSmatt	mr	%r13,%r9
944c283b4cSmatt	mr	%r14,%r9
954c283b4cSmatt	mr	%r15,%r9
964c283b4cSmatt	mr	%r16,%r9
974c283b4cSmatt	mr	%r17,%r9
984c283b4cSmatt	mr	%r18,%r9
994c283b4cSmatt	mr	%r19,%r9
1004c283b4cSmatt	mr	%r20,%r9
1014c283b4cSmatt	mr	%r21,%r9
1024c283b4cSmatt	mr	%r22,%r9
1034c283b4cSmatt	mr	%r23,%r9
1044c283b4cSmatt	mr	%r24,%r9
1054c283b4cSmatt	mr	%r25,%r9
1064c283b4cSmatt	mr	%r26,%r9
1074c283b4cSmatt	mr	%r27,%r9
1084c283b4cSmatt	mr	%r28,%r9
1094c283b4cSmatt	mr	%r29,%r9
1104c283b4cSmatt	mr	%r30,%r9
1114c283b4cSmatt	mr	%r31,%r9
1124c283b4cSmatt#endif /* DEBUG */
1134c283b4cSmatt
1144c283b4cSmatt	li	%r0,0
1154c283b4cSmatt	mtmsr	%r0			/* Disable FPU/MMU/exceptions */
1164c283b4cSmatt	isync
1174c283b4cSmatt
1184c283b4cSmatt/* get start of bss */
1194c283b4cSmatt	lis	%r15,_C_LABEL(_edata)-4@ha
1204c283b4cSmatt	addi	%r15,%r15,_C_LABEL(_edata)-4@l
1214c283b4cSmatt/* get end of kernel memory */
1224c283b4cSmatt	lis	%r16,_C_LABEL(end)@ha
1234c283b4cSmatt	addi	%r16,%r16,_C_LABEL(end)@l
1244c283b4cSmatt/* zero bss */
1254c283b4cSmatt	sub	%r17,%r16,%r15
1264c283b4cSmatt	addi	%r17,%r17,3+USPACE
12747835612Smatt	rlwinm	%r3,%r17,32-2,2,31	/* srwl	%r3,%r17,2 */
1284c283b4cSmatt	mtctr	%r3
1294c283b4cSmatt	li	%r0,0
1304c283b4cSmatt2:	stwu	%r0,4(%r15)
1314c283b4cSmatt	bdnz	2b
1324c283b4cSmatt
1334c283b4cSmatt#if NKSYMS || defined(DDB) || defined(MODULAR)
1344c283b4cSmatt	/* If we had symbol table location we'd store it here and would've adjusted r8 here */
13547835612Smatt	lis	%r17,_C_LABEL(startsym)@ha
13647835612Smatt	stw	%r18,_C_LABEL(startsym)@l(%r17)
13747835612Smatt	lis	%r17,_C_LABEL(endsym)@ha
13847835612Smatt	stw	%r18,_C_LABEL(endsym)@l(%r17)
1394c283b4cSmatt#endif
1404c283b4cSmatt
1414c283b4cSmatt	/* Set kernel MMU context. */
1424c283b4cSmatt	li	%r0,KERNEL_PID
1434c283b4cSmatt	mtpid	%r0
1444c283b4cSmatt	isync
1454c283b4cSmatt
14647835612Smatt	INIT_CPUINFO(16,1,18,17)	/* r16 has &_end */
14747835612Smatt	mr	%r4,%r16		/* remember kernelend */
14847835612Smatt	mtsprg2	%r13			/* r13 has &lwp0, put into sprg2 */
14947835612Smatt	GET_CPUINFO(%r17)
15047835612Smatt	addi	%r17,%r17,CI_SAVELIFO
15147835612Smatt	mtsprg3 %r17
15247835612Smatt	mr	%r18,%r31		/* make deadbeef again */
15347835612Smatt	mr	%r17,%r31		/* make deadbeef again */
15447835612Smatt	mr	%r16,%r31		/* make deadbeef again */
15547835612Smatt	mr	%r15,%r31		/* make deadbeef again */
1564c283b4cSmatt
1574c283b4cSmatt#if defined(GXEMUL)
1584c283b4cSmatt	/*
1594c283b4cSmatt	 * This is used to step through the external interrupt vector
1604c283b4cSmatt	 * to validate it.
1614c283b4cSmatt	 */
1624c283b4cSmatt	lis	%r29,3f@ha
1634c283b4cSmatt	addi	%r29,%r29,3f@l
1644c283b4cSmatt	mtsrr0	%r29
1654c283b4cSmatt	mfmsr	%r0
1664c283b4cSmatt	mtsrr1	%r0
1674c283b4cSmatt	lis	%r31,0xdeadf231@ha
1684c283b4cSmatt	addi	%r31,%r31,0xdeadf231@l
1694c283b4cSmatt	mtlr	%r31
1704c283b4cSmatt	addi	%r31,%r31,-0x10
1714c283b4cSmatt	mtcr	%r31
1724c283b4cSmatt	addi	%r31,%r31,-0x10
1734c283b4cSmatt	mtctr	%r31
1744c283b4cSmatt	addi	%r31,%r31,-0x10
1754c283b4cSmatt	mtxer	%r31
1764c283b4cSmatt	addi	%r31,%r31,-0x10
1774c283b4cSmatt	addi	%r30,%r31,-0x10
1784c283b4cSmatt	addi	%r29,%r30,-0x10
1794c283b4cSmatt	addi	%r28,%r29,-0x10
1804c283b4cSmatt	addi	%r27,%r28,-0x10
1814c283b4cSmatt	addi	%r26,%r27,-0x10
1824c283b4cSmatt	addi	%r25,%r26,-0x10
1834c283b4cSmatt	addi	%r24,%r25,-0x10
1844c283b4cSmatt	addi	%r23,%r24,-0x10
1854c283b4cSmatt	addi	%r22,%r23,-0x10
1864c283b4cSmatt	addi	%r21,%r22,-0x10
1874c283b4cSmatt	addi	%r20,%r21,-0x10
1884c283b4cSmatt	addi	%r19,%r20,-0x10
1894c283b4cSmatt	addi	%r18,%r19,-0x10
1904c283b4cSmatt	addi	%r17,%r18,-0x10
1914c283b4cSmatt	addi	%r16,%r17,-0x10
1924c283b4cSmatt	addi	%r15,%r16,-0x10
1934c283b4cSmatt	addi	%r14,%r15,-0x10
1944c283b4cSmatt	addi	%r13,%r14,-0x10
1954c283b4cSmatt	addi	%r12,%r13,-0x10
1964c283b4cSmatt	addi	%r11,%r12,-0x10
1974c283b4cSmatt	addi	%r10,%r11,-0x10
1984c283b4cSmatt	addi	%r9,%r10,-0x10
1994c283b4cSmatt	addi	%r8,%r9,-0x10
2004c283b4cSmatt	addi	%r7,%r8,-0x10
2014c283b4cSmatt	addi	%r6,%r7,-0x10
2024c283b4cSmatt	addi	%r5,%r6,-0x10
2034c283b4cSmatt	addi	%r4,%r5,-0x10
2044c283b4cSmatt	addi	%r3,%r4,-0x10
2054c283b4cSmatt	addi	%r2,%r3,-0x10
2064c283b4cSmatt	/* leave r1 alone */
2074c283b4cSmatt	addi	%r0,%r2,-0x20
2084c283b4cSmatt	b	_C_LABEL(instruction_tlb_error_vector)
2094c283b4cSmatt	//b	_C_LABEL(program_vector)
2104c283b4cSmatt	//b	_C_LABEL(external_input_vector)
2114c283b4cSmatt3:
2124c283b4cSmatt#endif
2134c283b4cSmatt
2144c283b4cSmatt	/*
2154c283b4cSmatt	 * TB is 50Mhz, watchdog should be ~10 seconds which makes that
2164c283b4cSmatt	 * 500 million or 0x20000000.  Since it takes 3 bit transitions
2174c283b4cSmatt	 * we really want 0x10000000.   That's bit 63-28 or 35.  This
2184c283b4cSmatt	 * means we want WPEXT,WP to be 0b10_0011.
2194c283b4cSmatt	 */
2204c283b4cSmatt	lis	%r3,(TCR_WRC_RESET|TCR_WP_2_N(0x23))@ha
2214c283b4cSmatt	addi	%r3,%r3,(TCR_WRC_RESET|TCR_WP_2_N(0x23))@l
2224c283b4cSmatt	mtspr	SPR_TCR, %r3
2234c283b4cSmatt	li	%r0, 0
2244c283b4cSmatt	mtspr	SPR_TBL, %r0
2254c283b4cSmatt	mtspr	SPR_TBU, %r0
2264c283b4cSmatt	mtspr	SPR_DBCR0, %r0
2274c283b4cSmatt
2284c283b4cSmatt#if 0
2294c283b4cSmatt	/*
2304c283b4cSmatt	 * Force all dirty lines in the kernel area to memory.
2314c283b4cSmatt	 */
2324a34c25dSmatt	lis	%r9,kernel_text@ha
2334a34c25dSmatt	addi	%r9,%r9,kernel_text@l
2344a34c25dSmatt4:	dcbst	%r0,%r9
2354a34c25dSmatt	addi	%r9,%r9,32
2364a34c25dSmatt	cmplw	%r9,%r4
2374c283b4cSmatt	blt	%cr0,4b
2384c283b4cSmatt	mbar	1
2394c283b4cSmatt	msync
2404c283b4cSmatt
2414c283b4cSmatt	/*
2424c283b4cSmatt	 * Turn off the data cache, and then invalidate it.
2434c283b4cSmatt	 */
2444c283b4cSmatt	li	%r3, 0
2454c283b4cSmatt	mtspr	SPR_L1CSR0, %r3
2464c283b4cSmatt	li	%r3, L1CSR_CFI
2474c283b4cSmatt	mtspr	SPR_L1CSR0, %r3
2484c283b4cSmatt#endif
2494c283b4cSmatt
2504c283b4cSmatt#if 1
2514c283b4cSmatt	/*
2524c283b4cSmatt	 * Clear any locks from the data or instruction caches.
2534c283b4cSmatt	 */
2544c283b4cSmatt	mfspr	%r3, SPR_L1CSR0
2554c283b4cSmatt	ori	%r3, %r3, L1CSR_CLFR
2564c283b4cSmatt	mtspr	SPR_L1CSR0, %r3
2574c283b4cSmatt	mfspr	%r3, SPR_L1CSR1
2584c283b4cSmatt	ori	%r3, %r3, L1CSR_CLFR
2594c283b4cSmatt	mtspr	SPR_L1CSR1, %r3
2604c283b4cSmatt#endif
2614c283b4cSmatt
2624c283b4cSmatt	lis	%r3,__start@ha
2634c283b4cSmatt	addi	%r3,%r3,__start@l
2644c283b4cSmatt
2654c283b4cSmatt	bl	_C_LABEL(initppc)
2664c283b4cSmatt	bl	_C_LABEL(main)
2674c283b4cSmatt
2684c283b4cSmattloop:	b	loop			/* XXX not reached */
2694c283b4cSmatt
2704c283b4cSmatt#include <powerpc/booke/trap_subr.S>
2714c283b4cSmatt#include <powerpc/powerpc/locore_subr.S>
2724c283b4cSmatt#include <powerpc/powerpc/pio_subr.S>
2734c283b4cSmatt#ifdef PPC_HAVE_SPE
2744c283b4cSmatt#include <powerpc/booke/spe_subr.S>
2754c283b4cSmatt#endif
27620e2c495Smatt#if defined(MULTIPROCESSOR)
27720e2c495Smatt#include <powerpc/booke/e500_mpsubr.S>
27820e2c495Smatt#endif
2794c283b4cSmatt
2804c283b4cSmatt#if 0
2814c283b4cSmatt	.p2align 5
2824c283b4cSmattENTRY(tlbwe)
2834c283b4cSmatt	isync
2844c283b4cSmatt	tlbwe
2854c283b4cSmatt	isync
2864c283b4cSmatt	blr
2874c283b4cSmatt#endif
288