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