source: rtems/c/src/lib/libbsp/powerpc/mvme5500/start/preload.S @ ee732739

4.104.114.84.95
Last change on this file since ee732739 was ee732739, checked in by Joel Sherrill <joel.sherrill@…>, on 09/13/07 at 14:26:24

2007-09-07 Kate Feng <feng1@…>

  • ChangeLog?, Makefile.am, README, README.booting, README.irq, preinstall.am, GT64260/MVME5500I2C.c, include/bsp.h, irq/irq.c, irq/irq.h, irq/irq_init.c, pci/detect_host_bridge.c, pci/pci.c, pci/pci_interface.c, pci/pcifinddevice.c, start/preload.S, startup/bspclean.c, startup/bspstart.c, startup/pgtbl_activate.c, startup/reboot.c, vectors/bspException.h, vectors/exceptionhandler.c: Merge my improvements in this BSP including a new network driver for the 1GHz NIC.
  • network/if_100MHz/GT64260eth.c, network/if_100MHz/GT64260eth.h, network/if_100MHz/GT64260ethreg.h, network/if_100MHz/Makefile.am, network/if_1GHz/Makefile.am, network/if_1GHz/POSSIBLEBUG, network/if_1GHz/if_wm.c, network/if_1GHz/if_wmreg.h, network/if_1GHz/pci_map.c, network/if_1GHz/pcireg.h: New files.
  • Property mode set to 100644
