1 | /*===============================================================*\ |
---|
2 | | Project: RTEMS generic MPC83xx BSP | |
---|
3 | +-----------------------------------------------------------------+ |
---|
4 | | Copyright (c) 2007 | |
---|
5 | | Embedded Brains GmbH | |
---|
6 | | Obere Lagerstr. 30 | |
---|
7 | | D-82178 Puchheim | |
---|
8 | | Germany | |
---|
9 | | rtems@embedded-brains.de | |
---|
10 | +-----------------------------------------------------------------+ |
---|
11 | | The license and distribution terms for this file may be | |
---|
12 | | found in the file LICENSE in this distribution or at | |
---|
13 | | | |
---|
14 | | http://www.rtems.com/license/LICENSE. | |
---|
15 | | | |
---|
16 | +-----------------------------------------------------------------+ |
---|
17 | | this file contains the startup assembly code | |
---|
18 | \*===============================================================*/ |
---|
19 | /* $Id$ */ |
---|
20 | |
---|
21 | #include <libcpu/powerpc-utility.h> |
---|
22 | #include <rtems/powerpc/cache.h> |
---|
23 | #include <bsp.h> |
---|
24 | #include <mpc83xx/mpc83xx.h> |
---|
25 | |
---|
26 | .macro SET_IMM_REGW base, reg2, offset, value |
---|
27 | LA \reg2, \value |
---|
28 | stw \reg2,\offset(\base) |
---|
29 | .endm |
---|
30 | |
---|
31 | #define REP8(l) l ; l; l; l; l; l; l; l; |
---|
32 | |
---|
33 | .extern boot_card |
---|
34 | .extern MBAR |
---|
35 | |
---|
36 | #if defined(RESET_CONF_WRD_L) |
---|
37 | .section ".resconf","ax" |
---|
38 | PUBLIC_VAR (reset_conf_words) |
---|
39 | reset_conf_words: |
---|
40 | REP8( .byte ((RESET_CONF_WRD_L >> 24) & 0xff)) |
---|
41 | REP8( .byte ((RESET_CONF_WRD_L >> 16) & 0xff)) |
---|
42 | REP8( .byte ((RESET_CONF_WRD_L >> 8) & 0xff)) |
---|
43 | REP8( .byte ((RESET_CONF_WRD_L >> 0) & 0xff)) |
---|
44 | |
---|
45 | REP8( .byte ((RESET_CONF_WRD_H >> 24) & 0xff)) |
---|
46 | REP8( .byte ((RESET_CONF_WRD_H >> 16) & 0xff)) |
---|
47 | REP8( .byte ((RESET_CONF_WRD_H >> 8) & 0xff)) |
---|
48 | REP8( .byte ((RESET_CONF_WRD_H >> 0) & 0xff)) |
---|
49 | #endif |
---|
50 | |
---|
51 | .section ".vectors","ax" |
---|
52 | PUBLIC_VAR (reset_vec) |
---|
53 | reset_vec: |
---|
54 | bl rom_entry |
---|
55 | |
---|
56 | .section ".entry" |
---|
57 | PUBLIC_VAR (start) |
---|
58 | start: |
---|
59 | |
---|
60 | #ifdef HAS_UBOOT |
---|
61 | |
---|
62 | .extern mpc83xx_uboot_board_info |
---|
63 | .extern mpc83xx_uboot_board_info_size |
---|
64 | |
---|
65 | /* Reset time base */ |
---|
66 | li r0, 0 |
---|
67 | mtspr TBWU, r0 |
---|
68 | mtspr TBWL, r0 |
---|
69 | |
---|
70 | /* Copy board info */ |
---|
71 | LA r6, mpc83xx_uboot_board_info |
---|
72 | LW r5, mpc83xx_uboot_board_info_size |
---|
73 | mtctr r5 |
---|
74 | |
---|
75 | copy_uboot_board_info: |
---|
76 | |
---|
77 | lwz r5, 0(r3) |
---|
78 | addi r3, r3, 4 |
---|
79 | stw r5, 0(r6) |
---|
80 | addi r6, r6, 4 |
---|
81 | bdnz copy_uboot_board_info |
---|
82 | |
---|
83 | #endif /* HAS_UBOOT */ |
---|
84 | |
---|
85 | /* |
---|
86 | * basic CPU setup: |
---|
87 | * init MSR |
---|
88 | */ |
---|
89 | mfmsr r30 |
---|
90 | SETBITS r30, r29, MSR_ME|MSR_RI |
---|
91 | CLRBITS r30, r29, MSR_IP|MSR_EE |
---|
92 | mtmsr r30 /* Set RI/ME, Clr EE in MSR */ |
---|
93 | |
---|
94 | b start_rom_skip |
---|
95 | |
---|
96 | PUBLIC_VAR (rom_entry) |
---|
97 | rom_entry: |
---|
98 | /* |
---|
99 | * basic CPU setup: |
---|
100 | * init MSR |
---|
101 | */ |
---|
102 | mfmsr r30 |
---|
103 | SETBITS r30, r29, MSR_ME|MSR_RI |
---|
104 | CLRBITS r30, r29, MSR_IP|MSR_EE |
---|
105 | mtmsr r30 /* Set RI/ME, Clr EE in MSR */ |
---|
106 | |
---|
107 | /* |
---|
108 | * ROM startup: remap IMMR to 0xE0000000 |
---|
109 | * use special sequence from MPC8349EA RM Rev 1, 5.2.4.1.1 "Updating IMMRBAR" |
---|
110 | */ |
---|
111 | LWI r30,IMMRBAR_DEFAULT |
---|
112 | LWI r31,IMMRBAR |
---|
113 | lwz r29,0(r30) |
---|
114 | stw r31,0(r30) |
---|
115 | #if 0 |
---|
116 | lwz r29,0(r28) /* read from ROM... */ |
---|
117 | #endif |
---|
118 | isync |
---|
119 | lwz r29,0(r31) /* read from IMMRBAR... */ |
---|
120 | isync |
---|
121 | /* |
---|
122 | * NOTE: now r31 points to onchip registers |
---|
123 | */ |
---|
124 | /* |
---|
125 | * we start from 0x100, so ROM is currently mapped to |
---|
126 | * 0x00000000.. |
---|
127 | * in the next step, ROM will be remapped to its final location |
---|
128 | * at 0xfe000000... (using LBLAWBAR1 with LBLAWBAR0 value) |
---|
129 | * and we jump to that location. |
---|
130 | * then we remove the ROM mapping to zero |
---|
131 | */ |
---|
132 | #ifdef LBLAWBAR0_VAL |
---|
133 | SET_IMM_REGW r31,r30,LBLAWBAR1_OFF,LBLAWBAR0_VAL |
---|
134 | #endif |
---|
135 | #ifdef LBLAWAR0_VAL |
---|
136 | SET_IMM_REGW r31,r30,LBLAWAR1_OFF,LBLAWAR0_VAL |
---|
137 | #endif |
---|
138 | |
---|
139 | |
---|
140 | /* |
---|
141 | * ROM startup: jump to code final ROM location |
---|
142 | */ |
---|
143 | LA r20, bsp_rom_start /* ROM-RAM reloc in r20 */ |
---|
144 | LA r29, start_code_in_rom /* get compile time addr of label */ |
---|
145 | add r29,r20,r29 /* compute exec address */ |
---|
146 | mtlr r29 |
---|
147 | blr /* now further execution in upper ROM */ |
---|
148 | |
---|
149 | start_code_in_rom: |
---|
150 | |
---|
151 | #ifdef LBLAWBAR0_VAL |
---|
152 | SET_IMM_REGW r31,r30,LBLAWBAR0_OFF,LBLAWBAR0_VAL |
---|
153 | #endif |
---|
154 | #ifdef LBLAWAR0_VAL |
---|
155 | SET_IMM_REGW r31,r30,LBLAWAR0_OFF,LBLAWAR0_VAL |
---|
156 | #endif |
---|
157 | #ifdef LBLAWBAR1_VAL |
---|
158 | SET_IMM_REGW r31,r30,LBLAWBAR1_OFF,LBLAWBAR1_VAL |
---|
159 | #endif |
---|
160 | #ifdef LBLAWAR1_VAL |
---|
161 | SET_IMM_REGW r31,r30,LBLAWAR1_OFF,LBLAWAR1_VAL |
---|
162 | #endif |
---|
163 | #ifdef LBLAWBAR2_VAL |
---|
164 | SET_IMM_REGW r31,r30,LBLAWBAR2_OFF,LBLAWBAR2_VAL |
---|
165 | #endif |
---|
166 | #ifdef LBLAWAR2_VAL |
---|
167 | SET_IMM_REGW r31,r30,LBLAWAR2_OFF,LBLAWAR2_VAL |
---|
168 | #endif |
---|
169 | #ifdef LBLAWBAR3_VAL |
---|
170 | SET_IMM_REGW r31,r30,LBLAWBAR3_OFF,LBLAWBAR3_VAL |
---|
171 | #endif |
---|
172 | #ifdef LBLAWAR3_VAL |
---|
173 | SET_IMM_REGW r31,r30,LBLAWAR3_OFF,LBLAWAR3_VAL |
---|
174 | #endif |
---|
175 | /* |
---|
176 | * ROM startup: init bus system |
---|
177 | */ |
---|
178 | #ifdef BR0_VAL |
---|
179 | SET_IMM_REGW r31,r30,BR0_OFF,BR0_VAL |
---|
180 | #endif |
---|
181 | #ifdef OR0_VAL |
---|
182 | SET_IMM_REGW r31,r30,OR0_OFF,OR0_VAL |
---|
183 | #endif |
---|
184 | #ifdef BR1_VAL |
---|
185 | SET_IMM_REGW r31,r30,BR1_OFF,BR1_VAL |
---|
186 | #endif |
---|
187 | #ifdef OR1_VAL |
---|
188 | SET_IMM_REGW r31,r30,OR1_OFF,OR1_VAL |
---|
189 | #endif |
---|
190 | #ifdef BR2_VAL |
---|
191 | SET_IMM_REGW r31,r30,BR2_OFF,BR2_VAL |
---|
192 | #endif |
---|
193 | #ifdef OR2_VAL |
---|
194 | SET_IMM_REGW r31,r30,OR2_OFF,OR2_VAL |
---|
195 | #endif |
---|
196 | #ifdef BR3_VAL |
---|
197 | SET_IMM_REGW r31,r30,BR3_OFF,BR3_VAL |
---|
198 | #endif |
---|
199 | #ifdef OR3_VAL |
---|
200 | SET_IMM_REGW r31,r30,OR3_OFF,OR3_VAL |
---|
201 | #endif |
---|
202 | |
---|
203 | /* |
---|
204 | * ROM startup: init SDRAM access window |
---|
205 | */ |
---|
206 | #ifdef DDRLAWBAR0_VAL |
---|
207 | SET_IMM_REGW r31,r30,DDRLAWBAR0_OFF,DDRLAWBAR0_VAL |
---|
208 | #endif |
---|
209 | #ifdef DDRLAWAR0_VAL |
---|
210 | SET_IMM_REGW r31,r30,DDRLAWAR0_OFF,DDRLAWAR0_VAL |
---|
211 | #endif |
---|
212 | #ifdef DDRLAWBAR1_VAL |
---|
213 | SET_IMM_REGW r31,r30,DDRLAWBAR1_OFF,DDRLAWBAR1_VAL |
---|
214 | #endif |
---|
215 | #ifdef DDRLAWAR1_VAL |
---|
216 | SET_IMM_REGW r31,r30,DDRLAWAR1_OFF,DDRLAWAR1_VAL |
---|
217 | #endif |
---|
218 | /* |
---|
219 | * ROM startup: init refresh interval |
---|
220 | */ |
---|
221 | #ifdef MRPTR_VAL |
---|
222 | SET_IMM_REGW r31,r30,MRPTR_OFF,MRPTR_VAL |
---|
223 | #endif |
---|
224 | /* |
---|
225 | * ROM startup: init SDRAM |
---|
226 | */ |
---|
227 | #ifdef LSRT_VAL |
---|
228 | SET_IMM_REGW r31,r30, LSRT_OFF, LSRT_VAL |
---|
229 | #endif |
---|
230 | #ifdef LSDMR_VAL |
---|
231 | SET_IMM_REGW r31,r30, LSDMR_OFF, LSDMR_VAL |
---|
232 | #endif |
---|
233 | #ifdef CS0_BNDS_VAL |
---|
234 | SET_IMM_REGW r31,r30,CS0_BNDS_OFF,CS0_BNDS_VAL |
---|
235 | #endif |
---|
236 | #ifdef CS1_BNDS_VAL |
---|
237 | SET_IMM_REGW r31,r30,CS1_BNDS_OFF,CS1_BNDS_VAL |
---|
238 | #endif |
---|
239 | #ifdef CS2_BNDS_VAL |
---|
240 | SET_IMM_REGW r31,r30,CS2_BNDS_OFF,CS2_BNDS_VAL |
---|
241 | #endif |
---|
242 | #ifdef CS3_BNDS_VAL |
---|
243 | SET_IMM_REGW r31,r30,CS3_BNDS_OFF,CS3_BNDS_VAL |
---|
244 | #endif |
---|
245 | #ifdef CS0_CONFIG_VAL |
---|
246 | SET_IMM_REGW r31,r30,CS0_CONFIG_OFF,CS0_CONFIG_VAL |
---|
247 | #endif |
---|
248 | #ifdef CS1_CONFIG_VAL |
---|
249 | SET_IMM_REGW r31,r30,CS1_CONFIG_OFF,CS1_CONFIG_VAL |
---|
250 | #endif |
---|
251 | #ifdef CS2_CONFIG_VAL |
---|
252 | SET_IMM_REGW r31,r30,CS2_CONFIG_OFF,CS2_CONFIG_VAL |
---|
253 | #endif |
---|
254 | #ifdef CS3_CONFIG_VAL |
---|
255 | SET_IMM_REGW r31,r30,CS3_CONFIG_OFF,CS3_CONFIG_VAL |
---|
256 | #endif |
---|
257 | #ifdef TIMING_CFG_3_VAL |
---|
258 | SET_IMM_REGW r31,r30,TIMING_CFG_3_OFF,TIMING_CFG_3_VAL |
---|
259 | #endif |
---|
260 | #ifdef TIMING_CFG_0_VAL |
---|
261 | SET_IMM_REGW r31,r30,TIMING_CFG_0_OFF,TIMING_CFG_0_VAL |
---|
262 | #endif |
---|
263 | #ifdef TIMING_CFG_1_VAL |
---|
264 | SET_IMM_REGW r31,r30,TIMING_CFG_1_OFF,TIMING_CFG_1_VAL |
---|
265 | #endif |
---|
266 | #ifdef TIMING_CFG_2_VAL |
---|
267 | SET_IMM_REGW r31,r30,TIMING_CFG_2_OFF,TIMING_CFG_2_VAL |
---|
268 | #endif |
---|
269 | #ifdef DDRCDR_VAL |
---|
270 | SET_IMM_REGW r31,r30,DDRCDR_OFF,DDRCDR_VAL |
---|
271 | #endif |
---|
272 | #ifdef DDR_SDRAM_CFG_2_VAL |
---|
273 | SET_IMM_REGW r31,r30,DDR_SDRAM_CFG_2_OFF,DDR_SDRAM_CFG_2_VAL |
---|
274 | #endif |
---|
275 | #ifdef DDR_SDRAM_MODE_VAL |
---|
276 | SET_IMM_REGW r31,r30,DDR_SDRAM_MODE_OFF,DDR_SDRAM_MODE_VAL |
---|
277 | #endif |
---|
278 | #ifdef DDR_SDRAM_MODE_2_VAL |
---|
279 | SET_IMM_REGW r31,r30,DDR_SDRAM_MODE_2_OFF,DDR_SDRAM_MODE_2_VAL |
---|
280 | #endif |
---|
281 | #ifdef DDR_SDRAM_MD_CNTL_VAL |
---|
282 | SET_IMM_REGW r31,r30,DDR_SDRAM_MD_CNTL_OFF,DDR_SDRAM_MD_CNTL_VAL |
---|
283 | #endif |
---|
284 | #ifdef DDR_SDRAM_MD_ITVL_VAL |
---|
285 | SET_IMM_REGW r31,r30,DDR_SDRAM_MD_ITVL_OFF,DDR_SDRAM_MD_ITVL_VAL |
---|
286 | #endif |
---|
287 | #ifdef DDR_SDRAM_CLK_CNTL_VAL |
---|
288 | SET_IMM_REGW r31,r30,DDR_SDRAM_CLK_CNTL_OFF,DDR_SDRAM_CLK_CNTL_VAL |
---|
289 | #endif |
---|
290 | #ifdef DDR_SDRAM_CFG_2_VAL |
---|
291 | SET_IMM_REGW r31,r30,DDR_SDRAM_CFG_2_OFF,DDR_SDRAM_CFG_2_VAL|DDR_SDRAM_CFG_2_D_INIT |
---|
292 | #endif |
---|
293 | |
---|
294 | #ifdef DDR_ERR_DISABLE_VAL |
---|
295 | /* |
---|
296 | * disable detect of RAM errors |
---|
297 | */ |
---|
298 | SET_IMM_REGW r31,r30,DDR_ERR_DISABLE_OFF,DDR_ERR_DISABLE_VAL |
---|
299 | #endif |
---|
300 | #ifdef DDR_SDRAM_DATA_INIT_VAL |
---|
301 | /* |
---|
302 | * set this value to initialize memory |
---|
303 | */ |
---|
304 | SET_IMM_REGW r31,r30,DDR_SDRAM_DATA_INIT_OFF,DDR_SDRAM_DATA_INIT_VAL |
---|
305 | #endif |
---|
306 | #ifdef DDR_SDRAM_INIT_ADDR_VAL |
---|
307 | SET_IMM_REGW r31,r30,DDR_SDRAM_INIT_ADDR_OFF,DDR_SDRAM_INIT_ADDR_VAL |
---|
308 | #endif |
---|
309 | #ifdef DDR_SDRAM_CFG_VAL |
---|
310 | /* |
---|
311 | * config DDR SDRAM |
---|
312 | */ |
---|
313 | SET_IMM_REGW r31,r30,DDR_SDRAM_CFG_OFF,DDR_SDRAM_CFG_VAL & ~DDR_SDRAM_CFG_MEM_EN |
---|
314 | /* |
---|
315 | * FIXME: wait 200us |
---|
316 | */ |
---|
317 | /* |
---|
318 | * enable DDR SDRAM |
---|
319 | */ |
---|
320 | SET_IMM_REGW r31,r30,DDR_SDRAM_CFG_OFF,DDR_SDRAM_CFG_VAL | DDR_SDRAM_CFG_MEM_EN |
---|
321 | /* |
---|
322 | * wait, until DDR_SDRAM_CFG_2_D_INIT is cleared |
---|
323 | */ |
---|
324 | 1: lwz r30,DDR_SDRAM_CFG_2_OFF(r31) |
---|
325 | andi. r30,r30,DDR_SDRAM_CFG_2_D_INIT |
---|
326 | bne 1b |
---|
327 | #endif |
---|
328 | #ifdef DDR_ERR_DISABLE_VAL2 |
---|
329 | /* |
---|
330 | * enable detect of some RAM errors |
---|
331 | */ |
---|
332 | SET_IMM_REGW r31,r30,DDR_ERR_DISABLE_OFF,DDR_ERR_DISABLE_VAL2 |
---|
333 | #endif |
---|
334 | #ifdef DDR_SDRAM_INTERVAL_VAL |
---|
335 | /* |
---|
336 | * set the refresh interval |
---|
337 | */ |
---|
338 | SET_IMM_REGW r31,r30,DDR_SDRAM_INTERVAL_OFF,DDR_SDRAM_INTERVAL_VAL |
---|
339 | #endif |
---|
340 | start_rom_skip: |
---|
341 | /* |
---|
342 | * determine current execution address offset |
---|
343 | */ |
---|
344 | bl start_rom_skip1 |
---|
345 | start_rom_skip1: |
---|
346 | mflr r20 |
---|
347 | LA r30,start_rom_skip1 |
---|
348 | sub. r20,r20,r30 |
---|
349 | /* |
---|
350 | * execution address offset == 0? |
---|
351 | * then do not relocate code and data |
---|
352 | */ |
---|
353 | beq start_code_in_ram |
---|
354 | /* |
---|
355 | * ROM or relocatable startup: copy startup code to SDRAM |
---|
356 | */ |
---|
357 | /* get start address of text section in RAM */ |
---|
358 | LA r29, bsp_section_text_start |
---|
359 | /* get start address of text section in ROM (add reloc offset) */ |
---|
360 | add r30, r20, r29 |
---|
361 | /* get size of startup code */ |
---|
362 | LA r28, end_reloc_startup |
---|
363 | LA r31, bsp_section_text_start |
---|
364 | sub 28,r28,r31 |
---|
365 | /* copy startup code from ROM to RAM location */ |
---|
366 | bl copy_image |
---|
367 | |
---|
368 | /* |
---|
369 | * ROM startup: jump to code copy in SDRAM |
---|
370 | */ |
---|
371 | /* get compile time address of label */ |
---|
372 | LA r29, copy_rest_of_text |
---|
373 | mtlr r29 |
---|
374 | blr /* now further execution RAM */ |
---|
375 | copy_rest_of_text: |
---|
376 | #ifdef LCRR_VAL |
---|
377 | SET_IMM_REGW r31,r30,LCRR_OFF,LCRR_VAL |
---|
378 | #endif |
---|
379 | /* |
---|
380 | * ROM or relocatable startup: copy rest of code to SDRAM |
---|
381 | */ |
---|
382 | /* get start address of rest of code in RAM */ |
---|
383 | LA r29, end_reloc_startup |
---|
384 | /* get start address of text section in ROM (add reloc offset) */ |
---|
385 | add r30, r20, r29 |
---|
386 | /* get size of rest of code */ |
---|
387 | LA r28, bsp_section_text_start |
---|
388 | LA r31, bsp_section_text_size |
---|
389 | add r28,r28,r31 |
---|
390 | sub r28,r28,r29 |
---|
391 | bl copy_image /* copy text section from ROM to RAM location */ |
---|
392 | |
---|
393 | /* |
---|
394 | * ROM or relocatable startup: copy data to SDRAM |
---|
395 | */ |
---|
396 | /* get start address of data section in RAM */ |
---|
397 | LA r29, bsp_section_data_start |
---|
398 | /* get start address of data section in ROM (add reloc offset) */ |
---|
399 | add r30, r20, r29 |
---|
400 | /* get size of RAM image */ |
---|
401 | LA r28, bsp_section_data_size |
---|
402 | /* copy initialized data section from ROM to RAM location */ |
---|
403 | bl copy_image |
---|
404 | |
---|
405 | start_code_in_ram: |
---|
406 | |
---|
407 | /* |
---|
408 | * ROM/RAM startup: clear bss in SDRAM |
---|
409 | */ |
---|
410 | LA r3, bsp_section_bss_start /* get start address of bss section */ |
---|
411 | LWI r4, bsp_section_bss_size /* get size of bss section */ |
---|
412 | bl mpc83xx_zero_4 /* Clear the bss section */ |
---|
413 | /* |
---|
414 | * call boot_card |
---|
415 | */ |
---|
416 | |
---|
417 | /* Set stack pointer (common for RAM/ROM startup) */ |
---|
418 | LA r1, bsp_section_text_start |
---|
419 | addi r1, r1, -0x10 /* Set up stack pointer = beginning of text section - 0x10 */ |
---|
420 | |
---|
421 | /* Create NULL */ |
---|
422 | li r0, 0 |
---|
423 | |
---|
424 | /* Return address */ |
---|
425 | stw r0, 4(r1) |
---|
426 | |
---|
427 | /* Back chain */ |
---|
428 | stw r0, 0(r1) |
---|
429 | |
---|
430 | /* Read-only small data */ |
---|
431 | LA r2, _SDA2_BASE_ |
---|
432 | |
---|
433 | /* Read-write small data */ |
---|
434 | LA r13, _SDA_BASE_ |
---|
435 | |
---|
436 | /* clear arguments and do further init. in C (common for RAM/ROM startup) */ |
---|
437 | |
---|
438 | /* Clear argc, argv and envp */ |
---|
439 | xor r3, r3, r3 |
---|
440 | xor r4, r4, r4 |
---|
441 | xor r5, r5, r5 |
---|
442 | |
---|
443 | bl SYM (boot_card) /* Call the first C routine */ |
---|
444 | |
---|
445 | twiddle: |
---|
446 | /* We don't expect to return from boot_card but if we do */ |
---|
447 | /* wait here for watchdog to kick us into hard reset */ |
---|
448 | b twiddle |
---|
449 | |
---|
450 | copy_image: |
---|
451 | mr r27, r28 |
---|
452 | srwi r28, r28, 2 |
---|
453 | mtctr r28 |
---|
454 | |
---|
455 | slwi r28, r28, 2 |
---|
456 | sub r27, r27, r28 /* maybe some residual bytes */ |
---|
457 | copy_image_word: |
---|
458 | lswi r28, r30, 0x04 |
---|
459 | |
---|
460 | stswi r28, r29, 0x04 /* do word copy ROM -> RAM */ |
---|
461 | |
---|
462 | |
---|
463 | addi r30, r30, 0x04 /* increment source pointer */ |
---|
464 | addi r29, r29, 0x04 /* increment destination pointer */ |
---|
465 | |
---|
466 | bdnz copy_image_word /* decrement ctr and branch if not 0 */ |
---|
467 | |
---|
468 | cmpwi r27, 0x00 /* copy image finished ? */ |
---|
469 | beq copy_image_end; |
---|
470 | mtctr r27 /* reload counter for residual bytes */ |
---|
471 | copy_image_byte: |
---|
472 | lswi r28, r30, 0x01 |
---|
473 | |
---|
474 | stswi r28, r29, 0x01 /* do byte copy ROM -> RAM */ |
---|
475 | |
---|
476 | |
---|
477 | addi r30, r30, 0x01 /* increment source pointer */ |
---|
478 | addi r29, r29, 0x01 /* increment destination pointer */ |
---|
479 | |
---|
480 | bdnz copy_image_byte /* decrement ctr and branch if not 0 */ |
---|
481 | |
---|
482 | copy_image_end: |
---|
483 | blr |
---|
484 | |
---|
485 | |
---|
486 | /** |
---|
487 | * @fn int mpc83xx_zero_4( void *dest, size_t n) |
---|
488 | * |
---|
489 | * @brief Zero all @a n bytes starting at @a dest with 4 byte writes. |
---|
490 | * |
---|
491 | * The address @a dest has to be aligned on 4 byte boundaries. The size @a n |
---|
492 | * must be evenly divisible by 4. |
---|
493 | */ |
---|
494 | GLOBAL_FUNCTION mpc83xx_zero_4 |
---|
495 | /* Create zero */ |
---|
496 | xor r0, r0, r0 |
---|
497 | |
---|
498 | /* Set offset */ |
---|
499 | xor r5, r5, r5 |
---|
500 | |
---|
501 | /* Loop counter for the first bytes up to 16 bytes */ |
---|
502 | rlwinm. r9, r4, 30, 30, 31 |
---|
503 | beq mpc83xx_zero_4_more |
---|
504 | mtctr r9 |
---|
505 | |
---|
506 | mpc83xx_zero_4_head: |
---|
507 | |
---|
508 | stwx r0, r3, r5 |
---|
509 | addi r5, r5, 4 |
---|
510 | bdnz mpc83xx_zero_4_head |
---|
511 | |
---|
512 | mpc83xx_zero_4_more: |
---|
513 | |
---|
514 | /* More than 16 bytes? */ |
---|
515 | srwi. r9, r4, 4 |
---|
516 | beqlr |
---|
517 | mtctr r9 |
---|
518 | |
---|
519 | /* Set offsets */ |
---|
520 | addi r6, r5, 4 |
---|
521 | addi r7, r5, 8 |
---|
522 | addi r8, r5, 12 |
---|
523 | |
---|
524 | mpc83xx_zero_4_tail: |
---|
525 | |
---|
526 | stwx r0, r3, r5 |
---|
527 | addi r5, r5, 16 |
---|
528 | stwx r0, r3, r6 |
---|
529 | addi r6, r6, 16 |
---|
530 | stwx r0, r3, r7 |
---|
531 | addi r7, r7, 16 |
---|
532 | stwx r0, r3, r8 |
---|
533 | addi r8, r8, 16 |
---|
534 | bdnz mpc83xx_zero_4_tail |
---|
535 | |
---|
536 | /* Return */ |
---|
537 | blr |
---|
538 | |
---|
539 | end_reloc_startup: |
---|