SRT0.S revision 1.1.126.1 1 | $NetBSD: SRT0.S,v 1.1.126.1 2008/06/02 13:22:47 mjf Exp $
2
3 | Copyright (c) 1998 The NetBSD Foundation, Inc.
4 | All rights reserved.
5 |
6 | This code is derived from software contributed to The NetBSD Foundation
7 | by Gordon W. Ross.
8 |
9 | Redistribution and use in source and binary forms, with or without
10 | modification, are permitted provided that the following conditions
11 | are met:
12 | 1. Redistributions of source code must retain the above copyright
13 | notice, this list of conditions and the following disclaimer.
14 | 2. Redistributions in binary form must reproduce the above copyright
15 | notice, this list of conditions and the following disclaimer in the
16 | documentation and/or other materials provided with the distribution.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 | POSSIBILITY OF SUCH DAMAGE.
29
30 #include <machine/asm.h>
31
32 | SRT0.S - Stand-alone Run-Time startup code, part 0
33 .file "SRT0.S"
34 .data
35
36 | Flush the CPU cache using MC68020 values just to be safe.
37 | This will cause the MC68030 to run with the data cache
38 | disabled, but that is OK for boot programs.
39 .set IC_CLEAR,0x9
40 .set PSL_HIGHIPL,0x2700
41
42 .text
43
44 ASENTRY_NOPROFILE(start)
45 | Disable interrupts (just in case...)
46 movw #PSL_HIGHIPL,%sr
47
48 | Check to see if the code is located correctly.
49 | Get current location via PC-relative load, then...
50 lea %pc@(start:w),%a0 | current location (0x4000)
51 | ...force a long (not PC-relative) load to a1 and compare.
52 lea start:l,%a1 | desired location (LINKADDR)
53 cmpl %a0,%a1
54 beqs restart
55
56 | Relocate the code and data to where they belong.
57 movl #_edata,%d0 | Desired end of program
58 subl %a1,%d0 | Calculate length, round up.
59 lsrl #2,%d0
60 Lcp:
61 movl %a0@+,%a1@+
62 dbra %d0,Lcp
63
64 | If we are on a sun2, we don't want to clear the I-cache
65 | because we don't have one. We are on a sun2 if the PROM
66 | has pointed the vector base register to zero. This is
67 | similar to the test that SRT1.c's _start does.
68 movc %vbr, %d0
69 tstl %d0
70 beqs Ljmpreloc
71 | Clear the I-cache in case the copied code was cached.
72 movl #IC_CLEAR,%d0
73 movc %d0,%cacr
74 Ljmpreloc:
75 | Force a long jump to the relocated code (not pc-relative)
76 lea restart:l,%a0
77 jmp %a0@
78
79 | Define the location of our stack (just before relocated text).
80 | Leave room the exit jmpbuf at the end of our stack.
81 .set estack,start-60
82
83 restart:
84 | Now in the relocated code, using the monitor stack.
85 | Save this context so we can return with it.
86 pea estack
87 jsr _C_LABEL(setjmp)
88 addqw #4,%sp
89 tstl %d0
90 bne Ldone | here via longjmp
91
92 | Switch to our own stack.
93 lea estack,%a0
94 movl %a0,%sp
95 subl %a6,%a6
96
97 | Clear out BSS...
98 lea _edata,%a0
99 lea _end,%a1
100 Lclrbss:
101 clrl %a0@+
102 cmpl %a1,%a0
103 ble Lclrbss
104
105 | Call the run-time startup C code, which will:
106 | initialize, call main, call exit.
107 jsr _C_LABEL(_start)
108
109 | Switch back to the monitor stack, then either
110 | "chain" to the next program or return.
111 ENTRY(exit)
112 pea estack
113 jsr _C_LABEL(longjmp) | to next line
114 Ldone:
115 movl _C_LABEL(chain_to_func),%a0
116 movl %a0,%d0
117 beq Lret
118 jmp %a0@
119 Lret:
120 rts
121
122 | function to clear the I-cache
123 ENTRY(ICIA)
124 tstl _C_LABEL(_is2)
125 bne Lret
126 movl #IC_CLEAR,%d0
127 movc %d0,%cacr
128 rts
129
130 | function to get the vector base register
131 ENTRY(getvbr)
132 movc %vbr,%a0
133 rts
134
135 | Kernel version of setjmp/longjmp (label_t is 16 words)
136
137 ENTRY(setjmp)
138 movl %sp@(4),%a0 | savearea pointer
139 moveml #0xFCFC,%a0@ | save d2-d7/a2-a7
140 movl %sp@,%a0@(48) | and return address
141 movl #0,%d0 | return 0
142 rts
143
144 ENTRY(longjmp)
145 movl %sp@(4),%a0 | savearea pointer
146 moveml %a0@+,#0xFCFC | restore d2-d7/a2-a7
147 | Note: just changed sp!
148 movl %a0@,%sp@ | and return address
149 movl #1,%d0 | return 1
150 rts
151
152 | The end.
153