ARM: dts: at91: sama5d2_icp: fix i2c eeprom compatible
[platform/kernel/u-boot.git] / arch / mips / cpu / start.S
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  *  Startup Code for MIPS32 CPU-core
4  *
5  *  Copyright (c) 2003  Wolfgang Denk <wd@denx.de>
6  */
7
8 #include <asm-offsets.h>
9 #include <config.h>
10 #include <asm/asm.h>
11 #include <asm/regdef.h>
12 #include <asm/mipsregs.h>
13
14 #ifndef CONFIG_SYS_INIT_SP_ADDR
15 #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + \
16                                 CONFIG_SYS_INIT_SP_OFFSET)
17 #endif
18
19 #ifdef CONFIG_32BIT
20 # define STATUS_SET     0
21 #endif
22
23 #ifdef CONFIG_64BIT
24 # define STATUS_SET     ST0_KX
25 #endif
26
27         .set noreorder
28
29         .macro init_wr sel
30         MTC0    zero, CP0_WATCHLO,\sel
31         mtc0    t1, CP0_WATCHHI,\sel
32         mfc0    t0, CP0_WATCHHI,\sel
33         bgez    t0, wr_done
34          nop
35         .endm
36
37         .macro uhi_mips_exception
38         move    k0, t9          # preserve t9 in k0
39         move    k1, a0          # preserve a0 in k1
40         li      t9, 15          # UHI exception operation
41         li      a0, 0           # Use hard register context
42         sdbbp   1               # Invoke UHI operation
43         .endm
44
45         .macro setup_stack_gd
46         li      t0, -16
47         PTR_LI  t1, CONFIG_SYS_INIT_SP_ADDR
48         and     sp, t1, t0              # force 16 byte alignment
49         PTR_SUBU \
50                 sp, sp, GD_SIZE         # reserve space for gd
51         and     sp, sp, t0              # force 16 byte alignment
52         move    k0, sp                  # save gd pointer
53 #if CONFIG_VAL(SYS_MALLOC_F_LEN) && \
54     !CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
55         li      t2, CONFIG_VAL(SYS_MALLOC_F_LEN)
56         PTR_SUBU \
57                 sp, sp, t2              # reserve space for early malloc
58         and     sp, sp, t0              # force 16 byte alignment
59 #endif
60         move    fp, sp
61
62         /* Clear gd */
63         move    t0, k0
64 1:
65         PTR_S   zero, 0(t0)
66         PTR_ADDIU t0, PTRSIZE
67         blt     t0, t1, 1b
68          nop
69
70 #if CONFIG_VAL(SYS_MALLOC_F_LEN) && \
71     !CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
72         PTR_S   sp, GD_MALLOC_BASE(k0)  # gd->malloc_base offset
73 #endif
74         .endm
75
76 ENTRY(_start)
77         /* U-Boot entry point */
78         b       reset
79          mtc0   zero, CP0_COUNT # clear cp0 count for most accurate boot timing
80
81 #if defined(CONFIG_MIPS_INSERT_BOOT_CONFIG)
82         /*
83          * Store some board-specific boot configuration. This is used by some
84          * MIPS systems like Malta.
85          */
86         .org 0x10
87         .word CONFIG_MIPS_BOOT_CONFIG_WORD0
88         .word CONFIG_MIPS_BOOT_CONFIG_WORD1
89 #endif
90
91 #if defined(CONFIG_ROM_EXCEPTION_VECTORS)
92         /*
93          * Exception vector entry points. When running from ROM, an exception
94          * cannot be handled. Halt execution and transfer control to debugger,
95          * if one is attached.
96          */
97         .org 0x200
98         /* TLB refill, 32 bit task */
99         uhi_mips_exception
100
101         .org 0x280
102         /* XTLB refill, 64 bit task */
103         uhi_mips_exception
104
105         .org 0x300
106         /* Cache error exception */
107         uhi_mips_exception
108
109         .org 0x380
110         /* General exception */
111         uhi_mips_exception
112
113         .org 0x400
114         /* Catch interrupt exceptions */
115         uhi_mips_exception
116
117         .org 0x480
118         /* EJTAG debug exception */
119 1:      b       1b
120          nop
121
122         .org 0x500
123 #endif
124
125 reset:
126 #if __mips_isa_rev >= 6
127         mfc0    t0, CP0_CONFIG, 5
128         and     t0, t0, MIPS_CONF5_VP
129         beqz    t0, 1f
130          nop
131
132         b       2f
133          mfc0   t0, CP0_GLOBALNUMBER
134 #endif
135
136 #ifdef CONFIG_ARCH_BMIPS
137 1:      mfc0    t0, CP0_DIAGNOSTIC, 3
138         and     t0, t0, (1 << 31)
139 #else
140 1:      mfc0    t0, CP0_EBASE
141         and     t0, t0, MIPS_EBASE_CPUNUM
142 #endif
143
144         /* Hang if this isn't the first CPU in the system */
145 2:      beqz    t0, 4f
146          nop
147 3:      wait
148         b       3b
149          nop
150
151         /* Init CP0 Status */
152 4:      mfc0    t0, CP0_STATUS
153         and     t0, ST0_IMPL
154         or      t0, ST0_BEV | ST0_ERL | STATUS_SET
155         mtc0    t0, CP0_STATUS
156
157         /*
158          * Check whether CP0 Config1 is implemented. If not continue
159          * with legacy Watch register initialization.
160          */
161         mfc0    t0, CP0_CONFIG
162         bgez    t0, wr_legacy
163          nop
164
165         /*
166          * Check WR bit in CP0 Config1 to determine if Watch registers
167          * are implemented.
168          */
169         mfc0    t0, CP0_CONFIG, 1
170         andi    t0, (1 << 3)
171         beqz    t0, wr_done
172          nop
173
174         /* Clear Watch Status bits and disable watch exceptions */
175         li      t1, 0x7         # Clear I, R and W conditions
176         init_wr 0
177         init_wr 1
178         init_wr 2
179         init_wr 3
180         init_wr 4
181         init_wr 5
182         init_wr 6
183         init_wr 7
184         b       wr_done
185          nop
186
187 wr_legacy:
188         MTC0    zero, CP0_WATCHLO
189         mtc0    zero, CP0_WATCHHI
190
191 wr_done:
192         /* Clear WP, IV and SW interrupts */
193         mtc0    zero, CP0_CAUSE
194
195         /* Clear timer interrupt (CP0_COUNT cleared on branch to 'reset') */
196         mtc0    zero, CP0_COMPARE
197
198 #ifdef CONFIG_MIPS_CACHE_DISABLE
199         /* Disable caches */
200         PTR_LA  t9, mips_cache_disable
201         jalr    t9
202          nop
203 #endif
204
205 #ifdef CONFIG_MIPS_CM
206         PTR_LA  t9, mips_cm_map
207         jalr    t9
208          nop
209 #endif
210
211 #ifdef CONFIG_MIPS_INIT_STACK_IN_SRAM
212 #ifdef CONFIG_MIPS_SRAM_INIT
213         /* Initialize the SRAM first */
214         PTR_LA  t9, mips_sram_init
215         jalr    t9
216          nop
217 #endif
218
219         /* Set up initial stack and global data */
220         setup_stack_gd
221
222 # ifdef CONFIG_DEBUG_UART
223         /* Earliest point to set up debug uart */
224         PTR_LA  t9, debug_uart_init
225         jalr    t9
226          nop
227 # endif
228 #endif
229
230 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
231 # ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
232         /* Initialize any external memory */
233         PTR_LA  t9, lowlevel_init
234         jalr    t9
235          nop
236 # endif
237 #endif
238
239 #ifdef CONFIG_MIPS_MACH_EARLY_INIT
240         bal     mips_mach_early_init
241          nop
242 #endif
243
244 #ifdef CONFIG_MIPS_CACHE_SETUP
245         /* Initialize caches... */
246         PTR_LA  t9, mips_cache_reset
247         jalr    t9
248          nop
249 #endif
250
251 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
252 # ifndef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
253         /* Initialize any external memory */
254         PTR_LA  t9, lowlevel_init
255         jalr    t9
256          nop
257 # endif
258 #endif
259
260 #ifndef CONFIG_MIPS_INIT_STACK_IN_SRAM
261         /* Set up initial stack and global data */
262         setup_stack_gd
263
264 # ifdef CONFIG_DEBUG_UART
265         /* Earliest point to set up debug uart */
266         PTR_LA  t9, debug_uart_init
267         jalr    t9
268          nop
269 # endif
270 #endif
271
272         move    a0, zero                # a0 <-- boot_flags = 0
273         PTR_LA  t9, board_init_f
274
275         jr      t9
276          move   ra, zero
277
278         END(_start)