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