xref: /openbmc/u-boot/arch/microblaze/cpu/start.S (revision b98cba0911c7d0c0486d600c2aa646395adf32f4)
16260fb04SPeter Tyser/*
26260fb04SPeter Tyser * (C) Copyright 2007 Michal Simek
36260fb04SPeter Tyser * (C) Copyright 2004 Atmark Techno, Inc.
46260fb04SPeter Tyser *
56260fb04SPeter Tyser * Michal  SIMEK <monstr@monstr.eu>
66260fb04SPeter Tyser * Yasushi SHOJI <yashi@atmark-techno.com>
76260fb04SPeter Tyser *
86260fb04SPeter Tyser * See file CREDITS for list of people who contributed to this
96260fb04SPeter Tyser * project.
106260fb04SPeter Tyser *
116260fb04SPeter Tyser * This program is free software; you can redistribute it and/or
126260fb04SPeter Tyser * modify it under the terms of the GNU General Public License as
136260fb04SPeter Tyser * published by the Free Software Foundation; either version 2 of
146260fb04SPeter Tyser * the License, or (at your option) any later version.
156260fb04SPeter Tyser *
166260fb04SPeter Tyser * This program is distributed in the hope that it will be useful,
176260fb04SPeter Tyser * but WITHOUT ANY WARRANTY; without even the implied warranty of
186260fb04SPeter Tyser * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
196260fb04SPeter Tyser * GNU General Public License for more details.
206260fb04SPeter Tyser *
216260fb04SPeter Tyser * You should have received a copy of the GNU General Public License
226260fb04SPeter Tyser * along with this program; if not, write to the Free Software
236260fb04SPeter Tyser * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
246260fb04SPeter Tyser * MA 02111-1307 USA
256260fb04SPeter Tyser */
266260fb04SPeter Tyser
276260fb04SPeter Tyser#include <config.h>
286260fb04SPeter Tyser
296260fb04SPeter Tyser	.text
306260fb04SPeter Tyser	.global _start
316260fb04SPeter Tyser_start:
326260fb04SPeter Tyser	mts	rmsr, r0	/* disable cache */
336260fb04SPeter Tyser	addi	r1, r0, CONFIG_SYS_INIT_SP_OFFSET
346260fb04SPeter Tyser	addi	r1, r1, -4	/* Decrement SP to top of memory */
35*b98cba09SMichal Simek
36*b98cba09SMichal Simek	/* Find-out if u-boot is running on BIG/LITTLE endian platform
37*b98cba09SMichal Simek	 * There are some steps which is necessary to keep in mind:
38*b98cba09SMichal Simek	 * 1. Setup offset value to r6
39*b98cba09SMichal Simek	 * 2. Store word offset value to address 0x0
40*b98cba09SMichal Simek	 * 3. Load just byte from address 0x0
41*b98cba09SMichal Simek	 * 4a) LITTLE endian - r10 contains 0x2 because it is the smallest
42*b98cba09SMichal Simek	 *     value that's why is on address 0x0
43*b98cba09SMichal Simek	 * 4b) BIG endian - r10 contains 0x0 because 0x2 offset is on addr 0x3
44*b98cba09SMichal Simek	 */
45*b98cba09SMichal Simek	addik	r6, r0, 0x2 /* BIG/LITTLE endian offset */
46*b98cba09SMichal Simek	swi	r6, r0, 0
47*b98cba09SMichal Simek	lbui	r10, r0, 0
48*b98cba09SMichal Simek	swi	r6, r0, 0x40
49*b98cba09SMichal Simek	swi	r10, r0, 0x50
50*b98cba09SMichal Simek
516260fb04SPeter Tyser	/* add opcode instruction for 32bit jump - 2 instruction imm & brai*/
526260fb04SPeter Tyser	addi	r6, r0, 0xb0000000	/* hex b000 opcode imm */
536260fb04SPeter Tyser	swi	r6, r0, 0x0	/* reset address */
546260fb04SPeter Tyser	swi	r6, r0, 0x8	/* user vector exception */
556260fb04SPeter Tyser	swi	r6, r0, 0x10	/* interrupt */
566260fb04SPeter Tyser	swi	r6, r0, 0x20	/* hardware exception */
576260fb04SPeter Tyser
586260fb04SPeter Tyser	addi	r6, r0, 0xb8080000	/* hew b808 opcode brai*/
596260fb04SPeter Tyser	swi	r6, r0, 0x4	/* reset address */
606260fb04SPeter Tyser	swi	r6, r0, 0xC	/* user vector exception */
616260fb04SPeter Tyser	swi	r6, r0, 0x14	/* interrupt */
626260fb04SPeter Tyser	swi	r6, r0, 0x24	/* hardware exception */
636260fb04SPeter Tyser
646260fb04SPeter Tyser#ifdef CONFIG_SYS_RESET_ADDRESS
656260fb04SPeter Tyser	/* reset address */
666260fb04SPeter Tyser	addik	r6, r0, CONFIG_SYS_RESET_ADDRESS
676260fb04SPeter Tyser	sw	r6, r1, r0
686260fb04SPeter Tyser	lhu	r7, r1, r0
696260fb04SPeter Tyser	shi	r7, r0, 0x2
706260fb04SPeter Tyser	shi	r6, r0, 0x6
716260fb04SPeter Tyser/*
726260fb04SPeter Tyser * Copy U-Boot code to TEXT_BASE
736260fb04SPeter Tyser * solve problem with sbrk_base
746260fb04SPeter Tyser */
756260fb04SPeter Tyser#if (CONFIG_SYS_RESET_ADDRESS != TEXT_BASE)
766260fb04SPeter Tyser	addi	r4, r0, __end
776260fb04SPeter Tyser	addi	r5, r0, __text_start
786260fb04SPeter Tyser	rsub	r4, r5, r4	/* size = __end - __text_start */
796260fb04SPeter Tyser	addi	r6, r0, CONFIG_SYS_RESET_ADDRESS	/* source address */
806260fb04SPeter Tyser	addi	r7, r0, 0	/* counter */
816260fb04SPeter Tyser4:
826260fb04SPeter Tyser	lw	r8, r6, r7
836260fb04SPeter Tyser	sw	r8, r5, r7
846260fb04SPeter Tyser	addi	r7, r7, 0x4
856260fb04SPeter Tyser	cmp	r8, r4, r7
866260fb04SPeter Tyser	blti	r8, 4b
876260fb04SPeter Tyser#endif
886260fb04SPeter Tyser#endif
896260fb04SPeter Tyser
906260fb04SPeter Tyser#ifdef CONFIG_SYS_USR_EXCEP
916260fb04SPeter Tyser	/* user_vector_exception */
926260fb04SPeter Tyser	addik	r6, r0, _exception_handler
936260fb04SPeter Tyser	sw	r6, r1, r0
94*b98cba09SMichal Simek	/*
95*b98cba09SMichal Simek	 * BIG ENDIAN memory map for user exception
96*b98cba09SMichal Simek	 * 0x8: 0xB000XXXX
97*b98cba09SMichal Simek	 * 0xC: 0xB808XXXX
98*b98cba09SMichal Simek	 *
99*b98cba09SMichal Simek	 * then it is necessary to count address for storing the most significant
100*b98cba09SMichal Simek	 * 16bits from _exception_handler address and copy it to
101*b98cba09SMichal Simek	 * 0xa address. Big endian use offset in r10=0 that's why is it just
102*b98cba09SMichal Simek	 * 0xa address. The same is done for the least significant 16 bits
103*b98cba09SMichal Simek	 * for 0xe address.
104*b98cba09SMichal Simek	 *
105*b98cba09SMichal Simek	 * LITTLE ENDIAN memory map for user exception
106*b98cba09SMichal Simek	 * 0x8: 0xXXXX00B0
107*b98cba09SMichal Simek	 * 0xC: 0xXXXX08B8
108*b98cba09SMichal Simek	 *
109*b98cba09SMichal Simek	 * Offset is for little endian setup to 0x2. rsubi instruction decrease
110*b98cba09SMichal Simek	 * address value to ensure that points to proper place which is
111*b98cba09SMichal Simek	 * 0x8 for the most significant 16 bits and
112*b98cba09SMichal Simek	 * 0xC for the least significant 16 bits
113*b98cba09SMichal Simek	 */
114*b98cba09SMichal Simek	lhu	r7, r1, r10
115*b98cba09SMichal Simek	rsubi	r8, r10, 0xa
116*b98cba09SMichal Simek	sh	r7, r0, r8
117*b98cba09SMichal Simek	rsubi	r8, r10, 0xe
118*b98cba09SMichal Simek	sh	r6, r0, r8
1196260fb04SPeter Tyser#endif
1206260fb04SPeter Tyser
1216260fb04SPeter Tyser#ifdef CONFIG_SYS_INTC_0
1226260fb04SPeter Tyser	/* interrupt_handler */
1236260fb04SPeter Tyser	addik	r6, r0, _interrupt_handler
1246260fb04SPeter Tyser	sw	r6, r1, r0
125*b98cba09SMichal Simek	lhu	r7, r1, r10
126*b98cba09SMichal Simek	rsubi	r8, r10, 0x12
127*b98cba09SMichal Simek	sh	r7, r0, r8
128*b98cba09SMichal Simek	rsubi	r8, r10, 0x16
129*b98cba09SMichal Simek	sh	r6, r0, r8
1306260fb04SPeter Tyser#endif
1316260fb04SPeter Tyser
1326260fb04SPeter Tyser	/* hardware exception */
1336260fb04SPeter Tyser	addik	r6, r0, _hw_exception_handler
1346260fb04SPeter Tyser	sw	r6, r1, r0
135*b98cba09SMichal Simek	lhu	r7, r1, r10
136*b98cba09SMichal Simek	rsubi	r8, r10, 0x22
137*b98cba09SMichal Simek	sh	r7, r0, r8
138*b98cba09SMichal Simek	rsubi	r8, r10, 0x26
139*b98cba09SMichal Simek	sh	r6, r0, r8
1406260fb04SPeter Tyser
1416260fb04SPeter Tyser	/* enable instruction and data cache */
1426260fb04SPeter Tyser	mfs	r12, rmsr
1436260fb04SPeter Tyser	ori	r12, r12, 0xa0
1446260fb04SPeter Tyser	mts	rmsr, r12
1456260fb04SPeter Tyser
1466260fb04SPeter Tyserclear_bss:
1476260fb04SPeter Tyser	/* clear BSS segments */
1486260fb04SPeter Tyser	addi	r5, r0, __bss_start
1496260fb04SPeter Tyser	addi	r4, r0, __bss_end
1506260fb04SPeter Tyser	cmp	r6, r5, r4
1516260fb04SPeter Tyser	beqi	r6, 3f
1526260fb04SPeter Tyser2:
1536260fb04SPeter Tyser	swi     r0, r5, 0 /* write zero to loc */
1546260fb04SPeter Tyser	addi    r5, r5, 4 /* increment to next loc */
1556260fb04SPeter Tyser	cmp     r6, r5, r4 /* check if we have reach the end */
1566260fb04SPeter Tyser	bnei    r6, 2b
1576260fb04SPeter Tyser3:	/* jumping to board_init */
1586260fb04SPeter Tyser	brai	board_init
1596260fb04SPeter Tyser1:	bri	1b
1606260fb04SPeter Tyser
1616260fb04SPeter Tyser/*
1626260fb04SPeter Tyser * Read 16bit little endian
1636260fb04SPeter Tyser */
1646260fb04SPeter Tyser	.text
1656260fb04SPeter Tyser	.global	in16
1666260fb04SPeter Tyser	.ent	in16
1676260fb04SPeter Tyser	.align	2
1686260fb04SPeter Tyserin16:	lhu	r3, r0, r5
1696260fb04SPeter Tyser	bslli	r4, r3, 8
1706260fb04SPeter Tyser	bsrli	r3, r3, 8
1716260fb04SPeter Tyser	andi	r4, r4, 0xffff
1726260fb04SPeter Tyser	or	r3, r3, r4
1736260fb04SPeter Tyser	rtsd	r15, 8
1746260fb04SPeter Tyser	sext16	r3, r3
1756260fb04SPeter Tyser	.end	in16
1766260fb04SPeter Tyser
1776260fb04SPeter Tyser/*
1786260fb04SPeter Tyser * Write 16bit little endian
1796260fb04SPeter Tyser * first parameter(r5) - address, second(r6) - short value
1806260fb04SPeter Tyser */
1816260fb04SPeter Tyser	.text
1826260fb04SPeter Tyser	.global	out16
1836260fb04SPeter Tyser	.ent	out16
1846260fb04SPeter Tyser	.align	2
1856260fb04SPeter Tyserout16:	bslli	r3, r6, 8
1866260fb04SPeter Tyser	bsrli	r6, r6, 8
1876260fb04SPeter Tyser	andi	r3, r3, 0xffff
1886260fb04SPeter Tyser	or	r3, r3, r6
1896260fb04SPeter Tyser	sh	r3, r0, r5
1906260fb04SPeter Tyser	rtsd	r15, 8
1916260fb04SPeter Tyser	or	r0, r0, r0
1926260fb04SPeter Tyser	.end	out16
193