srtbegin.S revision 1.4.2.3 1 1.4.2.3 nathanw /* $NetBSD: srtbegin.S,v 1.4.2.3 2002/10/18 02:36:35 nathanw Exp $ */
2 1.4.2.2 nathanw
3 1.4.2.2 nathanw /*
4 1.4.2.2 nathanw * Copyright (c) 2002 Wasabi Systems, Inc.
5 1.4.2.2 nathanw * All rights reserved.
6 1.4.2.2 nathanw *
7 1.4.2.2 nathanw * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.4.2.2 nathanw *
9 1.4.2.2 nathanw * Redistribution and use in source and binary forms, with or without
10 1.4.2.2 nathanw * modification, are permitted provided that the following conditions
11 1.4.2.2 nathanw * are met:
12 1.4.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
13 1.4.2.2 nathanw * notice, this list of conditions and the following disclaimer.
14 1.4.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
15 1.4.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
16 1.4.2.2 nathanw * documentation and/or other materials provided with the distribution.
17 1.4.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
18 1.4.2.2 nathanw * must display the following acknowledgement:
19 1.4.2.2 nathanw * This product includes software developed for the NetBSD Project by
20 1.4.2.2 nathanw * Wasabi Systems, Inc.
21 1.4.2.2 nathanw * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.4.2.2 nathanw * or promote products derived from this software without specific prior
23 1.4.2.2 nathanw * written permission.
24 1.4.2.2 nathanw *
25 1.4.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.4.2.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.4.2.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.4.2.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.4.2.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.4.2.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.4.2.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.4.2.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.4.2.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.4.2.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.4.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
36 1.4.2.2 nathanw */
37 1.4.2.2 nathanw
38 1.4.2.2 nathanw #include <machine/asm.h>
39 1.4.2.2 nathanw #include <arm/armreg.h>
40 1.4.2.2 nathanw
41 1.4.2.2 nathanw #define STACKSIZE 1024
42 1.4.2.2 nathanw
43 1.4.2.2 nathanw ENTRY(start)
44 1.4.2.2 nathanw /*
45 1.4.2.2 nathanw * We assume we've been loaded VA==PA, or that the MMU
46 1.4.2.2 nathanw * is disabled. Make sure the MMU is disabled so that
47 1.4.2.2 nathanw * we don't have to care about the caches.
48 1.4.2.2 nathanw */
49 1.4.2.2 nathanw mrc p15, 0, r2, c1, c0, 0
50 1.4.2.2 nathanw bic r2, r2, #CPU_CONTROL_MMU_ENABLE
51 1.4.2.2 nathanw mcr p15, 0, r2, c1, c0, 0
52 1.4.2.2 nathanw
53 1.4.2.2 nathanw nop
54 1.4.2.2 nathanw nop
55 1.4.2.2 nathanw nop
56 1.4.2.2 nathanw
57 1.4.2.2 nathanw /*
58 1.4.2.2 nathanw * Check to see if __text_store == &start. If not, we're most
59 1.4.2.2 nathanw * likely running from flash. Flash is slow, and we'd
60 1.4.2.2 nathanw * really like to run the code from RAM. Copy it out.
61 1.4.2.2 nathanw */
62 1.4.2.3 nathanw adr r1, Ltext
63 1.4.2.2 nathanw ldmia r1, {r1-r3}
64 1.4.2.2 nathanw cmp r1, r2 /* __text_store == &start? */
65 1.4.2.2 nathanw beq relocated /* yes, in RAM */
66 1.4.2.2 nathanw
67 1.4.2.2 nathanw /* Copy text segment from ROM to RAM */
68 1.4.2.2 nathanw 1: ldrb r0, [r1], #0x01
69 1.4.2.2 nathanw strb r0, [r2], #0x01
70 1.4.2.2 nathanw cmp r2, r3 /* copy done? */
71 1.4.2.2 nathanw bne 1b
72 1.4.2.2 nathanw
73 1.4.2.2 nathanw /*
74 1.4.2.2 nathanw * Okay, we are finished relocating the text segment. Now
75 1.4.2.2 nathanw * we need to leap to the next instruction.
76 1.4.2.2 nathanw */
77 1.4.2.3 nathanw adr r1, Lrelocated
78 1.4.2.2 nathanw ldr pc, [r1]
79 1.4.2.2 nathanw
80 1.4.2.2 nathanw relocated:
81 1.4.2.2 nathanw /*
82 1.4.2.2 nathanw * Check to see if __data_store == __data_start. If not,
83 1.4.2.2 nathanw * we're most likely built for running from flash,
84 1.4.2.2 nathanw * and must copy the data segment out to RAM.
85 1.4.2.2 nathanw */
86 1.4.2.3 nathanw adr r1, Ldata
87 1.4.2.2 nathanw ldmia r1, {r1-r3}
88 1.4.2.2 nathanw cmp r1, r2 /* __data_store == __data_start? */
89 1.4.2.2 nathanw beq 2f /* yes, in RAM */
90 1.4.2.2 nathanw
91 1.4.2.2 nathanw /* Copy data segment from ROM to RAM */
92 1.4.2.2 nathanw 1: ldrb r0, [r1], #0x01
93 1.4.2.2 nathanw strb r0, [r2], #0x01
94 1.4.2.2 nathanw cmp r2, r3 /* copy done? */
95 1.4.2.2 nathanw bne 1b
96 1.4.2.2 nathanw
97 1.4.2.2 nathanw 2:
98 1.4.2.2 nathanw /* Clear the BSS. */
99 1.4.2.3 nathanw adr r1, Lbss
100 1.4.2.2 nathanw ldmia r1, {r1, r2}
101 1.4.2.2 nathanw sub r2, r2, r1
102 1.4.2.2 nathanw mov r3, #0
103 1.4.2.2 nathanw
104 1.4.2.2 nathanw 1: strb r3, [r1], #0x01
105 1.4.2.2 nathanw subs r2, r2, #0x01
106 1.4.2.2 nathanw bgt 1b
107 1.4.2.2 nathanw
108 1.4.2.2 nathanw /* Set the stack pointer */
109 1.4.2.3 nathanw adr r1, Lstack
110 1.4.2.2 nathanw ldr r1, [r1]
111 1.4.2.2 nathanw add sp, r1, #STACKSIZE
112 1.4.2.2 nathanw
113 1.4.2.2 nathanw b _C_LABEL(main)
114 1.4.2.2 nathanw
115 1.4.2.2 nathanw Lrelocated:
116 1.4.2.2 nathanw .word relocated
117 1.4.2.2 nathanw
118 1.4.2.2 nathanw Ltext:
119 1.4.2.2 nathanw .word _C_LABEL(__text_store)
120 1.4.2.2 nathanw .word _C_LABEL(start)
121 1.4.2.2 nathanw .word _C_LABEL(_etext)
122 1.4.2.2 nathanw
123 1.4.2.2 nathanw Ldata:
124 1.4.2.2 nathanw .word _C_LABEL(__data_store)
125 1.4.2.2 nathanw .word _C_LABEL(__data_start)
126 1.4.2.2 nathanw
127 1.4.2.2 nathanw Lbss:
128 1.4.2.2 nathanw .word _C_LABEL(_edata)
129 1.4.2.2 nathanw .word _C_LABEL(_end)
130 1.4.2.2 nathanw
131 1.4.2.2 nathanw Lstack:
132 1.4.2.2 nathanw .word Lstackspace
133 1.4.2.2 nathanw
134 1.4.2.2 nathanw .comm Lstackspace, STACKSIZE
135