sparc: leon3: Move ambapp_bus_init() call to arch_cpu_init() function
[oweals/u-boot.git] / arch / sparc / cpu / leon3 / start.S
index 70aee78054a3e5a09ea5532fad197f28753c2d14..1988ee1f6b6bf3566588f95ea040ad31fdbc0d67 100644 (file)
@@ -1,31 +1,49 @@
-TRAP ta 0; nop; nop; nop;
-
-/* Software trap. Treat as BAD_TRAP for the time being... */
-#define SOFT_TRAP TRAP(_hwerr)
-
-#define PSR_INIT   0x1FC0      /* Disable traps, set s and ps */
-#define WIM_INIT   2
-
-/* All traps low-level code here must end with this macro. */
-#define RESTORE_ALL b ret_trap_entry; clr %l6;
-
-#define WRITE_PAUSE nop;nop;nop
+/* This is where the SPARC/LEON3 starts
+ *
+ * Copyright (C) 2007, 2015
+ * Daniel Hellstrom, Cobham Gaisler, daniel@gaisler.com
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
 
-WINDOWSIZE = (16 * 4)
-ARGPUSHSIZE = (6 * 4)
-ARGPUSH = (WINDOWSIZE + 4)
-MINFRAME = (WINDOWSIZE + ARGPUSHSIZE + 4)
+#include <asm-offsets.h>
+#include <config.h>
+#include <asm/asmmacro.h>
+#include <asm/winmacro.h>
+#include <asm/psr.h>
+#include <asm/stack.h>
+#include <asm/leon.h>
+#include <ambapp.h>
+
+/* Default Plug&Play I/O area */
+#ifndef CONFIG_AMBAPP_IOAREA
+#define CONFIG_AMBAPP_IOAREA AMBA_DEFAULT_IOAREA
+#endif
 
-/* Number of register windows */
+/* Default number of SPARC register windows */
 #ifndef CONFIG_SYS_SPARC_NWINDOWS
-#error Must define number of SPARC register windows, default is 8
+#define CONFIG_SYS_SPARC_NWINDOWS 8
 #endif
 
-#define STACK_ALIGN    8
-#define SA(X)  (((X)+(STACK_ALIGN-1)) & ~(STACK_ALIGN-1))
-
-       .section ".start", "ax"
-       .globl  _starttate */
+/* Entry for traps which jump to a programmer-specified trap handler.  */
+#define TRAPR(H)  \
+       wr      %g0, 0xfe0, %psr; \
+       mov     %g0, %tbr; \
+       ba      (H); \
+       mov     %g0, %wim;
+
+#define TRAP(H) \
+       mov     %psr, %l0; \
+       ba      (H); \
+       nop; nop;
+
+#define TRAPI(ilevel) \
+       mov     ilevel, %l7; \
+       mov     %psr, %l0; \
+       b       _irq_entry; \
+       mov     %wim, %l3
+
+/* Unexcpected trap will halt the processor by forcing it to error state */
 #undef BAD_TRAP
 #define BAD_TRAP ta 0; nop; nop; nop;
 
@@ -50,6 +68,27 @@ MINFRAME = (WINDOWSIZE + ARGPUSHSIZE + 4)
 #error Must define number of SPARC register windows, default is 8
 #endif
 
