blob: 892802483878b3b42ba061c287762457faa20214 [file] [log] [blame]
wdenk507bbe32004-04-18 21:13:41 +00001/*
Michal Simekcfc67112007-03-11 13:48:24 +01002 * (C) Copyright 2007 Michal Simek
wdenk507bbe32004-04-18 21:13:41 +00003 * (C) Copyright 2004 Atmark Techno, Inc.
4 *
Michal Simekcfc67112007-03-11 13:48:24 +01005 * Michal SIMEK <monstr@monstr.eu>
wdenk507bbe32004-04-18 21:13:41 +00006 * Yasushi SHOJI <yashi@atmark-techno.com>
7 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenk507bbe32004-04-18 21:13:41 +00009 */
10
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020011#include <asm-offsets.h>
wdenk507bbe32004-04-18 21:13:41 +000012#include <config.h>
13
14 .text
15 .global _start
16_start:
Michal Simek86c1b2a2011-07-21 10:47:21 +020017 /*
18 * reserve registers:
19 * r10: Stores little/big endian offset for vectors
20 * r2: Stores imm opcode
21 * r3: Stores brai opcode
22 */
23
Michal Simekcfc67112007-03-11 13:48:24 +010024 mts rmsr, r0 /* disable cache */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020025 addi r1, r0, CONFIG_SYS_INIT_SP_OFFSET
Michal Simek17980492007-03-26 01:39:07 +020026 addi r1, r1, -4 /* Decrement SP to top of memory */
Michal Simekb98cba02010-08-12 11:47:11 +020027
28 /* Find-out if u-boot is running on BIG/LITTLE endian platform
29 * There are some steps which is necessary to keep in mind:
30 * 1. Setup offset value to r6
31 * 2. Store word offset value to address 0x0
32 * 3. Load just byte from address 0x0
33 * 4a) LITTLE endian - r10 contains 0x2 because it is the smallest
34 * value that's why is on address 0x0
35 * 4b) BIG endian - r10 contains 0x0 because 0x2 offset is on addr 0x3
36 */
37 addik r6, r0, 0x2 /* BIG/LITTLE endian offset */
Michal Simekf3090fc2010-11-15 09:54:43 +000038 lwi r7, r0, 0x28
39 swi r6, r0, 0x28 /* used first unused MB vector */
40 lbui r10, r0, 0x28 /* used first unused MB vector */
41 swi r7, r0, 0x28
Michal Simekb98cba02010-08-12 11:47:11 +020042
Michal Simek86c1b2a2011-07-21 10:47:21 +020043 /* add opcode instruction for 32bit jump - 2 instruction imm & brai */
44 addi r2, r0, 0xb0000000 /* hex b000 opcode imm */
45 addi r3, r0, 0xb8080000 /* hew b808 opcode brai */
wdenk507bbe32004-04-18 21:13:41 +000046
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020047#ifdef CONFIG_SYS_RESET_ADDRESS
Michal Simekcfc67112007-03-11 13:48:24 +010048 /* reset address */
Michal Simek86c1b2a2011-07-21 10:47:21 +020049 swi r2, r0, 0x0 /* reset address - imm opcode */
50 swi r3, r0, 0x4 /* reset address - brai opcode */
51
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020052 addik r6, r0, CONFIG_SYS_RESET_ADDRESS
Michal Simekcfc67112007-03-11 13:48:24 +010053 sw r6, r1, r0
Michal Simek5562bcc2011-08-30 15:22:24 +020054 lhu r7, r1, r10
55 rsubi r8, r10, 0x2
56 sh r7, r0, r8
57 rsubi r8, r10, 0x6
58 sh r6, r0, r8
Michal Simekcfc67112007-03-11 13:48:24 +010059#endif
60
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020061#ifdef CONFIG_SYS_USR_EXCEP
Michal Simekcfc67112007-03-11 13:48:24 +010062 /* user_vector_exception */
Michal Simek86c1b2a2011-07-21 10:47:21 +020063 swi r2, r0, 0x8 /* user vector exception - imm opcode */
64 swi r3, r0, 0xC /* user vector exception - brai opcode */
65
Michal Simekcfc67112007-03-11 13:48:24 +010066 addik r6, r0, _exception_handler
67 sw r6, r1, r0
Michal Simekb98cba02010-08-12 11:47:11 +020068 /*
69 * BIG ENDIAN memory map for user exception
70 * 0x8: 0xB000XXXX
71 * 0xC: 0xB808XXXX
72 *
73 * then it is necessary to count address for storing the most significant
Wolfgang Denk071bc922010-10-27 22:48:30 +020074 * 16bits from _exception_handler address and copy it to
Michal Simekb98cba02010-08-12 11:47:11 +020075 * 0xa address. Big endian use offset in r10=0 that's why is it just
76 * 0xa address. The same is done for the least significant 16 bits
77 * for 0xe address.
78 *
79 * LITTLE ENDIAN memory map for user exception
80 * 0x8: 0xXXXX00B0
81 * 0xC: 0xXXXX08B8
82 *
83 * Offset is for little endian setup to 0x2. rsubi instruction decrease
84 * address value to ensure that points to proper place which is
85 * 0x8 for the most significant 16 bits and
86 * 0xC for the least significant 16 bits
87 */
88 lhu r7, r1, r10
89 rsubi r8, r10, 0xa
90 sh r7, r0, r8
91 rsubi r8, r10, 0xe
92 sh r6, r0, r8
Michal Simekcfc67112007-03-11 13:48:24 +010093#endif
94
Michal Simekcfc67112007-03-11 13:48:24 +010095 /* interrupt_handler */
Michal Simek86c1b2a2011-07-21 10:47:21 +020096 swi r2, r0, 0x10 /* interrupt - imm opcode */
97 swi r3, r0, 0x14 /* interrupt - brai opcode */
98
Michal Simekcfc67112007-03-11 13:48:24 +010099 addik r6, r0, _interrupt_handler
100 sw r6, r1, r0
Michal Simekb98cba02010-08-12 11:47:11 +0200101 lhu r7, r1, r10
102 rsubi r8, r10, 0x12
103 sh r7, r0, r8
104 rsubi r8, r10, 0x16
105 sh r6, r0, r8
Michal Simekcfc67112007-03-11 13:48:24 +0100106
107 /* hardware exception */
Michal Simek86c1b2a2011-07-21 10:47:21 +0200108 swi r2, r0, 0x20 /* hardware exception - imm opcode */
109 swi r3, r0, 0x24 /* hardware exception - brai opcode */
110
Michal Simekcfc67112007-03-11 13:48:24 +0100111 addik r6, r0, _hw_exception_handler
112 sw r6, r1, r0
Michal Simekb98cba02010-08-12 11:47:11 +0200113 lhu r7, r1, r10
114 rsubi r8, r10, 0x22
115 sh r7, r0, r8
116 rsubi r8, r10, 0x26
117 sh r6, r0, r8
Michal Simekcfc67112007-03-11 13:48:24 +0100118
Michal Simek58118302012-09-25 10:13:35 +0200119 /* Flush cache before enable cache */
120 addik r5, r0, 0
121 addik r6, r0, XILINX_DCACHE_BYTE_SIZE
122flush: bralid r15, flush_cache
123 nop
124
Michal Simekcfc67112007-03-11 13:48:24 +0100125 /* enable instruction and data cache */
126 mfs r12, rmsr
127 ori r12, r12, 0xa0
128 mts rmsr, r12
129
Michal Simek17980492007-03-26 01:39:07 +0200130clear_bss:
131 /* clear BSS segments */
132 addi r5, r0, __bss_start
133 addi r4, r0, __bss_end
134 cmp r6, r5, r4
135 beqi r6, 3f
1362:
137 swi r0, r5, 0 /* write zero to loc */
138 addi r5, r5, 4 /* increment to next loc */
139 cmp r6, r5, r4 /* check if we have reach the end */
140 bnei r6, 2b
1413: /* jumping to board_init */
Michal Simek2380b8f2012-07-04 13:12:37 +0200142 brai board_init_f
wdenk507bbe32004-04-18 21:13:41 +00001431: bri 1b
Michal Simek06436312007-04-21 21:02:40 +0200144
145/*
146 * Read 16bit little endian
147 */
148 .text
149 .global in16
150 .ent in16
151 .align 2
152in16: lhu r3, r0, r5
153 bslli r4, r3, 8
154 bsrli r3, r3, 8
155 andi r4, r4, 0xffff
156 or r3, r3, r4
157 rtsd r15, 8
158 sext16 r3, r3
159 .end in16
160
161/*
162 * Write 16bit little endian
163 * first parameter(r5) - address, second(r6) - short value
164 */
165 .text
166 .global out16
167 .ent out16
168 .align 2
169out16: bslli r3, r6, 8
170 bsrli r6, r6, 8
171 andi r3, r3, 0xffff
172 or r3, r3, r6
173 sh r3, r0, r5
174 rtsd r15, 8
175 or r0, r0, r0
176 .end out16