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

Last change on this file since eeea4fee was eeea4fee, checked in by Christian Mauderer <christian.mauderer@…>, on 03/02/22 at 11:58:53

bsps/powerpc/tqm8xx: Manual file header clean up

Updates #4625.

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