Home | History | Annotate | Line # | Download | only in altboot
entry.S revision 1.2
      1 /* $NetBSD: entry.S,v 1.2 2011/02/26 20:11:24 phx Exp $ */
      2 
      3 #include <powerpc/psl.h>
      4 #include <powerpc/spr.h>
      5 #include <powerpc/oea/spr.h>
      6 #include <powerpc/oea/bat.h>
      7 #include <powerpc/oea/hid.h>
      8 
      9 	.text
     10 	.globl _start
     11 _start:
     12 	/*
     13 	 * Save possible argc and argv values from the firmware, usually
     14 	 * passed in r3 and r4.
     15 	 * When started with "bootm", as a Linux kernel module, r6 and r7
     16 	 * point to the start and end address of the bootargs.
     17 	 */
     18 	mr	30,3
     19 	mr	31,4
     20 	mr	28,6
     21 	mr	29,7
     22 
     23 	/*
     24 	 * U-Boot/PPCBoot forgets to flush the cache when using the "bootm"
     25 	 * command, so we have to do that now.
     26 	 */
     27 	lis	3,_start@ha
     28 	addi	3,3,_start@l
     29 	andi.	3,3,~31@l
     30 	lis	4,(_edata+31)@ha
     31 	addi	4,4,(_edata+31)@l
     32 	mr	5,3
     33 10:
     34 	dcbst	0,5
     35 	addi	5,5,32
     36 	cmplw	5,4
     37 	ble	10b
     38 	sync
     39 11:
     40 	icbi	0,3
     41 	addi	3,3,32
     42 	cmplw	3,4
     43 	ble	11b
     44 	sync
     45 	isync
     46 
     47 	mfspr	11,SPR_HID0
     48 	andi.	0,11,HID0_DCE
     49 	ori	11,11,HID0_ICE
     50 	ori	8,11,HID0_ICFI
     51 	bne	1f			/* don't invalidate the D-cache */
     52 	ori	8,8,HID0_DCFI		/* unless it wasn't enabled */
     53 1:
     54 	mfmsr	0
     55 	andi.	0,0,PSL_DR
     56 	beq	2f
     57 	lis	5, 0xfec00000@ha	/* CONFIG_ADDR of PCI */
     58 	lis	6, 0xfee00000@ha	/* CONFIG_DATA of PCI */
     59 	mfspr	3,SPR_DBAT0U
     60 	mfspr	4,SPR_DBAT0L
     61 	bl	dbat_sanity_check
     62 	beq	3f
     63 	mfspr	3,SPR_DBAT1U
     64 	mfspr	4,SPR_DBAT1L
     65 	bl	dbat_sanity_check
     66 	beq	3f
     67 	mfspr	3,SPR_DBAT2U
     68 	mfspr	4,SPR_DBAT2L
     69 	bl	dbat_sanity_check
     70 	beq	3f
     71 	mfspr	3,SPR_DBAT3U
     72 	mfspr	4,SPR_DBAT3L
     73 	bl	dbat_sanity_check
     74 	beq	3f
     75 
     76 2:	/* Disable D-cache */
     77 	li	0,HID0_DCE
     78 	andc	11,11,0
     79 	b	4f
     80 
     81 3:	/* Enable D-cache */
     82 	ori	11,11,HID0_DCE
     83 
     84 4:
     85 	lis	1,BAT123@ha
     86 	addi	1,1,BAT123@l
     87 	lwz	3,0(1)
     88 	lwz	4,4(1)
     89 	mtdbatl	1,3
     90 	mtdbatu	1,4
     91 	lwz	3,8(1)
     92 	lwz	4,12(1)
     93 	mtdbatl	2,3
     94 	mtdbatu	2,4
     95 	lwz	3,16(1)
     96 	lwz	4,20(1)
     97 	mtdbatl	3,3
     98 	mtdbatu	3,4
     99 
    100 	sync
    101 	mtspr	SPR_HID0,8		/* enable and invalidate caches */
    102 	sync
    103 	mtspr	SPR_HID0,11		/* enable caches */
    104 	sync
    105 	isync
    106 
    107 	/* make sure .bss gets zeroed. */
    108 	li	0,0
    109 	lis	8,edata@ha
    110 	addi	8,8,edata@l
    111 	lis	9,end@ha
    112 	addi	9,9,end@l
    113 5:	cmpw	0,8,9			/* edata & end are >= word aligned */
    114 	bge	6f
    115 	stw	0,0(8)
    116 	addi	8,8,4
    117 	b	5b
    118 
    119 6:
    120 	/* prepare stack at +1MB from _start. */
    121 	lis	1,_start@h
    122 	ori	1,1,_start@l
    123 	addis	1,1,0x10
    124 	addi	1,1,-4
    125 
    126 	bl	brdsetup
    127 	mr	3,30
    128 	mr	4,31
    129 	mr	5,28
    130 	mr	6,29
    131 	bl	main
    132 
    133 hang:	b	hang
    134 	/* NOTREACHED */
    135 
    136 dbat_sanity_check:
    137 	andi.	0,3,BAT_Vs
    138 	beq	2f
    139 	andi.	0,4,BAT_I|BAT_PP_RW
    140 	cmpwi	0,0,BAT_I|BAT_PP_RW
    141 	bnelr
    142 	rlwinm	0,3,15,4,14
    143 	andis.	3,3,0xfffe0000@ha	/* BAT_EPI */
    144 	andis.	4,4,BAT_RPN@ha
    145 	cmplw	0,3,4
    146 	bnelr
    147 	add	4,4,0
    148 	oris	4,4,0x0001ffff@ha
    149 	ori	4,4,0x0001ffff@l
    150 	cmplw	0,3,5
    151 	bgt	1f
    152 	cmplw	0,5,4
    153 	bgt	1f
    154 	li	5,0
    155 1:	cmplw	0,3,6
    156 	bgt	2f
    157 	cmplw	0,6,4
    158 	bgt	2f
    159 	li	6,0
    160 2:	cmplw	0,5,6
    161 	blr
    162 
    163 /*
    164  * run(startsym, endsym, howto, bootinfo, entry)
    165  */
    166 	.globl	run
    167 run:
    168 	mtctr	7 	/* hat trick jump to entry point */
    169 	bctr
    170 
    171 /*
    172  * reverse endian access to mimic outw/outl/inw/inl
    173  */
    174 	.globl out16rb
    175 	.globl iohtole16
    176 out16rb:
    177 iohtole16:
    178 	sthbrx	4,0,3
    179 	eieio
    180 	blr
    181 
    182 	.globl out32rb
    183 	.globl iohtole32
    184 out32rb:
    185 iohtole32:
    186 	stwbrx	4,0,3
    187 	eieio
    188 	blr
    189 
    190 	.global in16rb
    191 	.global iole16toh
    192 in16rb:
    193 iole16toh:
    194 	lhbrx	3,0,3
    195 	eieio
    196 	blr
    197 
    198 	.global in32rb
    199 	.global iole32toh
    200 in32rb:
    201 iole32toh:
    202 	lwbrx	3,0,3
    203 	eieio
    204 	blr
    205 
    206 	.data
    207 #define	xBATL(pa, wimg, pp)						\
    208 	((pa) | (wimg) | (pp))
    209 #define	xBATU(va, len, v)						\
    210 	((va) | ((len) & BAT_BL) | ((v) & BAT_V))
    211 BAT123:
    212 	.long xBATL(0x80000000, BAT_I|BAT_G, BAT_PP_RW)
    213 	.long xBATU(0x80000000, BAT_BL_256M, BAT_Vs)
    214 	.long xBATL(0xfc000000, BAT_I|BAT_G, BAT_PP_RW)
    215 	.long xBATU(0xfc000000, BAT_BL_64M, BAT_Vs)
    216 	.long 0
    217 	.long 0
    218