source: rtems/c/src/lib/libbsp/powerpc/gen83xx/start/start.S @ 596bcb6f

4.9
Last change on this file since 596bcb6f was 596bcb6f, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 03/19/09 at 10:41:46
  • start/start.S, include/hwreg_vals.h, startup/cpuinit.c: correct some init values for HSC_CM01 boards
  • Property mode set to 100644
File size: 13.3 KB
Line 
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"
38PUBLIC_VAR (reset_conf_words)
39reset_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"
52PUBLIC_VAR (reset_vec)
53reset_vec:     
54        bl rom_entry
55       
56.section ".entry" 
57PUBLIC_VAR (start)
58start:
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
75copy_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       
96PUBLIC_VAR (rom_entry)
97rom_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
149start_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#ifdef BR4_VAL
203        SET_IMM_REGW r31,r30,BR4_OFF,BR4_VAL
204#endif
205#ifdef OR4_VAL
206        SET_IMM_REGW r31,r30,OR4_OFF,OR4_VAL
207#endif
208#ifdef BR5_VAL
209        SET_IMM_REGW r31,r30,BR5_OFF,BR5_VAL
210#endif
211#ifdef OR5_VAL
212        SET_IMM_REGW r31,r30,OR5_OFF,OR5_VAL
213#endif
214        /*
215         * ROM startup: init SDRAM access window
216         */
217#ifdef DDRLAWBAR0_VAL
218        SET_IMM_REGW r31,r30,DDRLAWBAR0_OFF,DDRLAWBAR0_VAL
219#endif
220#ifdef DDRLAWAR0_VAL
221        SET_IMM_REGW r31,r30,DDRLAWAR0_OFF,DDRLAWAR0_VAL
222#endif
223#ifdef DDRLAWBAR1_VAL
224        SET_IMM_REGW r31,r30,DDRLAWBAR1_OFF,DDRLAWBAR1_VAL
225#endif
226#ifdef DDRLAWAR1_VAL
227        SET_IMM_REGW r31,r30,DDRLAWAR1_OFF,DDRLAWAR1_VAL
228#endif
229        /*
230         * ROM startup: init refresh interval
231         */
232#ifdef MRPTR_VAL
233        SET_IMM_REGW r31,r30,MRPTR_OFF,MRPTR_VAL
234#endif 
235        /*
236         * ROM startup: init SDRAM
237         */
238#ifdef LSRT_VAL
239        SET_IMM_REGW r31,r30, LSRT_OFF, LSRT_VAL
240#endif
241#ifdef LSDMR_VAL
242        SET_IMM_REGW r31,r30, LSDMR_OFF, LSDMR_VAL
243#endif
244#ifdef CS0_BNDS_VAL
245        SET_IMM_REGW r31,r30,CS0_BNDS_OFF,CS0_BNDS_VAL
246#endif
247#ifdef CS1_BNDS_VAL
248        SET_IMM_REGW r31,r30,CS1_BNDS_OFF,CS1_BNDS_VAL
249#endif
250#ifdef CS2_BNDS_VAL
251        SET_IMM_REGW r31,r30,CS2_BNDS_OFF,CS2_BNDS_VAL
252#endif
253#ifdef CS3_BNDS_VAL
254        SET_IMM_REGW r31,r30,CS3_BNDS_OFF,CS3_BNDS_VAL
255#endif
256#ifdef CS0_CONFIG_VAL
257        SET_IMM_REGW r31,r30,CS0_CONFIG_OFF,CS0_CONFIG_VAL
258#endif
259#ifdef CS1_CONFIG_VAL
260        SET_IMM_REGW r31,r30,CS1_CONFIG_OFF,CS1_CONFIG_VAL
261#endif
262#ifdef CS2_CONFIG_VAL
263        SET_IMM_REGW r31,r30,CS2_CONFIG_OFF,CS2_CONFIG_VAL
264#endif
265#ifdef CS3_CONFIG_VAL
266        SET_IMM_REGW r31,r30,CS3_CONFIG_OFF,CS3_CONFIG_VAL
267#endif
268#ifdef TIMING_CFG_3_VAL
269        SET_IMM_REGW r31,r30,TIMING_CFG_3_OFF,TIMING_CFG_3_VAL
270#endif
271#ifdef TIMING_CFG_0_VAL
272        SET_IMM_REGW r31,r30,TIMING_CFG_0_OFF,TIMING_CFG_0_VAL
273#endif
274#ifdef TIMING_CFG_1_VAL
275        SET_IMM_REGW r31,r30,TIMING_CFG_1_OFF,TIMING_CFG_1_VAL
276#endif
277#ifdef TIMING_CFG_2_VAL
278        SET_IMM_REGW r31,r30,TIMING_CFG_2_OFF,TIMING_CFG_2_VAL
279#endif
280#ifdef DDRCDR_VAL
281        SET_IMM_REGW r31,r30,DDRCDR_OFF,DDRCDR_VAL
282#endif
283#ifdef DDR_SDRAM_CFG_2_VAL
284        SET_IMM_REGW r31,r30,DDR_SDRAM_CFG_2_OFF,DDR_SDRAM_CFG_2_VAL
285#endif
286#ifdef DDR_SDRAM_MODE_VAL
287        SET_IMM_REGW r31,r30,DDR_SDRAM_MODE_OFF,DDR_SDRAM_MODE_VAL
288#endif
289#ifdef DDR_SDRAM_MODE_2_VAL
290        SET_IMM_REGW r31,r30,DDR_SDRAM_MODE_2_OFF,DDR_SDRAM_MODE_2_VAL
291#endif
292#ifdef DDR_SDRAM_MD_CNTL_VAL
293        SET_IMM_REGW r31,r30,DDR_SDRAM_MD_CNTL_OFF,DDR_SDRAM_MD_CNTL_VAL
294#endif
295#ifdef DDR_SDRAM_MD_ITVL_VAL
296        SET_IMM_REGW r31,r30,DDR_SDRAM_MD_ITVL_OFF,DDR_SDRAM_MD_ITVL_VAL
297#endif
298#ifdef DDR_SDRAM_CLK_CNTL_VAL
299        SET_IMM_REGW r31,r30,DDR_SDRAM_CLK_CNTL_OFF,DDR_SDRAM_CLK_CNTL_VAL
300#endif
301#ifdef DDR_SDRAM_CFG_2_VAL
302        SET_IMM_REGW r31,r30,DDR_SDRAM_CFG_2_OFF,DDR_SDRAM_CFG_2_VAL|DDR_SDRAM_CFG_2_D_INIT
303#endif
304
305#ifdef DDR_ERR_DISABLE_VAL
306        /*
307         * disable detect of RAM errors
308         */
309        SET_IMM_REGW r31,r30,DDR_ERR_DISABLE_OFF,DDR_ERR_DISABLE_VAL
310#endif
311#ifdef DDR_SDRAM_DATA_INIT_VAL
312        /*
313         * set this value to initialize memory
314         */
315        SET_IMM_REGW r31,r30,DDR_SDRAM_DATA_INIT_OFF,DDR_SDRAM_DATA_INIT_VAL
316#endif
317#ifdef DDR_SDRAM_INIT_ADDR_VAL
318        SET_IMM_REGW r31,r30,DDR_SDRAM_INIT_ADDR_OFF,DDR_SDRAM_INIT_ADDR_VAL
319#endif
320#ifdef DDR_SDRAM_CFG_VAL
321        /*
322         * config DDR SDRAM
323         */
324        SET_IMM_REGW r31,r30,DDR_SDRAM_CFG_OFF,DDR_SDRAM_CFG_VAL & ~DDR_SDRAM_CFG_MEM_EN
325        /*
326         * FIXME: wait 200us
327         */
328        /*
329         * enable  DDR SDRAM
330         */
331        SET_IMM_REGW r31,r30,DDR_SDRAM_CFG_OFF,DDR_SDRAM_CFG_VAL | DDR_SDRAM_CFG_MEM_EN
332        /*
333         * wait, until DDR_SDRAM_CFG_2_D_INIT is cleared
334         */
3351:      lwz r30,DDR_SDRAM_CFG_2_OFF(r31)
336        andi. r30,r30,DDR_SDRAM_CFG_2_D_INIT
337        bne 1b
338#endif
339#ifdef DDR_ERR_DISABLE_VAL2
340        /*
341         * enable detect of some RAM errors
342         */
343        SET_IMM_REGW r31,r30,DDR_ERR_DISABLE_OFF,DDR_ERR_DISABLE_VAL2
344#endif
345#ifdef DDR_SDRAM_INTERVAL_VAL
346        /*
347         * set the refresh interval
348         */
349        SET_IMM_REGW r31,r30,DDR_SDRAM_INTERVAL_OFF,DDR_SDRAM_INTERVAL_VAL
350#endif
351start_rom_skip:
352        /*
353         * determine current execution address offset
354         */
355        bl start_rom_skip1
356start_rom_skip1:
357        mflr r20
358        LA   r30,start_rom_skip1
359        sub. r20,r20,r30       
360        /*
361         * execution address offset == 0?
362         * then do not relocate code and data
363         */
364        beq  start_code_in_ram
365        /*
366         * ROM or relocatable startup: copy startup code to SDRAM
367         */
368        /* get start address of text section in RAM */
369        LA      r29, bsp_section_text_start 
370        /* get start address of text section in ROM (add reloc offset) */
371        add     r30, r20, r29   
372        /* get size of startup code */
373        LA      r28, end_reloc_startup
374        LA      r31, bsp_section_text_start
375        sub     28,r28,r31
376        /* copy startup code from ROM to RAM location */
377        bl      copy_image     
378       
379        /*
380         * ROM startup: jump to code copy in  SDRAM
381         */
382        /* get compile time address of label */
383        LA      r29, copy_rest_of_text
384        mtlr    r29
385        blr                     /* now further execution RAM */
386copy_rest_of_text:     
387#ifdef LCRR_VAL
388        SET_IMM_REGW r31,r30,LCRR_OFF,LCRR_VAL
389#endif
390        /*
391         * ROM or relocatable startup: copy rest of code to SDRAM
392         */
393        /* get start address of rest of code in RAM */
394        LA      r29, end_reloc_startup
395        /* get start address of text section in ROM (add reloc offset) */
396        add     r30, r20, r29   
397        /* get size of rest of code */
398        LA      r28, bsp_section_text_start
399        LA      r31, bsp_section_text_size
400        add     r28,r28,r31
401        sub     r28,r28,r29
402        bl      copy_image      /* copy text section from ROM to RAM location */
403       
404        /*
405         * ROM or relocatable startup: copy data to SDRAM
406         */
407        /* get start address of data section in RAM */
408        LA      r29, bsp_section_data_start
409        /* get start address of data section in ROM (add reloc offset) */
410        add     r30, r20, r29   
411        /* get size of RAM image */
412        LA      r28, bsp_section_data_size 
413        /* copy initialized data section from ROM to RAM location */
414        bl      copy_image       
415
416start_code_in_ram:     
417
418        /*
419         * ROM/RAM startup: clear bss in SDRAM
420         */
421        LA      r3, bsp_section_bss_start  /* get start address of bss section */
422        LWI     r4, bsp_section_bss_size   /* get size of bss section */
423        bl      mpc83xx_zero_4          /* Clear the bss section */
424        /*
425         * call boot_card
426         */
427
428        /* Set stack pointer (common for RAM/ROM startup) */
429        LA      r1, bsp_section_text_start 
430        addi    r1, r1, -0x10 /* Set up stack pointer = beginning of text section - 0x10 */     
431
432        /* Create NULL */
433        li r0, 0
434
435        /* Return address */
436        stw r0, 4(r1)
437
438        /* Back chain */
439        stw r0, 0(r1)
440
441        /* Read-only small data */
442        LA r2, _SDA2_BASE_
443
444        /* Read-write small data */
445        LA r13, _SDA_BASE_
446
447/* clear arguments and do further init. in C (common for RAM/ROM startup) */
448
449        /* Clear argc, argv and envp */
450        xor r3, r3, r3
451        xor r4, r4, r4
452        xor r5, r5, r5
453
454        bl      SYM (boot_card)  /* Call the first C routine */
455       
456twiddle:
457        /* We don't expect to return from boot_card but if we do */
458        /* wait here for watchdog to kick us into hard reset     */
459        b       twiddle         
460                                               
461copy_image:
462        mr      r27, r28
463        srwi    r28, r28, 2
464        mtctr   r28
465
466        slwi    r28, r28, 2
467        sub     r27, r27, r28                   /* maybe some residual bytes */
468copy_image_word:
469        lswi    r28, r30, 0x04
470       
471        stswi   r28, r29, 0x04                  /* do word copy ROM -> RAM */
472       
473
474        addi    r30, r30, 0x04                  /* increment source pointer */
475        addi    r29, r29, 0x04                  /* increment destination pointer */
476       
477        bdnz    copy_image_word                 /* decrement ctr and branch if not 0 */
478
479        cmpwi   r27, 0x00                       /* copy image finished ? */
480        beq     copy_image_end;
481        mtctr   r27                             /* reload counter for residual bytes */
482copy_image_byte:
483        lswi    r28, r30, 0x01
484       
485        stswi   r28, r29, 0x01                  /* do byte copy ROM -> RAM */
486       
487       
488        addi    r30, r30, 0x01                  /* increment source pointer */
489        addi    r29, r29, 0x01                  /* increment destination pointer */
490       
491        bdnz    copy_image_byte                 /* decrement ctr and branch if not 0 */
492       
493copy_image_end:
494        blr
495
496       
497/**
498 * @fn int mpc83xx_zero_4( void *dest, size_t n)
499 *
500 * @brief Zero all @a n bytes starting at @a dest with 4 byte writes.
501 *
502 * The address @a dest has to be aligned on 4 byte boundaries.  The size @a n
503 * must be evenly divisible by 4.
504 */
505GLOBAL_FUNCTION mpc83xx_zero_4
506        /* Create zero */
507        xor     r0, r0, r0
508
509        /* Set offset */
510        xor     r5, r5, r5
511
512        /* Loop counter for the first bytes up to 16 bytes */
513        rlwinm. r9, r4, 30, 30, 31
514        beq     mpc83xx_zero_4_more
515        mtctr   r9
516
517mpc83xx_zero_4_head:
518
519        stwx    r0, r3, r5
520        addi    r5, r5, 4
521        bdnz    mpc83xx_zero_4_head
522
523mpc83xx_zero_4_more:
524
525        /* More than 16 bytes? */
526        srwi.   r9, r4, 4
527        beqlr
528        mtctr   r9
529
530        /* Set offsets */
531        addi    r6, r5, 4
532        addi    r7, r5, 8
533        addi    r8, r5, 12
534
535mpc83xx_zero_4_tail:
536
537        stwx    r0, r3, r5
538        addi    r5, r5, 16
539        stwx    r0, r3, r6
540        addi    r6, r6, 16
541        stwx    r0, r3, r7
542        addi    r7, r7, 16
543        stwx    r0, r3, r8
544        addi    r8, r8, 16
545        bdnz    mpc83xx_zero_4_tail
546       
547        /* Return */
548        blr
549
550end_reloc_startup:
Note: See TracBrowser for help on using the repository browser.