Home | History | Annotate | Line # | Download | only in virtex
virtex_start.S revision 1.8.52.1
      1  1.8.52.1  pgoyette /*	$NetBSD: virtex_start.S,v 1.8.52.1 2018/07/28 04:37:33 pgoyette 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 #include "opt_ddb.h"
     37       1.1     freza #include "opt_lockdebug.h"
     38       1.3       apb #include "opt_modular.h"
     39       1.1     freza #include "opt_multiprocessor.h"
     40       1.1     freza #include "opt_ppcarch.h"
     41       1.1     freza #include "opt_ppcparam.h"
     42       1.1     freza #include "opt_virtex.h"
     43       1.1     freza #include "assym.h"
     44       1.1     freza #include "ksyms.h"
     45       1.1     freza 
     46       1.1     freza #include <sys/syscall.h>
     47       1.1     freza 
     48       1.1     freza #include <machine/param.h>
     49       1.1     freza #include <machine/psl.h>
     50       1.1     freza #include <machine/trap.h>
     51       1.1     freza #include <machine/asm.h>
     52       1.1     freza 
     53       1.1     freza #include <powerpc/spr.h>
     54       1.5      matt #include <powerpc/ibm4xx/spr.h>
     55       1.6  kiyohara #include <powerpc/ibm4xx/dcr4xx.h>
     56       1.1     freza 
     57       1.1     freza 
     58       1.1     freza /* N megabytes. */
     59       1.1     freza #define MB(n) 				((n)*1024*1024)
     60       1.1     freza 
     61       1.1     freza /* Set bit (beginning with MSB) for each 128MB of RAM. */
     62       1.1     freza #define PHYSMEM_REGIONS_MASK 		~((1 << (32 - MB(PHYSMEM)/MB(128))) - 1)
     63       1.1     freza 
     64       1.1     freza /* For kvm_mkdb, supposed to mark the start of kernel text. */
     65       1.1     freza 	.text
     66       1.1     freza 	.globl	_C_LABEL(kernel_text)
     67       1.1     freza _C_LABEL(kernel_text):
     68       1.1     freza 
     69       1.1     freza /* Startup entry. This must be the first thing in the text segment! */
     70       1.1     freza 	.text
     71       1.1     freza 	.globl	__start
     72       1.1     freza __start:
     73       1.1     freza 	/* Disable MMU/exceptions */
     74       1.1     freza 	lis	%r0, 0
     75       1.1     freza 	mtmsr	%r0
     76       1.1     freza 
     77       1.1     freza 	/* Disable timers */
     78       1.1     freza 	lis 	%r0, 0
     79       1.1     freza 	mttcr 	%r0
     80       1.1     freza 
     81       1.1     freza 	sync
     82       1.1     freza 	isync
     83       1.1     freza 
     84       1.1     freza 	/* Disable caches */
     85       1.1     freza 	mtdccr 	%r0
     86       1.1     freza 	mticcr	%r0
     87       1.1     freza 	sync
     88       1.1     freza 	isync
     89       1.1     freza 
     90       1.1     freza 	/* Invalidate I$, operands ignored on the 405 */
     91       1.1     freza 	li 	%r0,0 			/* just in case... */
     92       1.1     freza 	iccci 	%r0,%r0
     93       1.1     freza 
     94       1.1     freza 	/* Invalidate D$, hardcoded for 16KB size, 32B line */
     95       1.1     freza 	li      %r7,256 		/* # of congruence classes */
     96       1.1     freza 	mtctr   %r7
     97       1.1     freza 	li      %r6,0
     98       1.1     freza 1:
     99       1.1     freza 	dccci   %r0,%r6 		/* invalidates both ways */
    100       1.1     freza 	addi    %r6,%r6,32
    101       1.1     freza 	bdnz    1b
    102       1.1     freza 
    103       1.1     freza         /*
    104       1.1     freza          * Errata 213: 	Incorrect data may be flushed from the data cache.
    105       1.1     freza          * Cores: 	PPC405D5X1, PPC405D5X2
    106       1.1     freza          * Workaround: 	#1, CCR0 modification sequence #2
    107       1.1     freza          * Note: 	Meaning of bits we need to set is undocumented.
    108       1.1     freza          */
    109       1.1     freza 	sync
    110       1.1     freza         mfccr0  %r0
    111       1.1     freza         oris    %r0,%r0,0x50000000@h
    112       1.1     freza         mtccr0  %r0
    113       1.1     freza 	isync
    114       1.1     freza 
    115       1.1     freza 	/*
    116       1.1     freza 	 * Errata  58: 	Load string instructions may write incorrect
    117       1.1     freza 	 * 		data into the last GPR targeted in operation.
    118       1.1     freza 	 * Cores: 	PPC405GP
    119       1.1     freza 	 * Workaround: 	set OCM0_DSCNTL[DSEN]=0 and OCM0_DSCNTL[DOF]=0
    120       1.1     freza 	 */
    121       1.1     freza 	mtdcr   DCR_OCM0_DSCNTL,%r0    /* Disable Data access to OCM */
    122       1.1     freza 
    123       1.1     freza #if 0
    124       1.1     freza 	/* Allow cacheing for whole RAM. */
    125       1.1     freza 	lis	%r0,PHYSMEM_REGIONS_MASK@ha
    126       1.1     freza 	ori 	%r0,%r0,PHYSMEM_REGIONS_MASK@l
    127       1.1     freza #else
    128       1.1     freza #ifndef PPC_4XX_NOCACHE
    129       1.1     freza 	/* Allow cacheing for only the first 1GB of RAM */
    130       1.1     freza 	lis 	%r0,0xff00
    131       1.1     freza 	mtdccr	%r0
    132       1.1     freza 	mticcr	%r0
    133       1.1     freza #endif /* PPC_4XX_NOCACHE */
    134       1.1     freza #endif
    135       1.1     freza 
    136       1.1     freza 	/* Invalidate all TLB entries */
    137       1.1     freza 	tlbia
    138       1.1     freza 	sync
    139       1.1     freza 	isync
    140       1.1     freza 
    141       1.1     freza 	/* Set kernel MMU context, we'll enable MMU in initppc() */
    142       1.1     freza 	li	%r0,KERNEL_PID
    143       1.1     freza 	mtpid	%r0
    144       1.1     freza 	sync
    145       1.1     freza 	isync
    146       1.1     freza 
    147       1.1     freza 	/* Setup endkernel argument for initppc() and INIT_CPUINFO */
    148       1.1     freza 	lis	%r4,_C_LABEL(end)@h
    149       1.1     freza 	ori 	%r4,%r4,_C_LABEL(end)@l
    150       1.1     freza 
    151       1.1     freza 	/* Clear .bss segment */
    152       1.1     freza 	lis 	%r7,_C_LABEL(edata)-4@h
    153       1.1     freza 	ori 	%r7,%r7,_C_LABEL(edata)-4@l
    154       1.1     freza 	li 	%r3,0
    155       1.1     freza 2: 	stwu    %r3,4(%r7)
    156       1.1     freza 	cmpw    %r7,%r4
    157       1.1     freza 	bne+    2b
    158       1.1     freza 
    159       1.2        ad #if NKSYMS || defined(DDB) || defined(MODULAR)
    160       1.1     freza 	/* We don't have a symbol table, so set startsym = endsym = end */
    161       1.1     freza 	lis	%r7,_C_LABEL(startsym)@ha
    162       1.1     freza 	ori 	%r7,%r7,_C_LABEL(startsym)@l
    163       1.1     freza 	stw	%r4,0(%r7)
    164       1.1     freza 	lis	%r7,_C_LABEL(endsym)@ha
    165       1.1     freza 	ori 	%r7,%r7,_C_LABEL(endsym)@l
    166       1.1     freza 	stw	%r4,0(%r7)
    167       1.1     freza #endif
    168       1.1     freza 
    169       1.1     freza 	/* INIT_CPUINFO will 'addi', so clean up. */
    170       1.1     freza 	lis 	%r1,0
    171       1.1     freza 
    172       1.1     freza 	INIT_CPUINFO(4,1,9,0)
    173       1.1     freza 
    174       1.1     freza 	/* startkernel argument for initppc */
    175       1.1     freza 	lis	%r3,__start@h
    176       1.1     freza 	addi	%r3,%r3,__start@l
    177       1.1     freza 
    178       1.1     freza 	bl	_C_LABEL(initppc)
    179       1.1     freza 	bl	_C_LABEL(main)
    180       1.1     freza 
    181       1.1     freza loop: 	/* UNREACHED */
    182       1.1     freza 	b	loop
    183       1.1     freza 
    184       1.1     freza #include <powerpc/ibm4xx/4xx_locore.S>
    185