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