Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2004, Psyent Corporation <www.psyent.com> |
| 4 | * Scott McNutt <smcnutt@psyent.com> |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 7 | #include <asm-offsets.h> |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 8 | #include <config.h> |
| 9 | #include <version.h> |
| 10 | |
Thomas Chou | 55e2b4d | 2015-10-09 20:09:17 +0800 | [diff] [blame] | 11 | /* |
| 12 | * icache and dcache configuration used only for start.S. |
| 13 | * the values are chosen so that it will work for all configuration. |
| 14 | */ |
| 15 | #define ICACHE_LINE_SIZE 32 /* fixed 32 */ |
| 16 | #define ICACHE_SIZE_MAX 0x10000 /* 64k max */ |
| 17 | #define DCACHE_LINE_SIZE_MIN 4 /* 4, 16, 32 */ |
| 18 | #define DCACHE_SIZE_MAX 0x10000 /* 64k max */ |
| 19 | |
Thomas Chou | 4a572fa | 2015-10-06 10:12:59 +0800 | [diff] [blame] | 20 | /* RESTART */ |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 21 | .text |
Thomas Chou | b811209 | 2015-10-06 14:09:19 +0800 | [diff] [blame] | 22 | .global _start, _except_start, _except_end |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 23 | |
| 24 | _start: |
Thomas Chou | fd2712d | 2010-04-20 11:01:11 +0800 | [diff] [blame] | 25 | wrctl status, r0 /* Disable interrupts */ |
Thomas Chou | 4a572fa | 2015-10-06 10:12:59 +0800 | [diff] [blame] | 26 | /* |
| 27 | * ICACHE INIT -- only the icache line at the reset address |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 28 | * is invalidated at reset. So the init must stay within |
| 29 | * the cache line size (8 words). If GERMS is used, we'll |
| 30 | * just be invalidating the cache a second time. If cache |
| 31 | * is not implemented initi behaves as nop. |
| 32 | */ |
Thomas Chou | 55e2b4d | 2015-10-09 20:09:17 +0800 | [diff] [blame] | 33 | ori r4, r0, %lo(ICACHE_LINE_SIZE) |
| 34 | movhi r5, %hi(ICACHE_SIZE_MAX) |
| 35 | ori r5, r5, %lo(ICACHE_SIZE_MAX) |
Thomas Chou | fd2712d | 2010-04-20 11:01:11 +0800 | [diff] [blame] | 36 | 0: initi r5 |
| 37 | sub r5, r5, r4 |
| 38 | bgt r5, r0, 0b |
wdenk | 0c1c117c | 2005-03-30 23:28:18 +0000 | [diff] [blame] | 39 | br _except_end /* Skip the tramp */ |
| 40 | |
Thomas Chou | 4a572fa | 2015-10-06 10:12:59 +0800 | [diff] [blame] | 41 | /* |
| 42 | * EXCEPTION TRAMPOLINE -- the following gets copied |
wdenk | 0c1c117c | 2005-03-30 23:28:18 +0000 | [diff] [blame] | 43 | * to the exception address (below), but is otherwise at the |
| 44 | * default exception vector offset (0x0020). |
| 45 | */ |
| 46 | _except_start: |
| 47 | movhi et, %hi(_exception) |
| 48 | ori et, et, %lo(_exception) |
| 49 | jmp et |
| 50 | _except_end: |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 51 | |
Thomas Chou | 4a572fa | 2015-10-06 10:12:59 +0800 | [diff] [blame] | 52 | /* |
| 53 | * INTERRUPTS -- for now, all interrupts masked and globally |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 54 | * disabled. |
| 55 | */ |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 56 | wrctl ienable, r0 /* All disabled */ |
| 57 | |
Thomas Chou | 4a572fa | 2015-10-06 10:12:59 +0800 | [diff] [blame] | 58 | /* |
| 59 | * DCACHE INIT -- if dcache not implemented, initd behaves as |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 60 | * nop. |
| 61 | */ |
Thomas Chou | 55e2b4d | 2015-10-09 20:09:17 +0800 | [diff] [blame] | 62 | ori r4, r0, %lo(DCACHE_LINE_SIZE_MIN) |
| 63 | movhi r5, %hi(DCACHE_SIZE_MAX) |
| 64 | ori r5, r5, %lo(DCACHE_SIZE_MAX) |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 65 | mov r6, r0 |
| 66 | 1: initd 0(r6) |
| 67 | add r6, r6, r4 |
| 68 | bltu r6, r5, 1b |
| 69 | |
Thomas Chou | 4a572fa | 2015-10-06 10:12:59 +0800 | [diff] [blame] | 70 | /* |
| 71 | * RELOCATE CODE, DATA & COMMAND TABLE -- the following code |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 72 | * assumes code, data and the command table are all |
| 73 | * contiguous. This lets us relocate everything as a single |
| 74 | * block. Make sure the linker script matches this ;-) |
| 75 | */ |
| 76 | nextpc r4 |
| 77 | _cur: movhi r5, %hi(_cur - _start) |
| 78 | ori r5, r5, %lo(_cur - _start) |
| 79 | sub r4, r4, r5 /* r4 <- cur _start */ |
| 80 | mov r8, r4 |
| 81 | movhi r5, %hi(_start) |
| 82 | ori r5, r5, %lo(_start) /* r5 <- linked _start */ |
Thomas Chou | 65af9f6 | 2015-11-03 13:47:02 +0800 | [diff] [blame] | 83 | mov sp, r5 /* initial stack below u-boot code */ |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 84 | beq r4, r5, 3f |
| 85 | |
Thomas Chou | e900298 | 2015-09-04 16:39:16 +0800 | [diff] [blame] | 86 | movhi r6, %hi(CONFIG_SYS_MONITOR_LEN) |
| 87 | ori r6, r6, %lo(CONFIG_SYS_MONITOR_LEN) |
| 88 | add r6, r6, r5 |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 89 | 2: ldwio r7, 0(r4) |
| 90 | addi r4, r4, 4 |
| 91 | stwio r7, 0(r5) |
| 92 | addi r5, r5, 4 |
| 93 | bne r5, r6, 2b |
| 94 | 3: |
| 95 | |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 96 | /* JUMP TO RELOC ADDR */ |
| 97 | movhi r4, %hi(_reloc) |
| 98 | ori r4, r4, %lo(_reloc) |
| 99 | jmp r4 |
| 100 | _reloc: |
| 101 | |
Thomas Chou | 4a572fa | 2015-10-06 10:12:59 +0800 | [diff] [blame] | 102 | /* STACK INIT -- zero top two words for call back chain. */ |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 103 | addi sp, sp, -8 |
| 104 | stw r0, 0(sp) |
| 105 | stw r0, 4(sp) |
| 106 | mov fp, sp |
| 107 | |
Thomas Chou | e4f348b | 2015-12-30 20:29:18 +0800 | [diff] [blame] | 108 | #ifdef CONFIG_DEBUG_UART |
| 109 | /* Set up the debug UART */ |
| 110 | movhi r2, %hi(debug_uart_init@h) |
| 111 | ori r2, r2, %lo(debug_uart_init@h) |
| 112 | callr r2 |
| 113 | #endif |
| 114 | |
Albert ARIBAUD | ecc3066 | 2015-11-25 17:56:32 +0100 | [diff] [blame] | 115 | /* Allocate and initialize reserved area, update SP */ |
Thomas Chou | 3e468e6 | 2015-09-09 15:09:43 +0800 | [diff] [blame] | 116 | mov r4, sp |
Albert ARIBAUD | ecc3066 | 2015-11-25 17:56:32 +0100 | [diff] [blame] | 117 | movhi r2, %hi(board_init_f_alloc_reserve@h) |
| 118 | ori r2, r2, %lo(board_init_f_alloc_reserve@h) |
| 119 | callr r2 |
| 120 | mov sp, r2 |
| 121 | mov r4, sp |
| 122 | movhi r2, %hi(board_init_f_init_reserve@h) |
| 123 | ori r2, r2, %lo(board_init_f_init_reserve@h) |
Thomas Chou | 3e468e6 | 2015-09-09 15:09:43 +0800 | [diff] [blame] | 124 | callr r2 |
| 125 | |
Albert ARIBAUD | ecc3066 | 2015-11-25 17:56:32 +0100 | [diff] [blame] | 126 | /* Update frame-pointer */ |
Thomas Chou | 3e468e6 | 2015-09-09 15:09:43 +0800 | [diff] [blame] | 127 | mov fp, sp |
| 128 | |
Thomas Chou | 4a572fa | 2015-10-06 10:12:59 +0800 | [diff] [blame] | 129 | /* Call board_init_f -- never returns */ |
Thomas Chou | 5ff10aa | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 130 | mov r4, r0 |
| 131 | movhi r2, %hi(board_init_f@h) |
| 132 | ori r2, r2, %lo(board_init_f@h) |
| 133 | callr r2 |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 134 | |
Thomas Chou | 4a572fa | 2015-10-06 10:12:59 +0800 | [diff] [blame] | 135 | /* |
| 136 | * NEVER RETURNS -- but branch to the _start just |
wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 137 | * in case ;-) |
| 138 | */ |
| 139 | br _start |
| 140 | |
Thomas Chou | 4a572fa | 2015-10-06 10:12:59 +0800 | [diff] [blame] | 141 | /* |
| 142 | * relocate_code -- Nios2 handles the relocation above. But |
| 143 | * the generic board code monkeys with the heap, stack, etc. |
| 144 | * (it makes some assumptions that may not be appropriate |
| 145 | * for Nios). Nevertheless, we capitulate here. |
| 146 | * |
| 147 | * We'll call the board_init_r from here since this isn't |
| 148 | * supposed to return. |
| 149 | * |
Simon Glass | 9413387 | 2019-12-28 10:44:45 -0700 | [diff] [blame] | 150 | * void relocate_code(ulong sp, gd_t *global_data, |
Thomas Chou | 4a572fa | 2015-10-06 10:12:59 +0800 | [diff] [blame] | 151 | * ulong reloc_addr) |
| 152 | * __attribute__ ((noreturn)); |
| 153 | */ |
Thomas Chou | 5ff10aa | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 154 | .text |
| 155 | .global relocate_code |
| 156 | |
| 157 | relocate_code: |
| 158 | mov sp, r4 /* Set the new sp */ |
| 159 | mov r4, r5 |
Thomas Chou | 4192b8c | 2015-09-07 08:57:14 +0800 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent |
| 163 | * and between __bss_start and __bss_end. |
| 164 | */ |
| 165 | movhi r5, %hi(__bss_start) |
| 166 | ori r5, r5, %lo(__bss_start) |
| 167 | movhi r6, %hi(__bss_end) |
| 168 | ori r6, r6, %lo(__bss_end) |
| 169 | beq r5, r6, 5f |
| 170 | |
Thomas Chou | 9208d7e | 2015-11-03 13:52:15 +0800 | [diff] [blame] | 171 | 4: stw r0, 0(r5) |
Thomas Chou | 4192b8c | 2015-09-07 08:57:14 +0800 | [diff] [blame] | 172 | addi r5, r5, 4 |
| 173 | bne r5, r6, 4b |
| 174 | 5: |
| 175 | |
Thomas Chou | 5ff10aa | 2014-08-22 11:36:47 +0800 | [diff] [blame] | 176 | movhi r8, %hi(board_init_r@h) |
| 177 | ori r8, r8, %lo(board_init_r@h) |
| 178 | callr r8 |
| 179 | ret |