]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/mips/cpu/xburst/start.S
Add GPL-2.0+ SPDX-License-Identifier to source files
[karo-tx-uboot.git] / arch / mips / cpu / xburst / start.S
1 /*
2  *  Startup Code for MIPS32 XBURST CPU-core
3  *
4  *  Copyright (c) 2010 Xiangfu Liu <xiangfu@sharism.cc>
5  *
6  * SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <config.h>
10 #include <version.h>
11 #include <asm/regdef.h>
12 #include <asm/mipsregs.h>
13 #include <asm/addrspace.h>
14 #include <asm/cacheops.h>
15
16         .set noreorder
17
18         .globl _start
19         .text
20 _start:
21         /* Initialize $gp */
22         bal     1f
23          nop
24         .word   _gp
25 1:
26         lw      gp, 0(ra)
27
28         /* Set up temporary stack */
29         li      sp, CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET
30
31         la      t9, board_init_f
32         jr      t9
33          nop
34
35 /*
36  * void relocate_code (addr_sp, gd, addr_moni)
37  *
38  * This "function" does not return, instead it continues in RAM
39  * after relocating the monitor code.
40  *
41  * a0 = addr_sp
42  * a1 = gd
43  * a2 = destination address
44  */
45         .globl  relocate_code
46         .ent    relocate_code
47 relocate_code:
48         move    sp, a0                  # set new stack pointer
49
50         li      t0, CONFIG_SYS_MONITOR_BASE
51         sub     t6, a2, t0              # t6 <-- relocation offset
52
53         la      t3, in_ram
54         lw      t2, -12(t3)             # t2 <-- __image_copy_end
55         move    t1, a2
56
57         add     gp, t6                  # adjust gp
58
59         /*
60          * t0 = source address
61          * t1 = target address
62          * t2 = source end address
63          */
64 1:
65         lw      t3, 0(t0)
66         sw      t3, 0(t1)
67         addu    t0, 4
68         blt     t0, t2, 1b
69          addu   t1, 4
70
71         /* If caches were enabled, we would have to flush them here. */
72
73         /* flush d-cache */
74         li      t0, KSEG0
75         addi    t1, t0, CONFIG_SYS_DCACHE_SIZE
76 2:
77         cache   INDEX_WRITEBACK_INV_D, 0(t0)
78         bne     t0, t1, 2b
79          addi   t0, CONFIG_SYS_CACHELINE_SIZE
80
81         sync
82
83         /* flush i-cache */
84         li      t0, KSEG0
85         addi    t1, t0, CONFIG_SYS_ICACHE_SIZE
86 3:
87         cache   INDEX_INVALIDATE_I, 0(t0)
88         bne     t0, t1, 3b
89          addi   t0, CONFIG_SYS_CACHELINE_SIZE
90
91         /* Invalidate BTB */
92         mfc0    t0, CP0_CONFIG, 7
93         nop
94         ori     t0, 2
95         mtc0    t0, CP0_CONFIG, 7
96         nop
97
98         /* Jump to where we've relocated ourselves */
99         addi    t0, a2, in_ram - _start
100         jr      t0
101          nop
102
103         .word   __rel_dyn_end
104         .word   __rel_dyn_start
105         .word   __image_copy_end
106         .word   _GLOBAL_OFFSET_TABLE_
107         .word   num_got_entries
108
109 in_ram:
110         /*
111          * Now we want to update GOT.
112          *
113          * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
114          * generated by GNU ld. Skip these reserved entries from relocation.
115          */
116         lw      t3, -4(t0)              # t3 <-- num_got_entries
117         lw      t4, -8(t0)              # t4 <-- _GLOBAL_OFFSET_TABLE_
118         add     t4, t6                  # t4 now holds relocated _G_O_T_
119         addi    t4, t4, 8               # skipping first two entries
120         li      t2, 2
121 1:
122         lw      t1, 0(t4)
123         beqz    t1, 2f
124          add    t1, t6
125         sw      t1, 0(t4)
126 2:
127         addi    t2, 1
128         blt     t2, t3, 1b
129          addi   t4, 4
130
131         /* Update dynamic relocations */
132         lw      t1, -16(t0)             # t1 <-- __rel_dyn_start
133         lw      t2, -20(t0)             # t2 <-- __rel_dyn_end
134
135         b       2f                      # skip first reserved entry
136          addi   t1, 8
137
138 1:
139         lw      t3, -4(t1)              # t3 <-- relocation info
140
141         sub     t3, 3
142         bnez    t3, 2f                  # skip non R_MIPS_REL32 entries
143          nop
144
145         lw      t3, -8(t1)              # t3 <-- location to fix up in FLASH
146
147         lw      t4, 0(t3)               # t4 <-- original pointer
148         add     t4, t6                  # t4 <-- adjusted pointer
149
150         add     t3, t6                  # t3 <-- location to fix up in RAM
151         sw      t4, 0(t3)
152
153 2:
154         blt     t1, t2, 1b
155          addi   t1, 8                   # each rel.dyn entry is 8 bytes
156
157         /*
158          * Clear BSS
159          *
160          * GOT is now relocated. Thus __bss_start and __bss_end can be
161          * accessed directly via $gp.
162          */
163         la      t1, __bss_start         # t1 <-- __bss_start
164         la      t2, __bss_end           # t2 <-- __bss_end
165
166 1:
167         sw      zero, 0(t1)
168         blt     t1, t2, 1b
169          addi   t1, 4
170
171         move    a0, a1                  # a0 <-- gd
172         la      t9, board_init_r
173         jr      t9
174          move   a1, a2
175
176         .end    relocate_code