wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 1 | /* |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 2 | * (C) Copyright 2007 Michal Simek |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 3 | * (C) Copyright 2004 Atmark Techno, Inc. |
| 4 | * |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 5 | * Michal SIMEK <monstr@monstr.eu> |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 6 | * Yasushi SHOJI <yashi@atmark-techno.com> |
| 7 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 11 | #include <asm-offsets.h> |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 12 | #include <config.h> |
| 13 | |
| 14 | .text |
| 15 | .global _start |
| 16 | _start: |
Michal Simek | 86c1b2a | 2011-07-21 10:47:21 +0200 | [diff] [blame] | 17 | /* |
| 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 Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 24 | mts rmsr, r0 /* disable cache */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 25 | addi r1, r0, CONFIG_SYS_INIT_SP_OFFSET |
Michal Simek | 1798049 | 2007-03-26 01:39:07 +0200 | [diff] [blame] | 26 | addi r1, r1, -4 /* Decrement SP to top of memory */ |
Michal Simek | b98cba0 | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 27 | |
| 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 Simek | f3090fc | 2010-11-15 09:54:43 +0000 | [diff] [blame] | 38 | 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 Simek | b98cba0 | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 42 | |
Michal Simek | 86c1b2a | 2011-07-21 10:47:21 +0200 | [diff] [blame] | 43 | /* 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 */ |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 46 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 47 | #ifdef CONFIG_SYS_RESET_ADDRESS |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 48 | /* reset address */ |
Michal Simek | 86c1b2a | 2011-07-21 10:47:21 +0200 | [diff] [blame] | 49 | swi r2, r0, 0x0 /* reset address - imm opcode */ |
| 50 | swi r3, r0, 0x4 /* reset address - brai opcode */ |
| 51 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 52 | addik r6, r0, CONFIG_SYS_RESET_ADDRESS |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 53 | sw r6, r1, r0 |
Michal Simek | 5562bcc | 2011-08-30 15:22:24 +0200 | [diff] [blame] | 54 | 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 Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 59 | #endif |
| 60 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 61 | #ifdef CONFIG_SYS_USR_EXCEP |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 62 | /* user_vector_exception */ |
Michal Simek | 86c1b2a | 2011-07-21 10:47:21 +0200 | [diff] [blame] | 63 | swi r2, r0, 0x8 /* user vector exception - imm opcode */ |
| 64 | swi r3, r0, 0xC /* user vector exception - brai opcode */ |
| 65 | |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 66 | addik r6, r0, _exception_handler |
| 67 | sw r6, r1, r0 |
Michal Simek | b98cba0 | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 68 | /* |
| 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 Denk | 071bc92 | 2010-10-27 22:48:30 +0200 | [diff] [blame] | 74 | * 16bits from _exception_handler address and copy it to |
Michal Simek | b98cba0 | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 75 | * 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 Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 93 | #endif |
| 94 | |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 95 | /* interrupt_handler */ |
Michal Simek | 86c1b2a | 2011-07-21 10:47:21 +0200 | [diff] [blame] | 96 | swi r2, r0, 0x10 /* interrupt - imm opcode */ |
| 97 | swi r3, r0, 0x14 /* interrupt - brai opcode */ |
| 98 | |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 99 | addik r6, r0, _interrupt_handler |
| 100 | sw r6, r1, r0 |
Michal Simek | b98cba0 | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 101 | 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 Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 106 | |
| 107 | /* hardware exception */ |
Michal Simek | 86c1b2a | 2011-07-21 10:47:21 +0200 | [diff] [blame] | 108 | swi r2, r0, 0x20 /* hardware exception - imm opcode */ |
| 109 | swi r3, r0, 0x24 /* hardware exception - brai opcode */ |
| 110 | |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 111 | addik r6, r0, _hw_exception_handler |
| 112 | sw r6, r1, r0 |
Michal Simek | b98cba0 | 2010-08-12 11:47:11 +0200 | [diff] [blame] | 113 | 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 Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 118 | |
Michal Simek | 5811830 | 2012-09-25 10:13:35 +0200 | [diff] [blame] | 119 | /* Flush cache before enable cache */ |
| 120 | addik r5, r0, 0 |
| 121 | addik r6, r0, XILINX_DCACHE_BYTE_SIZE |
| 122 | flush: bralid r15, flush_cache |
| 123 | nop |
| 124 | |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 125 | /* enable instruction and data cache */ |
| 126 | mfs r12, rmsr |
| 127 | ori r12, r12, 0xa0 |
| 128 | mts rmsr, r12 |
| 129 | |
Michal Simek | 1798049 | 2007-03-26 01:39:07 +0200 | [diff] [blame] | 130 | clear_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 |
| 136 | 2: |
| 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 |
| 141 | 3: /* jumping to board_init */ |
Michal Simek | 2380b8f | 2012-07-04 13:12:37 +0200 | [diff] [blame] | 142 | brai board_init_f |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 143 | 1: bri 1b |
Michal Simek | 0643631 | 2007-04-21 21:02:40 +0200 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * Read 16bit little endian |
| 147 | */ |
| 148 | .text |
| 149 | .global in16 |
| 150 | .ent in16 |
| 151 | .align 2 |
| 152 | in16: 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 |
| 169 | out16: 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 |