Home | History | Annotate | Line # | Download | only in mpcsa
mpcsa_start.S revision 1.2.20.1
      1       1.2   matt /*
      2       1.2   matt  * mpcsa_start.S
      3       1.2   matt  * Copyright (c) 2007, S. Kantoluoto <sami.kantoluoto (at) iki.fi>
      4       1.2   matt  * All rights reserved.
      5       1.2   matt  *
      6       1.2   matt  * Based on vx115_vep_start.S
      7       1.2   matt  * Copyright (c) 2007, J. Sevy <jsevy (at) cs.drexel.edu>
      8       1.2   matt  *
      9       1.2   matt  * Based on g42xxeb_start.S
     10       1.2   matt  * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
     11       1.2   matt  * Written by Hiroyuki Bessho for Genetec Corporation.
     12       1.2   matt  *
     13       1.2   matt  * Redistribution and use in source and binary forms, with or without
     14       1.2   matt  * modification, are permitted provided that the following conditions
     15       1.2   matt  * are met:
     16       1.2   matt  * 1. Redistributions of source code must retain the above copyright
     17       1.2   matt  *    notice, this list of conditions and the following disclaimer.
     18       1.2   matt  * 2. Redistributions in binary form must reproduce the above copyright
     19       1.2   matt  *    notice, this list of conditions and the following disclaimer in the
     20       1.2   matt  *    documentation and/or other materials provided with the distribution.
     21       1.2   matt  * 3. The name of Genetec Corporation may not be used to endorse or
     22       1.2   matt  *    promote products derived from this software without specific prior
     23       1.2   matt  *    written permission.
     24       1.2   matt  *
     25       1.2   matt  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     26       1.2   matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27       1.2   matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28       1.2   matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     29       1.2   matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30       1.2   matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31       1.2   matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32       1.2   matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33       1.2   matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34       1.2   matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35       1.2   matt  * POSSIBILITY OF SUCH DAMAGE.
     36       1.2   matt  */
     37       1.2   matt 
     38       1.2   matt #include <machine/asm.h>
     39       1.2   matt #include <arm/armreg.h>
     40  1.2.20.1  rmind #include "assym.h"
     41  1.2.20.1  rmind 
     42  1.2.20.1  rmind RCSID("$NetBSD: mpcsa_start.S,v 1.2.20.1 2011/03/05 20:50:08 rmind Exp $")
     43       1.2   matt 
     44       1.2   matt #ifndef	FLASH_START
     45       1.2   matt #define	FLASH_START	0x10020000
     46       1.2   matt #endif
     47       1.2   matt 
     48       1.2   matt #ifndef SDRAM_START
     49       1.2   matt #define SDRAM_START    0x20000000
     50       1.2   matt #endif
     51       1.2   matt 
     52       1.2   matt #define	MODBASE	       0x20200000
     53       1.2   matt 
     54       1.2   matt /*
     55       1.2   matt  * CPWAIT -- Canonical method to wait for CP15 update.
     56       1.2   matt  * NOTE: Clobbers the specified temp reg.
     57       1.2   matt  * copied from arm/arm/cpufunc_asm_xscale.S
     58       1.2   matt  * XXX: better be in a common header file.
     59       1.2   matt  */
     60       1.2   matt #define    CPWAIT_BRANCH    \
     61       1.2   matt     sub pc, pc, #4
     62       1.2   matt 
     63       1.2   matt #define    CPWAIT(tmp)                             				 \
     64       1.2   matt     mrc p15, 0, tmp, c2, c0, 0  /* arbitrary read of CP15 */    ;\
     65       1.2   matt     mov tmp, tmp        		/* wait for it to complete */   ;\
     66       1.2   matt     CPWAIT_BRANCH            	/* branch to next insn */
     67       1.2   matt 
     68       1.2   matt /*
     69       1.2   matt  * Kernel start routine for MPCSA board.
     70       1.2   matt  * This code is executed from Flash when the bootloader jumps to it.
     71       1.2   matt  */
     72       1.2   matt     .text
     73       1.2   matt 
     74       1.2   matt     .global _C_LABEL(mpcsa_start)
     75       1.2   matt _C_LABEL(mpcsa_start):
     76       1.2   matt 
     77       1.2   matt     /* make sure we're in supervisor mode */
     78       1.2   matt     mov	   r0,sp
     79       1.2   matt     msr    CPSR_c,#I32_bit | F32_bit | PSR_SVC32_MODE
     80       1.2   matt     mov	   sp,r0
     81       1.2   matt 
     82       1.2   matt     /* move code to RAM */
     83       1.2   matt     ldr    r1, Lcopy_size
     84       1.2   matt     adr    r0, _C_LABEL(mpcsa_start)
     85       1.2   matt     add    r1, r1, #3
     86       1.2   matt     mov    r1, r1, LSR #2         /* get size of code in words */
     87       1.2   matt     mov    r2, #SDRAM_START
     88       1.2   matt     add    r2, r2, #0x200000    /* code placed 2MB above kernel base */
     89       1.2   matt     mov    r4, r2
     90       1.2   matt 
     91       1.2   matt     /* copy kernel to RAM */
     92       1.2   matt 5:  ldr    r3, [r0], #4
     93       1.2   matt     subs   r1, r1, #1
     94       1.2   matt     str    r3, [r2], #4
     95       1.2   matt     bhi    5b
     96       1.2   matt 
     97       1.2   matt     /* jump to RAM */
     98       1.2   matt     ldr    r0, Lstart_off
     99       1.2   matt     add    pc, r4, r0
    100       1.2   matt 
    101       1.2   matt 
    102       1.2   matt Lcopy_size:    .word _edata-_C_LABEL(mpcsa_start)
    103       1.2   matt Lstart_off:    .word mpcsa_start_ram-_C_LABEL(mpcsa_start)
    104       1.2   matt 
    105       1.2   matt mpcsa_start_ram:
    106       1.2   matt     /*
    107       1.2   matt      *  Kernel is loaded in SDRAM (0x20200000), and is expected to run
    108       1.2   matt      *  in VA 0xc0200000.
    109       1.2   matt      */
    110       1.2   matt 
    111       1.2   matt     /* build page table from scratch */
    112       1.2   matt     ldr    r0, Lstartup_pagetable
    113       1.2   matt     adr    r4, mmu_init_table
    114       1.2   matt     b      3f
    115       1.2   matt 
    116       1.2   matt 2:
    117       1.2   matt     str    r3, [r0, r2]
    118       1.2   matt     add    r2, r2, #4
    119       1.2   matt     add    r3, r3, #(L1_S_SIZE)
    120       1.2   matt     adds   r1, r1, #-1
    121       1.2   matt     bhi    2b
    122       1.2   matt 3:
    123       1.2   matt     ldmia  r4!, {r1,r2,r3}   /* # of sections, PA|attr, VA */
    124       1.2   matt     cmp    r1, #0
    125       1.2   matt     bne    2b
    126       1.2   matt 
    127       1.2   matt 
    128       1.2   matt     mcr    p15, 0, r0, c2, c0, 0    /* Set TTB */
    129       1.2   matt     mcr    p15, 0, r0, c8, c7, 0    /* Flush TLB */
    130       1.2   matt 
    131       1.2   matt     /* Set the Domain Access register.  Very important! */
    132       1.2   matt     mov    r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
    133       1.2   matt     mcr    p15, 0, r0, c3, c0, 0
    134       1.2   matt 
    135       1.2   matt     /* Enable MMU */
    136       1.2   matt     mrc    p15, 0, r0, c1, c0, 0
    137       1.2   matt     orr    r0, r0, #CPU_CONTROL_MMU_ENABLE
    138       1.2   matt     mcr    p15, 0, r0, c1, c0, 0
    139       1.2   matt     CPWAIT(r0)
    140       1.2   matt 
    141       1.2   matt     /* Jump to kernel code in TRUE VA */
    142       1.2   matt     adr    r0, Lstart
    143       1.2   matt     ldr    pc, [r0]
    144       1.2   matt 
    145       1.2   matt Lstart:
    146       1.2   matt     .word    start
    147       1.2   matt 
    148       1.2   matt 
    149       1.2   matt #define MMU_INIT(va,pa,n_sec,attr)  \
    150       1.2   matt     .word    n_sec                 ;\
    151       1.2   matt     .word    4*((va)>>L1_S_SHIFT)  ;\
    152       1.2   matt     .word    (pa) | (attr)
    153       1.2   matt 
    154       1.2   matt #define STARTUP_PAGETABLE_ADDR  0x20100000 + 0x4000
    155       1.2   matt 
    156       1.2   matt Lstartup_pagetable:
    157       1.2   matt 	.word STARTUP_PAGETABLE_ADDR
    158       1.2   matt 
    159       1.2   matt mmu_init_table:
    160       1.2   matt     /* fill all table VA==PA */
    161  1.2.20.1  rmind     MMU_INIT(0x00000000, 0x00000000, 1<<(32-L1_S_SHIFT), L1_TYPE_S|L1_S_AP_KRW)
    162       1.2   matt     /* map in peripheral space */
    163  1.2.20.1  rmind     MMU_INIT(0xfff00000, 0xfff00000, 1, L1_TYPE_S|L1_S_AP_KRW)
    164       1.2   matt     /* map SDRAM VA==PA, WT cacheable */
    165  1.2.20.1  rmind     MMU_INIT(0x20100000, 0x20100000, 63, L1_TYPE_S|L1_S_C|L1_S_AP_KRW)
    166       1.2   matt     /* map VA 0xc0000000..0xc0efffff to PA 0x20100000..0x23ffffff */
    167  1.2.20.1  rmind     MMU_INIT(0xc0000000, 0x20000000, 63, L1_TYPE_S|L1_S_C|L1_S_AP_KRW)
    168       1.2   matt     .word 0    /* end of table */
    169       1.2   matt 
    170       1.2   matt 	.align	7
    171       1.2   matt jme_module_header:
    172       1.2   matt 	.word	0xe990510e		/* magic number			*/
    173       1.2   matt 	.string	"NetBSD/mpcsa\0\0\0"	/* module name			*/
    174       1.2   matt 	.short	0			/* build flags			*/
    175       1.2   matt 	.short	0			/* flags			*/
    176       1.2   matt 	.word	0			/* version			*/
    177       1.2   matt 	.word	0			/* compile / link timestamp	*/
    178       1.2   matt 	.word	MODBASE		/* pointer to init routine	*/
    179       1.2   matt 	.word	MODBASE		/* start address		*/
    180       1.2   matt 	.word	(_edata-(_C_LABEL(mpcsa_start)))			/* length of module		*/
    181       1.2   matt 	.word	(jme_module_header-_C_LABEL(mpcsa_start)+MODBASE)			/* back pointer to module struct*/
    182       1.2   matt 	.word	0			/* data pointer (ignored but SBZ)*/
    183       1.2   matt 	.word	0			/* data length (ignored but SBZ)*/
    184       1.2   matt 	.word	0x20200000		/* alternate address		*/
    185       1.2   matt 	.word	0			/* reserved, SBZ		*/
    186       1.2   matt 
    187       1.2   matt jme_kmodule_header:
    188       1.2   matt 	.word	0xe000301e		/* magic number			*/
    189       1.2   matt 	.string	"JME kernel\0\0\0\0\0"	/* module name			*/
    190       1.2   matt 	.short	0			/* build flags			*/
    191       1.2   matt 	.short	0			/* flags			*/
    192       1.2   matt 	.word	0			/* version			*/
    193       1.2   matt 	.word	0			/* compile / link timestamp	*/
    194       1.2   matt 	.word	MODBASE		/* pointer to init routine	*/
    195       1.2   matt 	.word	MODBASE		/* start address		*/
    196       1.2   matt 	.word	(_edata-(_C_LABEL(mpcsa_start)))			/* length of module		*/
    197       1.2   matt 	.word	(jme_kmodule_header-_C_LABEL(mpcsa_start)+MODBASE)	/* back pointer to module struct*/
    198       1.2   matt 	.word	0			/* data pointer (ignored but SBZ)*/
    199       1.2   matt 	.word	0			/* data length (ignored but SBZ)*/
    200       1.2   matt 	.word	0x20200000		/* alternate address		*/
    201       1.2   matt 	.word	0			/* reserved, SBZ		*/
    202