1 | $NetBSD: SRT0.S,v 1.1 2001/06/14 12:57:13 fredette Exp $
3 | Copyright (c) 1998 The NetBSD Foundation, Inc.
6 | This code is derived from software contributed to The NetBSD Foundation
9 | Redistribution and use in source and binary forms, with or without
10 | modification, are permitted provided that the following conditions
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.
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.
30 #include <machine/asm.h>
32 | SRT0.S - Stand-alone Run-Time startup code, part 0
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.
40 .set PSL_HIGHIPL,0x2700
44 ASENTRY_NOPROFILE(start)
45 | Disable interrupts (just in case...)
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)
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.
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.
71 | Clear the I-cache in case the copied code was cached.
75 | Force a long jump to the relocated code (not pc-relative)
79 | Define the location of our stack (just before relocated text).
80 | Leave room the exit jmpbuf at the end of our stack.
84 | Now in the relocated code, using the monitor stack.
85 | Save this context so we can return with it.
90 bne Ldone | here via longjmp
92 | Switch to our own stack.
105 | Call the run-time startup C code, which will:
106 | initialize, call main, call exit.
109 | Switch back to the monitor stack, then either
110 | "chain" to the next program or return.
113 jsr _C_LABEL(longjmp) | to next line
115 movl _C_LABEL(chain_to_func),%a0
122 | function to clear the I-cache
130 | function to get the vector base register
135 | Kernel version of setjmp/longjmp (label_t is 16 words)
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
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