+/* Macros to load address into a register. Uses GOT table for PIC */
+#ifdef __PIC__
+
+#define SPARC_PIC_THUNK_CALL(reg) \
+       sethi   %pc22(_GLOBAL_OFFSET_TABLE_-4), %##reg; \
+       call    __sparc_get_pc_thunk.reg; \
+        add    %##reg, %pc10(_GLOBAL_OFFSET_TABLE_+4), %##reg;
+
+#define SPARC_LOAD_ADDRESS(sym, got, reg) \
+       sethi   %gdop_hix22(sym), %##reg; \
+       xor     %##reg, %gdop_lox10(sym), %##reg; \
+       ld      [%##got + %##reg], %##reg, %gdop(sym);
+
+#else
+
+#define SPARC_PIC_THUNK_CALL(reg)
+#define SPARC_LOAD_ADDRESS(sym, got, tmp) \
+       set     sym, %##reg;
+
+#endif
+
 #define STACK_ALIGN    8
 #define SA(X)  (((X)+(STACK_ALIGN-1)) & ~(STACK_ALIGN-1))
 
@@ -169,17 +208,9 @@ _trap_table:
        SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;     ! f4-f7
        SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;     ! f8-fb
        SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;     ! fc-ff
-/*
- * Version string
- */
-
-       .data
-       .extern leon3_snooping_avail
-       .globl  version_string
-version_string:
-       .ascii U_BOOT_VERSION_STRING, "\0"
 
        .section        ".text"
+       .extern _nomem_amba_init, _nomem_memory_ctrl_init
        .align 4
 
 _hardreset:
@@ -222,7 +253,7 @@ clear_window:
        bge     clear_window
        save
 
-wininit:
+wiminit:
        set     WIM_INIT, %g3
        mov     %g3, %wim
 
@@ -231,9 +262,41 @@ stackp:
        andn    %fp, 0x0f, %fp
        sub     %fp, 64, %sp
 
+/* Obtain the address of _GLOBAL_OFFSET_TABLE_ */
+       SPARC_PIC_THUNK_CALL(l7)
+
+/* Scan AMBA Bus for AMBA buses using PnP information. All found
+ * AMBA buses I/O area will be located in i0-i5 upon return.
+ * The i0-i5 registers are later used by _nomem_amba_init2
+ */
+ambainit:
+       call    _nomem_amba_init
+        sethi  %hi(CONFIG_AMBAPP_IOAREA), %o0
+
+/* Scan AMBA Buses for memory controllers, then initialize the
+ * memory controllers. Note that before setting up the memory controller
+ * the stack can not be used.
+ */
+memory_ctrl_init:
+       SPARC_LOAD_ADDRESS(grlib_mctrl_handlers, l7, o0)
+
+       call    _nomem_memory_ctrl_init
+        nop
+
+/* The return valu indicate how many memory controllers where found and
+ * initialized, if no memory controller was initialized, we can not continue
+ * because from here on we expect memory to be working.
+ */
+       cmp     %o0, 0
+memory_ctrl_init_failed:
+       beq     memory_ctrl_init_failed
+        nop
+
+/*** From now on the stack can be used. ***/
+
 cpu_init_unreloc:
        call    cpu_init_f
-       nop
+        nop
 
 /* un relocated start address of monitor */
 #define TEXT_START _text
@@ -242,8 +305,8 @@ cpu_init_unreloc:
 #define DATA_END __init_end
 
 reloc:
-       set     TEXT_START,%g2
-       set     DATA_END,%g3
+       SPARC_LOAD_ADDRESS(TEXT_START, l7, g2)
+       SPARC_LOAD_ADDRESS(DATA_END, l7, g3)
        set     CONFIG_SYS_RELOC_MONITOR_BASE,%g4
 reloc_loop:
        ldd     [%g2],%l0
@@ -253,7 +316,7 @@ reloc_loop:
        inc     16,%g2
        subcc   %g3,%g2,%g0
        bne     reloc_loop
-       inc     16,%g4
+        inc    16,%g4
 
        clr     %l0
        clr     %l1
@@ -270,8 +333,8 @@ reloc_loop:
 
 clr_bss:
 /* clear bss area (the relocated) */
-       set     __bss_start,%g2
-       set     __bss_end,%g3
+       SPARC_LOAD_ADDRESS(__bss_start, l7, g2)
+       SPARC_LOAD_ADDRESS(__bss_end, l7, g3)
        sub     %g3,%g2,%g3
        add     %g3,%g4,%g3
        clr     %g1     /* std %g0 uses g0 and g1 */
@@ -282,19 +345,19 @@ clr_bss_16:
        inc     16,%g4
        cmp     %g3,%g4
        bne     clr_bss_16
-       nop
+        nop
 
 /* add offsets to GOT table */
 fixup_got:
-       set     __got_start,%g4
-       set     __got_end,%g3
+       SPARC_LOAD_ADDRESS(__got_start, l7, g4)
+       SPARC_LOAD_ADDRESS(__got_end, l7, g3)
 /*
  * new got offset = (old GOT-PTR (read with ld) -
  *   CONFIG_SYS_RELOC_MONITOR_BASE(from define) ) +
  *   Destination Address (from define)
  */
        set     CONFIG_SYS_RELOC_MONITOR_BASE,%g2
-       set     TEXT_START, %g1
+       SPARC_LOAD_ADDRESS(TEXT_START, l7, g1)
        add     %g4,%g2,%g4
        sub     %g4,%g1,%g4
        add     %g3,%g2,%g3
@@ -309,11 +372,11 @@ got_loop:
        inc     4,%g4
        cmp     %g3,%g4
        bne     got_loop
-       nop
+        nop
 
 prom_relocate:
-       set     __prom_start, %g2
-       set     __prom_end, %g3
+       SPARC_LOAD_ADDRESS(__prom_start, l7, g2)
+       SPARC_LOAD_ADDRESS(__prom_end, l7, g3)
        set     CONFIG_SYS_PROM_OFFSET, %g4
 
 prom_relocate_loop:
@@ -324,7 +387,7 @@ prom_relocate_loop:
        inc     16,%g2
        subcc   %g3,%g2,%g0
        bne     prom_relocate_loop
-       inc     16,%g4
+        inc    16,%g4
 
 /* Trap table has been moved, lets tell CPU about
  * the new trap table address
@@ -336,34 +399,22 @@ prom_relocate_loop:
        nop
        nop
 
-/* If CACHE snooping is available in hardware the
- * variable leon3_snooping_avail will be set to
- * 0x800000 else 0.
- */
-snoop_detect:
-       sethi   %hi(0x00800000), %o0
-       lda     [%g0] 2, %o1
-       and     %o0, %o1, %o0
-       sethi   %hi(leon3_snooping_avail+CONFIG_SYS_RELOC_MONITOR_BASE-CONFIG_SYS_TEXT_BASE), %o1
-       st      %o0, [%lo(leon3_snooping_avail+CONFIG_SYS_RELOC_MONITOR_BASE-CONFIG_SYS_TEXT_BASE)+%o1]
-
-/*     call    relocate*/
-       nop
 /* Call relocated init functions */
 jump:
-       set     cpu_init_f2,%o1
+       SPARC_LOAD_ADDRESS(cpu_init_f2, l7, o1)
        set     CONFIG_SYS_RELOC_MONITOR_BASE,%o2
        add     %o1,%o2,%o1
        sub     %o1,%g1,%o1
        call    %o1
-       clr     %o0
+        clr    %o0
 
-       set     board_init_f,%o1
+       SPARC_LOAD_ADDRESS(board_init_f, l7, o1)
        set     CONFIG_SYS_RELOC_MONITOR_BASE,%o2
+       SPARC_LOAD_ADDRESS(TEXT_START, l7, g1)
        add     %o1,%o2,%o1
        sub     %o1,%g1,%o1
        call    %o1
-       clr     %o0
+        clr    %o0
 
 dead:  ta 0                            ! if call returns...
        nop