]> git.sur5r.net Git - u-boot/blob - arch/mips/cpu/mips32/start.S
59468590a98b39f03ab34edc880248fc1934530e
[u-boot] / arch / mips / cpu / mips32 / start.S
1 /*
2  *  Startup Code for MIPS32 CPU-core
3  *
4  *  Copyright (c) 2003  Wolfgang Denk <wd@denx.de>
5  *
6  * SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <asm-offsets.h>
10 #include <config.h>
11 #include <asm/regdef.h>
12 #include <asm/mipsregs.h>
13
14 #ifndef CONFIG_SYS_MIPS_CACHE_MODE
15 #define CONFIG_SYS_MIPS_CACHE_MODE CONF_CM_CACHABLE_NONCOHERENT
16 #endif
17
18 #ifndef CONFIG_SYS_INIT_SP_ADDR
19 #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + \
20                                 CONFIG_SYS_INIT_SP_OFFSET)
21 #endif
22
23         /*
24          * For the moment disable interrupts, mark the kernel mode and
25          * set ST0_KX so that the CPU does not spit fire when using
26          * 64-bit addresses.
27          */
28         .macro  setup_c0_status set clr
29         .set    push
30         mfc0    t0, CP0_STATUS
31         or      t0, ST0_CU0 | \set | 0x1f | \clr
32         xor     t0, 0x1f | \clr
33         mtc0    t0, CP0_STATUS
34         .set    noreorder
35         sll     zero, 3                         # ehb
36         .set    pop
37         .endm
38
39         .set noreorder
40
41         .globl _start
42         .text
43 _start:
44         /* U-boot entry point */
45         b       reset
46          nop
47
48         .org 0x10
49 #if defined(CONFIG_SYS_XWAY_EBU_BOOTCFG)
50         /*
51          * Almost all Lantiq XWAY SoC devices have an external bus unit (EBU) to
52          * access external NOR flashes. If the board boots from NOR flash the
53          * internal BootROM does a blind read at address 0xB0000010 to read the
54          * initial configuration for that EBU in order to access the flash
55          * device with correct parameters. This config option is board-specific.
56          */
57         .word CONFIG_SYS_XWAY_EBU_BOOTCFG
58         .word 0x0
59 #elif defined(CONFIG_MALTA)
60         /*
61          * Linux expects the Board ID here.
62          */
63         .word 0x00000420        # 0x420 (Malta Board with CoreLV)
64         .word 0x00000000
65 #endif
66
67         .org 0x200
68         /* TLB refill, 32 bit task */
69 1:      b       1b
70          nop
71
72         .org 0x280
73         /* XTLB refill, 64 bit task */
74 1:      b       1b
75          nop
76
77         .org 0x300
78         /* Cache error exception */
79 1:      b       1b
80          nop
81
82         .org 0x380
83         /* General exception */
84 1:      b       1b
85          nop
86
87         .org 0x400
88         /* Catch interrupt exceptions */
89 1:      b       1b
90          nop
91
92         .org 0x480
93         /* EJTAG debug exception */
94 1:      b       1b
95          nop
96
97         .align 4
98 reset:
99
100         /* Clear watch registers */
101         mtc0    zero, CP0_WATCHLO
102         mtc0    zero, CP0_WATCHHI
103
104         /* WP(Watch Pending), SW0/1 should be cleared */
105         mtc0    zero, CP0_CAUSE
106
107         setup_c0_status 0 0
108
109         /* Init Timer */
110         mtc0    zero, CP0_COUNT
111         mtc0    zero, CP0_COMPARE
112
113 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
114         /* CONFIG0 register */
115         li      t0, CONF_CM_UNCACHED
116         mtc0    t0, CP0_CONFIG
117 #endif
118
119         /* Initialize $gp */
120         bal     1f
121          nop
122         .word   _gp
123 1:
124         lw      gp, 0(ra)
125
126 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
127         /* Initialize any external memory */
128         la      t9, lowlevel_init
129         jalr    t9
130          nop
131
132         /* Initialize caches... */
133         la      t9, mips_cache_reset
134         jalr    t9
135          nop
136
137         /* ... and enable them */
138         li      t0, CONFIG_SYS_MIPS_CACHE_MODE
139         mtc0    t0, CP0_CONFIG
140 #endif
141
142         /* Set up temporary stack */
143         li      sp, CONFIG_SYS_INIT_SP_ADDR
144         move    fp, sp
145
146         la      t9, board_init_f
147         jr      t9
148          move   ra, zero
149
150 /*
151  * void relocate_code (addr_sp, gd, addr_moni)
152  *
153  * This "function" does not return, instead it continues in RAM
154  * after relocating the monitor code.
155  *
156  * a0 = addr_sp
157  * a1 = gd
158  * a2 = destination address
159  */
160         .globl  relocate_code
161         .ent    relocate_code
162 relocate_code:
163         move    sp, a0                  # set new stack pointer
164         move    fp, sp
165
166         move    s0, a1                  # save gd in s0
167         move    s2, a2                  # save destination address in s2
168
169         li      t0, CONFIG_SYS_MONITOR_BASE
170         sub     s1, s2, t0              # s1 <-- relocation offset
171
172         la      t3, in_ram
173         lw      t2, -12(t3)             # t2 <-- __image_copy_end
174         move    t1, a2
175
176         add     gp, s1                  # adjust gp
177
178         /*
179          * t0 = source address
180          * t1 = target address
181          * t2 = source end address
182          */
183 1:
184         lw      t3, 0(t0)
185         sw      t3, 0(t1)
186         addu    t0, 4
187         blt     t0, t2, 1b
188          addu   t1, 4
189
190         /* If caches were enabled, we would have to flush them here. */
191         sub     a1, t1, s2              # a1 <-- size
192         la      t9, flush_cache
193         jalr    t9
194          move   a0, s2                  # a0 <-- destination address
195
196         /* Jump to where we've relocated ourselves */
197         addi    t0, s2, in_ram - _start
198         jr      t0
199          nop
200
201         .word   __rel_dyn_end
202         .word   __rel_dyn_start
203         .word   __image_copy_end
204         .word   _GLOBAL_OFFSET_TABLE_
205         .word   num_got_entries
206
207 in_ram:
208         /*
209          * Now we want to update GOT.
210          *
211          * GOT[0] is reserved. GOT[1] is also reserved for the dynamic object
212          * generated by GNU ld. Skip these reserved entries from relocation.
213          */
214         lw      t3, -4(t0)              # t3 <-- num_got_entries
215         lw      t8, -8(t0)              # t8 <-- _GLOBAL_OFFSET_TABLE_
216         add     t8, s1                  # t8 now holds relocated _G_O_T_
217         addi    t8, t8, 8               # skipping first two entries
218         li      t2, 2
219 1:
220         lw      t1, 0(t8)
221         beqz    t1, 2f
222          add    t1, s1
223         sw      t1, 0(t8)
224 2:
225         addi    t2, 1
226         blt     t2, t3, 1b
227          addi   t8, 4
228
229         /* Update dynamic relocations */
230         lw      t1, -16(t0)             # t1 <-- __rel_dyn_start
231         lw      t2, -20(t0)             # t2 <-- __rel_dyn_end
232
233         b       2f                      # skip first reserved entry
234          addi   t1, 8
235
236 1:
237         lw      t8, -4(t1)              # t8 <-- relocation info
238
239         li      t3, 3
240         bne     t8, t3, 2f              # skip non R_MIPS_REL32 entries
241          nop
242
243         lw      t3, -8(t1)              # t3 <-- location to fix up in FLASH
244
245         lw      t8, 0(t3)               # t8 <-- original pointer
246         add     t8, s1                  # t8 <-- adjusted pointer
247
248         add     t3, s1                  # t3 <-- location to fix up in RAM
249         sw      t8, 0(t3)
250
251 2:
252         blt     t1, t2, 1b
253          addi   t1, 8                   # each rel.dyn entry is 8 bytes
254
255         /*
256          * Clear BSS
257          *
258          * GOT is now relocated. Thus __bss_start and __bss_end can be
259          * accessed directly via $gp.
260          */
261         la      t1, __bss_start         # t1 <-- __bss_start
262         la      t2, __bss_end           # t2 <-- __bss_end
263
264 1:
265         sw      zero, 0(t1)
266         blt     t1, t2, 1b
267          addi   t1, 4
268
269         move    a0, s0                  # a0 <-- gd
270         move    a1, s2
271         la      t9, board_init_r
272         jr      t9
273          move   ra, zero
274
275         .end    relocate_code