source: rtems/bsps/powerpc/tqm8xx/start/start.S @ fbcd7c8f

5
Last change on this file since fbcd7c8f was fbcd7c8f, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/18 at 08:19:28

bsps: Move start files to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 7.0 KB
Line 
1/*===============================================================*\
2| Project: RTEMS generic TQM8xx BSP                               |
3+-----------------------------------------------------------------+
4|                    Copyright (c) 2008                           |
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.org/license/LICENSE.                           |
15|                                                                 |
16+-----------------------------------------------------------------+
17| this file contains the startup assembly code                    |
18| it is based on the gen83xx BSP                                  |
19\*===============================================================*/
20
21#include <libcpu/powerpc-utility.h>
22#include <rtems/powerpc/cache.h>
23#include <bsp.h>
24#include <mpc8xx.h>
25
26.extern boot_card
27
28PUBLIC_VAR (_start)
29PUBLIC_VAR (bsp_interrupt_stack_start)
30PUBLIC_VAR (bsp_interrupt_stack_end)
31
32.section ".bsp_start_text", "ax"
33_start:
34
35        /*
36         * basic CPU setup:
37         * init MSR
38         */
39        mfmsr   r30
40        SETBITS r30, r29, MSR_ME|MSR_RI
41        CLRBITS r30, r29, MSR_IP|MSR_EE
42        mtmsr   r30                             /* Set RI/ME, Clr EE in MSR */
43        /*
44         * init IMMR
45         */
46        LA  r30,m8xx
47        mtspr immr,r30
48        /*
49         * determine current execution address offset
50         */
51        bl start_1
52start_1:
53        mflr r20
54        LA   r30,start_1
55        sub. r20,r20,r30
56        /*
57         * execution address offset == 0?
58         * then do not relocate code and data
59         */
60        beq  start_code_in_ram
61        /*
62         * ROM or relocatable startup: copy startup code to SDRAM
63         */
64        /* get start address of text section in RAM */
65        LA      r29, bsp_section_text_begin
66        /* get start address of text section in ROM (add reloc offset) */
67        add     r30, r20, r29
68        /* get size of startup code */
69        LA      r28, end_reloc_startup
70        LA      r31, bsp_section_text_begin
71        sub     28,r28,r31
72        /* copy startup code from ROM to RAM location */
73        bl      copy_image
74
75        /*
76         * jump to code copy in  SDRAM
77         */
78        /* get compile time address of label */
79        LA      r29, copy_rest_of_text
80        mtlr    r29
81        blr                     /* now further execution RAM */
82copy_rest_of_text:
83        /*
84         * ROM or relocatable startup: copy rest of code to SDRAM
85         */
86        /* get start address of rest of code in RAM */
87        LA      r29, end_reloc_startup
88        /* get start address of text section in ROM (add reloc offset) */
89        add     r30, r20, r29
90        /* get size of rest of code */
91        LA      r28, bsp_section_text_begin
92        LA      r31, bsp_section_text_size
93        add     r28,r28,r31
94        sub     r28,r28,r29
95        bl      copy_image      /* copy text section from ROM to RAM location */
96
97        /*
98         * ROM or relocatable startup: copy data to SDRAM
99         */
100        /* get start address of data section in RAM */
101        LA      r29, bsp_section_data_begin
102        /* get start address of data section in ROM (add reloc offset) */
103        add     r30, r20, r29
104        /* get size of RAM image */
105        LA      r28, bsp_section_data_size
106        /* copy initialized data section from ROM to RAM location */
107        bl      copy_image
108
109start_code_in_ram:
110
111        /*
112         * ROM/RAM startup: clear bss in SDRAM
113         */
114        LA      r3, bsp_section_bss_begin  /* get start address of bss section */
115        LWI     r4, bsp_section_bss_size   /* get size of bss section */
116        bl      mpc8xx_zero_4          /* Clear the bss section */
117        /*
118         * call boot_card
119         */
120
121        /* Set stack pointer (common for RAM/ROM startup) */
122        LA      r1, bsp_section_text_begin
123        addi    r1, r1, -0x10 /* Set up stack pointer = beginning of text section - 0x10 */
124
125        /* Create NULL */
126        li r0, 0
127
128        /* Return address */
129        stw r0, 4(r1)
130
131        /* Back chain */
132        stw r0, 0(r1)
133
134        /* Read-only small data */
135        LA r2, _SDA2_BASE_
136
137        /* Read-write small data */
138        LA r13, _SDA_BASE_
139
140        /*
141         * init some CPU stuff
142         */
143        bl SYM (_InitTQM8xx)
144
145/* clear arguments and do further init. in C (common for RAM/ROM startup) */
146
147        /* Clear cmdline */
148        xor r3, r3, r3
149
150        bl      SYM (boot_card)  /* Call the first C routine */
151
152twiddle:
153        /* We don't expect to return from boot_card but if we do */
154        /* wait here for watchdog to kick us into hard reset     */
155        b       twiddle
156
157copy_with_watchdog:
158     addi    r5,r5,16
159     rlwinm. r5,r5,28,4,31
160     mtctr   r5
161
162copy_loop:
163     lwz     r6,0(r3)
164     lwz     r7,4(r3)
165     lwz     r8,8(r3)
166     lwz     r9,12(r3)
167     stw     r6,0(r4)
168     stw     r7,4(r4)
169     stw     r8,8(r4)
170     stw     r9,12(r4)
171     addi    r3,r3,16
172     addi    r4,r4,16
173     sth     r28,14(r30)
174     sth     r29,14(r30)
175     bdnz+   copy_loop
176     blr
177
178copy_image:
179        /*
180         * watchdog:
181         * r26 = immr
182         * r25 = watchdog magic 1
183         * r24 = watchdog magic 2
184         */
185        mfimmr  r26
186        rlwinm. r26,r26,0,0,15
187        li      r25,0x556c
188        li      r24,0xffffaa39
189
190        mr      r27, r28                /* determine number of 4word chunks */
191        srwi    r28, r28, 4
192        mtctr   r28
193
194        slwi    r28, r28, 4
195        sub     r27, r27, r28           /* determine residual bytes */
196copy_image_4word:
197        lwz     r20, 0(r30)             /* fetch data */
198        lwz     r21, 4(r30)
199        lwz     r22, 8(r30)
200        lwz     r23,12(r30)
201        stw     r20, 0(r29)             /* store data */
202        stw     r21, 4(r29)
203        stw     r22, 8(r29)
204        stw     r23,12(r29)
205
206        addi    r30, r30, 0x10          /* increment source pointer */
207        addi    r29, r29, 0x10          /* increment destination pointer */
208        /*
209         * trigger watchdog
210         */
211        sth     r25,14(r26)
212        sth     r24,14(r26)
213
214        bdnz    copy_image_4word        /* decrement ctr and branch if not 0 */
215
216        cmpwi   r27, 0x00               /* copy image finished ? */
217        beq     copy_image_end;
218        mtctr   r27                     /* reload counter for residual bytes */
219copy_image_byte:
220        lswi    r28, r30, 0x01
221
222        stswi   r28, r29, 0x01          /* do byte copy ROM -> RAM */
223
224
225        addi    r30, r30, 0x01          /* increment source pointer */
226        addi    r29, r29, 0x01          /* increment destination pointer */
227
228        bdnz    copy_image_byte         /* decrement ctr and branch if not 0 */
229
230copy_image_end:
231        blr
232
233
234/**
235 * @fn int mpc8xx_zero_4( void *dest, size_t n)
236 *
237 * @brief Zero all @a n bytes starting at @a dest with 4 byte writes.
238 *
239 * The address @a dest has to be aligned on 4 byte boundaries.  The size @a n
240 * must be evenly divisible by 4.
241 */
242GLOBAL_FUNCTION mpc8xx_zero_4
243        /* Create zero */
244        xor     r0, r0, r0
245
246        /* Set offset */
247        xor     r5, r5, r5
248
249        /* Loop counter for the first bytes up to 16 bytes */
250        rlwinm. r9, r4, 30, 30, 31
251        beq     mpc8xx_zero_4_more
252        mtctr   r9
253
254mpc8xx_zero_4_head:
255
256        stwx    r0, r3, r5
257        addi    r5, r5, 4
258        bdnz    mpc8xx_zero_4_head
259
260mpc8xx_zero_4_more:
261
262        /* More than 16 bytes? */
263        srwi.   r9, r4, 4
264        beqlr
265        mtctr   r9
266
267        /* Set offsets */
268        addi    r6, r5, 4
269        addi    r7, r5, 8
270        addi    r8, r5, 12
271
272mpc8xx_zero_4_tail:
273
274        stwx    r0, r3, r5
275        addi    r5, r5, 16
276        stwx    r0, r3, r6
277        addi    r6, r6, 16
278        stwx    r0, r3, r7
279        addi    r7, r7, 16
280        stwx    r0, r3, r8
281        addi    r8, r8, 16
282        bdnz    mpc8xx_zero_4_tail
283
284        /* Return */
285        blr
286
287end_reloc_startup:
288
289        /* Interrupt stack */
290        .section ".bsp_rwextra", "aw", @nobits
291        .align 4
292bsp_interrupt_stack_start:
293        .space 32768
294bsp_interrupt_stack_end:
Note: See TracBrowser for help on using the repository browser.