File size: 8.3 KB
Line 
1/*
2 * Mini-loader for the SVGM BSP.
3 *
4 * $Id$
5 *
6 * Author: Till Straumann, 10/2001 <strauman@slac.stanford.edu>
7 *
8 * Some ideas are borrowed from the powerpc/shared/bootloader
9 * by
10 *  Copyright (C) 1998, 1999 Gabriel Paubert, paubert@iram.es
11 *  Copyright (C) 1999 Eric Valette. valette@crf.canon.fr
12 *
13 * The SMON firmware is unable to load the RTEMS image below
14 * 0x2000 (I believe their stack is growing below 0x1000).
15 *
16 * The code provided by this file is responsible for the performing
17 * the following steps:
18 *
19 *  1) Save commandline parameters to an area that is
20 *       a) not covered by the downloaded image
21 *       b) will not be overwritten by the moved image
22 *          nor the final BSS segment (rtems clears BSS
23 *          before saving the command line).
24 *  2) Move the entire image (including this very file) to
25 *     its final location starting at 0x0000.
26 *     It is important to note that _NO_STACK_ is available
27 *     during this step. Also, there is probably no return to
28 *     SMON because relocating RTEMS will destroy vital SMON
29 *     data (such as its stack).
30 *  3) Flush the cache to make sure the relocated image is actually
31 *     in memory.
32 *  4) setup RTEMS environment (initial register values), most
33 *     notably an initial STACK. The initial stack may be small and
34 *     is used by RTEMS only at a very early stage.
35 *     A safe place for the stack seems to be the 00..0x7f area.
36 *     NOTE: we should respect the MAILBOX area 0x80..0xff!
37 *  5) switch the MMU off (because that's what RTEMS is expecting
38 *     it to be at startup).
39 *  6) fire up rtems...
40 *
41 *
42 *  Calling convention:
43 *     R1: SMON SP
44 *     R3: command line string start
45 *     R4: command line string end + 1
46 *     R5: where SMON put the image
47 *         if R5 is 0, the preloader will use its entry point
48 *         as the image starting address.
49 *         See NOTE below.
50 *     R6: end of the image (i.e. R6-R5 is the image length)
51 *         if R6 is 0, _edata will be used as the image length
52 *         See NOTE below.
53 *
54 *     NOTE: if the symbol DONT_USE_R5_ENTRY is defined,
55 *         R5/R6 are never used and the necessary parameters are
56 *         determined at runtime (R5) / linkage (R6) [_edata]
57 *
58 *  ASSUMPTIONS:
59 *    The code RELIES on the assumption that the image will be
60 *    moved DOWNWARDS in memory and that the this loader is
61 *    prepended to the image, i.e. it is safe to do
62 *        codemove(codemove,0,codemove_end - codemove);
63 *        (*0)(codemove_end, codemove_end-codemove, __rtems_end-codemove_end);
64 *    where codemove(from, to, nbytes) is defined as
65 *        codemove(from, to, nbytes) { while (nbytes--) *(to++)=*(from++); }
66 *    Implicit to these assumptions is the assumption that the destination
67 *    address is cache block aligned.
68 *    Furthermore, the byte count is assumed to be a multiple
69 *    of four
70 *
71 */
72#if 0
73#include <rtems/score/powerpc.h>
74#else
75#ifndef PPC_CACHE_ALIGNMENT
76#define PPC_CACHE_ALIGNMENT     32
77#endif
78#endif
79
80#include <rtems/score/cpu.h>
81#include <rtems/asm.h>
82
83/* Note that major modifications may be needed
84 * if DESTINATION_ADDR is not 0
85 */
86#define KERNELBASE                      0x0
87#define INITIAL_STACK           0x78                                    /* 8-byte aligned */
88#define CACHE_LINE_SIZE         PPC_CACHE_ALIGNMENT     /* autodetect doesn't work, see below */
89#define ASSUME_RTEMS_INSTALLS_VECTORS                           /* assume we need not load vectors */
90#define DONT_USE_R5_ENTRY                                                       /* always dynamically determine the address we're running from */
91
92        /* put this into its own section which we want to
93         * be loaded at the very beginning. We should probably
94         * not use more than 255 bytes.
95         */
96        PUBLIC_VAR(__rtems_start)
97        PUBLIC_VAR(__rtems_entry_point)
98        PUBLIC_VAR(__rtems_end)
99        .section .entry_point_section,"awx",@progbits
100preload:
101        /* find out where we are */
102        bl      here
103here:
104        xor             r0,r0,r0
105        mtmsr   r0      /* clear MSR to known state */
106        mflr    r5
107        addi    r5,r5,-(here-preload)
108        lis             r27,_edata@h
109        ori             r27,r27,_edata@l
110
111        /* at this point the register contents are
112         * R3:  command line start
113         * R4:  R3 + command line length
114         * R5:  address we are running from / loaded to
115         * R27: image end
116         */
117
118        /* save command line start */
119        mr              r6, r3
120        /* save the command line parameters if they are to be overwritten */
121        sub.    r17, r4, r3             /* string length */
122        ble             leaveparms              /* <=0 -> no parameters */
123        /* copy has to be out of the way of the bss; therefore we must
124         * put the string out of the way of both, the current end of
125         * the image (without bss) AND the end of the loaded image
126         * (including bss):
127         * |......image.........|  downloaded image
128         * |image_bss...........|  loaded image with bss appended
129         *
130         *             ^ safe place for string
131         *
132         * the alternative scenario looks like this:
133         * |..image.............|  downloaded image
134         * |image_bss...........|  loaded image with bss appended
135         *           ^ safe place for string
136         */
137        lis             r18, __rtems_end+0x10000@h      /* round up, save one instruction */
138        add             r16, r5, r27    /* image end + 1 */
139        cmpw    r16, r18
140        bge             ishighenough
141        mr              r16,r18                 /* __rtems_end is higher than the image end
142                                                         * (without bss)
143                                                         */
144ishighenough:
145        cmpw    r16, r3             /* destination start > current string start ? */
146        ble             leaveparms              /* string already after dst, leave it */
147        /* copy string from the last byte downwards */
148        add             r6, r16, r17    /* last byte of destination + 1 */
149        mtctr   r17
1501:
151        lbzu    r3, -1(r4)
152        stbu    r3,     -1(r6)
153        bdnz    1b
154leaveparms:
155        add             r7, r6, r17             /* destination + strlen */
156
157#ifndef CACHE_LINE_SIZE
158        /* Oh well, SMON has inhibited the cache, so this
159         * nice routine doesn't work...
160         */
161        /* figure out the cache line size */
162        li              r16, 0x80
163        cmpw    r5, r16                 /* 'from' must be > 0x80 */
164        blt             panic
165       
1661:      /* store some arbitrary, nonzero stuff in 0..0x7c */
167        stwu    r16,-4(r16)
168        cmpwi   r16,0
169        bne             1b
170        dcbz    0,r16                   /* zero out one cache line */
171        subi    r16,r16,4
1722:      lwzu    r0,4(r16)               /* search for a non-zero word */
173        cmpwi   r0,0
174        beq             2b
175        /* OK, r16 now hold the size of a cache line in bytes */
176#else
177        li              r16,CACHE_LINE_SIZE
178#endif
179       
180    lis         r3,preload@h
181        ori             r3,r3,preload@l
182        mr              r4,r5                   /* from-addr */
183        li              r5,_preload_size/* this is never > 16k */
184        /* now move ourselves to the link address ('preload').
185         * We set up the LR, so domove() 'returns' to the
186         * relocated copy
187         */
188        lis             r0,return_here@h
189        ori             r0,r0,return_here@l
190        mtlr    r0     
191        b               domove                  /* move the preloader itself */
192return_here:
193        /* now we move the entire rest of the image */
194#ifdef ASSUME_RTEMS_INSTALLS_VECTORS
195        lis             r3,__rtems_start@h
196        ori             r3,r3,__rtems_start@l
197        lis             r0,preload@h    /* calculate/adjust from address */
198        ori             r0,r0,preload@l
199        sub             r0,r3,r0
200        add             r4,r4,r0
201        sub             r5,r27,r3
202#else
203        add             r3,r3,r5                /* add preloader size to destination */
204        add             r4,r4,r5                /* and source addresses */
205        sub             r5,r27,r5               /* length of the remaining rest */
206#endif
207        bl              domove
208        /* OK, now everything should be in place.
209     * we are ready to start...
210         */
211
212        /* setup initial stack for rtems early boot */
213        li              r1,INITIAL_STACK
214        /* disable the MMU and fire up rtems */
215        mfmsr   r0
216        ori     r0,r0,MSR_IR|MSR_DR|MSR_IP|MSR_ME
217        xori    r0,r0,MSR_IR|MSR_DR
218        mtsrr1  r0
219        lis             r0,__rtems_entry_point@h
220        ori             r0,r0,__rtems_entry_point@l
221        mtsrr0  r0
222        /* R6: start of command line */
223        /* R7: end of command line +1 */
224        rfi
225
226    /* domove(to, from, nbytes):
227     *
228     * move a R5 bytes from R4 to R3 and flush
229     * the caches for the destination memory
230     * region. R16 provides the cache line size.
231         * DESTROYS: R0, R17, R18, CTR, CR
232     */
233domove:
234        addi    r0,r5,3                 /* convert to word count */
235        srwi.   r0,r0,2
236        beq     3f                                      /* nothing to do */
237        cmpw    r3,r4                   /* from == to ?  */
238        beq 3f
239        mtctr   r0
240        la              r18,-4(r4)
241        la              r17,-4(r3)
2421:      lwzu    r0,4(r18)
243        stwu    r0,4(r17)
244        bdnz    1b                              /* move data */
245        /* now, we must flush the destination cache region */
246#ifndef CACHE_LINE_SIZE
247        cmpwi   r16,0
248        beq             3f                              /* nothing to do */
249#endif
250#if defined(CACHE_LINE_SIZE) && CACHE_LINE_SIZE > 0
251        add             r17,r3,r5               /* target end pointer */
252        subi    r0,r16,1
253        add             r17,r17,r0
254        andc    r17,r17,r0              /* cache aligned target end pointer */
255        mr              r18,r3
2562:      cmpw    r18,r17
257        dcbst   0,r18                   /* write out data cache line */
258        icbi    0,r18                   /* invalidate corresponding i-cache line */
259        add             r18,r18,r16
260        blt             2b
261        sync                                    /* make sure data is written back */
262        isync                                   /* invalidate possibly preloaded instructions */
263#endif
2643:
265        blr
266
267#if !defined(CACHE_LINE_SIZE)
268panic:
269        li              r10,0x63
270        mfmsr   r0
271        ori             r0,r0,MSR_IP
272        mtmsr   r0
273        sc
274#endif
275
276/* DONT PUT ANY CODE BELOW HERE */
277_preload_size = . - preload
Note: See TracBrowser for help on using the repository browser.