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