2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2004-10-10 21:27:30 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2004, Psyent Corporation <www.psyent.com>
|
|
|
|
* Scott McNutt <smcnutt@psyent.com>
|
|
|
|
*/
|
|
|
|
|
2010-10-26 12:34:52 +00:00
|
|
|
#include <asm-offsets.h>
|
2004-10-10 21:27:30 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2015-10-09 12:09:17 +00:00
|
|
|
/*
|
|
|
|
* icache and dcache configuration used only for start.S.
|
|
|
|
* the values are chosen so that it will work for all configuration.
|
|
|
|
*/
|
|
|
|
#define ICACHE_LINE_SIZE 32 /* fixed 32 */
|
|
|
|
#define ICACHE_SIZE_MAX 0x10000 /* 64k max */
|
|
|
|
#define DCACHE_LINE_SIZE_MIN 4 /* 4, 16, 32 */
|
|
|
|
#define DCACHE_SIZE_MAX 0x10000 /* 64k max */
|
|
|
|
|
2015-10-06 02:12:59 +00:00
|
|
|
/* RESTART */
|
2004-10-10 21:27:30 +00:00
|
|
|
.text
|
2015-10-06 06:09:19 +00:00
|
|
|
.global _start, _except_start, _except_end
|
2004-10-10 21:27:30 +00:00
|
|
|
|
|
|
|
_start:
|
2010-04-20 03:01:11 +00:00
|
|
|
wrctl status, r0 /* Disable interrupts */
|
2015-10-06 02:12:59 +00:00
|
|
|
/*
|
|
|
|
* ICACHE INIT -- only the icache line at the reset address
|
2004-10-10 21:27:30 +00:00
|
|
|
* is invalidated at reset. So the init must stay within
|
|
|
|
* the cache line size (8 words). If GERMS is used, we'll
|
|
|
|
* just be invalidating the cache a second time. If cache
|
|
|
|
* is not implemented initi behaves as nop.
|
|
|
|
*/
|
2015-10-09 12:09:17 +00:00
|
|
|
ori r4, r0, %lo(ICACHE_LINE_SIZE)
|
|
|
|
movhi r5, %hi(ICACHE_SIZE_MAX)
|
|
|
|
ori r5, r5, %lo(ICACHE_SIZE_MAX)
|
2010-04-20 03:01:11 +00:00
|
|
|
0: initi r5
|
|
|
|
sub r5, r5, r4
|
|
|
|
bgt r5, r0, 0b
|
2005-03-30 23:28:18 +00:00
|
|
|
br _except_end /* Skip the tramp */
|
|
|
|
|
2015-10-06 02:12:59 +00:00
|
|
|
/*
|
|
|
|
* EXCEPTION TRAMPOLINE -- the following gets copied
|
2005-03-30 23:28:18 +00:00
|
|
|
* to the exception address (below), but is otherwise at the
|
|
|
|
* default exception vector offset (0x0020).
|
|
|
|
*/
|
|
|
|
_except_start:
|
|
|
|
movhi et, %hi(_exception)
|
|
|
|
ori et, et, %lo(_exception)
|
|
|
|
jmp et
|
|
|
|
_except_end:
|
2004-10-10 21:27:30 +00:00
|
|
|
|
2015-10-06 02:12:59 +00:00
|
|
|
/*
|
|
|
|
* INTERRUPTS -- for now, all interrupts masked and globally
|
2004-10-10 21:27:30 +00:00
|
|
|
* disabled.
|
|
|
|
*/
|
|
|
|
wrctl ienable, r0 /* All disabled */
|
|
|
|
|
2015-10-06 02:12:59 +00:00
|
|
|
/*
|
|
|
|
* DCACHE INIT -- if dcache not implemented, initd behaves as
|
2004-10-10 21:27:30 +00:00
|
|
|
* nop.
|
|
|
|
*/
|
2015-10-09 12:09:17 +00:00
|
|
|
ori r4, r0, %lo(DCACHE_LINE_SIZE_MIN)
|
|
|
|
movhi r5, %hi(DCACHE_SIZE_MAX)
|
|
|
|
ori r5, r5, %lo(DCACHE_SIZE_MAX)
|
2004-10-10 21:27:30 +00:00
|
|
|
mov r6, r0
|
|
|
|
1: initd 0(r6)
|
|
|
|
add r6, r6, r4
|
|
|
|
bltu r6, r5, 1b
|
|
|
|
|
2015-10-06 02:12:59 +00:00
|
|
|
/*
|
|
|
|
* RELOCATE CODE, DATA & COMMAND TABLE -- the following code
|
2004-10-10 21:27:30 +00:00
|
|
|
* assumes code, data and the command table are all
|
|
|
|
* contiguous. This lets us relocate everything as a single
|
|
|
|
* block. Make sure the linker script matches this ;-)
|
|
|
|
*/
|
|
|
|
nextpc r4
|
|
|
|
_cur: movhi r5, %hi(_cur - _start)
|
|
|
|
ori r5, r5, %lo(_cur - _start)
|
|
|
|
sub r4, r4, r5 /* r4 <- cur _start */
|
|
|
|
mov r8, r4
|
|
|
|
movhi r5, %hi(_start)
|
|
|
|
ori r5, r5, %lo(_start) /* r5 <- linked _start */
|
2015-11-03 05:47:02 +00:00
|
|
|
mov sp, r5 /* initial stack below u-boot code */
|
2004-10-10 21:27:30 +00:00
|
|
|
beq r4, r5, 3f
|
|
|
|
|
2015-09-04 08:39:16 +00:00
|
|
|
movhi r6, %hi(CONFIG_SYS_MONITOR_LEN)
|
|
|
|
ori r6, r6, %lo(CONFIG_SYS_MONITOR_LEN)
|
|
|
|
add r6, r6, r5
|
2004-10-10 21:27:30 +00:00
|
|
|
2: ldwio r7, 0(r4)
|
|
|
|
addi r4, r4, 4
|
|
|
|
stwio r7, 0(r5)
|
|
|
|
addi r5, r5, 4
|
|
|
|
bne r5, r6, 2b
|
|
|
|
3:
|
|
|
|
|
|
|
|
/* JUMP TO RELOC ADDR */
|
|
|
|
movhi r4, %hi(_reloc)
|
|
|
|
ori r4, r4, %lo(_reloc)
|
|
|
|
jmp r4
|
|
|
|
_reloc:
|
|
|
|
|
2015-10-06 02:12:59 +00:00
|
|
|
/* STACK INIT -- zero top two words for call back chain. */
|
2004-10-10 21:27:30 +00:00
|
|
|
addi sp, sp, -8
|
|
|
|
stw r0, 0(sp)
|
|
|
|
stw r0, 4(sp)
|
|
|
|
mov fp, sp
|
|
|
|
|
2015-12-30 12:29:18 +00:00
|
|
|
#ifdef CONFIG_DEBUG_UART
|
|
|
|
/* Set up the debug UART */
|
|
|
|
movhi r2, %hi(debug_uart_init@h)
|
|
|
|
ori r2, r2, %lo(debug_uart_init@h)
|
|
|
|
callr r2
|
|
|
|
#endif
|
|
|
|
|
2015-11-25 16:56:32 +00:00
|
|
|
/* Allocate and initialize reserved area, update SP */
|
2015-09-09 07:09:43 +00:00
|
|
|
mov r4, sp
|
2015-11-25 16:56:32 +00:00
|
|
|
movhi r2, %hi(board_init_f_alloc_reserve@h)
|
|
|
|
ori r2, r2, %lo(board_init_f_alloc_reserve@h)
|
2015-09-09 07:09:43 +00:00
|
|
|
callr r2
|
|
|
|
mov sp, r2
|
2015-11-25 16:56:32 +00:00
|
|
|
mov r4, sp
|
|
|
|
movhi r2, %hi(board_init_f_init_reserve@h)
|
|
|
|
ori r2, r2, %lo(board_init_f_init_reserve@h)
|
|
|
|
callr r2
|
|
|
|
|
|
|
|
/* Update frame-pointer */
|
2015-09-09 07:09:43 +00:00
|
|
|
mov fp, sp
|
|
|
|
|
2015-10-06 02:12:59 +00:00
|
|
|
/* Call board_init_f -- never returns */
|
2014-08-22 03:36:47 +00:00
|
|
|
mov r4, r0
|
|
|
|
movhi r2, %hi(board_init_f@h)
|
|
|
|
ori r2, r2, %lo(board_init_f@h)
|
|
|
|
callr r2
|
2004-10-10 21:27:30 +00:00
|
|
|
|
2015-10-06 02:12:59 +00:00
|
|
|
/*
|
|
|
|
* NEVER RETURNS -- but branch to the _start just
|
2004-10-10 21:27:30 +00:00
|
|
|
* in case ;-)
|
|
|
|
*/
|
|
|
|
br _start
|
|
|
|
|
2015-10-06 02:12:59 +00:00
|
|
|
/*
|
|
|
|
* relocate_code -- Nios2 handles the relocation above. But
|
|
|
|
* the generic board code monkeys with the heap, stack, etc.
|
|
|
|
* (it makes some assumptions that may not be appropriate
|
|
|
|
* for Nios). Nevertheless, we capitulate here.
|
|
|
|
*
|
|
|
|
* We'll call the board_init_r from here since this isn't
|
|
|
|
* supposed to return.
|
|
|
|
*
|
2019-12-28 17:44:45 +00:00
|
|
|
* void relocate_code(ulong sp, gd_t *global_data,
|
2015-10-06 02:12:59 +00:00
|
|
|
* ulong reloc_addr)
|
|
|
|
* __attribute__ ((noreturn));
|
|
|
|
*/
|
2014-08-22 03:36:47 +00:00
|
|
|
.text
|
|
|
|
.global relocate_code
|
|
|
|
|
|
|
|
relocate_code:
|
|
|
|
mov sp, r4 /* Set the new sp */
|
|
|
|
mov r4, r5
|
2015-09-07 00:57:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ZERO BSS/SBSS -- bss and sbss are assumed to be adjacent
|
|
|
|
* and between __bss_start and __bss_end.
|
|
|
|
*/
|
|
|
|
movhi r5, %hi(__bss_start)
|
|
|
|
ori r5, r5, %lo(__bss_start)
|
|
|
|
movhi r6, %hi(__bss_end)
|
|
|
|
ori r6, r6, %lo(__bss_end)
|
|
|
|
beq r5, r6, 5f
|
|
|
|
|
2015-11-03 05:52:15 +00:00
|
|
|
4: stw r0, 0(r5)
|
2015-09-07 00:57:14 +00:00
|
|
|
addi r5, r5, 4
|
|
|
|
bne r5, r6, 4b
|
|
|
|
5:
|
|
|
|
|
2014-08-22 03:36:47 +00:00
|
|
|
movhi r8, %hi(board_init_r@h)
|
|
|
|
ori r8, r8, %lo(board_init_r@h)
|
|
|
|
callr r8
|
|
|
|
ret
|