Annotation of sys/arch/mvme68k/stand/libsa/SRT0.S, Revision 1.1
1.1 ! nbrk 1: | $OpenBSD: SRT0.S,v 1.7 2001/07/04 08:06:56 niklas Exp $
! 2: | $NetBSD: SRT0.S,v 1.2 1995/08/12 18:38:55 gwr Exp $
! 3:
! 4: | Copyright (c) 1995 Gordon W. Ross
! 5: | All rights reserved.
! 6: |
! 7: | Redistribution and use in source and binary forms, with or without
! 8: | modification, are permitted provided that the following conditions
! 9: | are met:
! 10: | 1. Redistributions of source code must retain the above copyright
! 11: | notice, this list of conditions and the following disclaimer.
! 12: | 2. Redistributions in binary form must reproduce the above copyright
! 13: | notice, this list of conditions and the following disclaimer in the
! 14: | documentation and/or other materials provided with the distribution.
! 15: | 3. The name of the author may not be used to endorse or promote products
! 16: | derived from this software without specific prior written permission.
! 17: | 4. All advertising materials mentioning features or use of this software
! 18: | must display the following acknowledgement:
! 19: | This product includes software developed by Gordon Ross
! 20: |
! 21: | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 22: | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 23: | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
! 24: | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
! 25: | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
! 26: | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
! 27: | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
! 28: | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 29: | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
! 30: | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 31:
! 32: | this is a pre-startup wrapper for bugcrt which relocates the
! 33: | code to the correct place before exec()ing.
! 34:
! 35: | SRT0.S - Stand-alone Run-Time startup code, part 0
! 36: .file "SRT0.S"
! 37: .text
! 38: .globl __estack
! 39: __estack:
! 40: .globl xstart
! 41: xstart:
! 42: | first, relocate code to correct place without touching critical regs
! 43: | (args are in: d0, d1, d4, a0, a1, a2, a3, a4, a5, a6)
! 44: | [a3 and a4 only when netbooting]
! 45: movl a3, d3 | SAVE a3 in d3
! 46: movl a4, d5 | SAVE a4 in d5
! 47: lea pc@(xstart:w), a3 | a3 = current addr (could be anywhere)
! 48: lea xstart:l, a4 | a4 = desired location (LINKADDR)
! 49: cmpl a3, a4 | already there?
! 50: beqs restart | short-circuit out
! 51:
! 52: | Relocate the code and data
! 53: movl #_edata,d2 | Desired end of program
! 54: subl a4,d2 | Calculate length, round up.
! 55: lsrl #2,d2
! 56: Lcp:
! 57: movl a3@+, a4@+
! 58: dbra d2, Lcp
! 59:
! 60: | Force a long jump to the relocated code (not pc-relative)
! 61: lea restart:l, a3
! 62: jmp a3@
! 63:
! 64: restart:
! 65: | now in the relocated code
! 66:
! 67: | Set up stack (just before relocated text)
! 68: lea __estack:l, a3
! 69: movl a3, sp
! 70:
! 71: | now that we have relocated, call the bugcrt (note we skip over the special
! 72: | bug header which has a PC and SP in it)
! 73: movl d3, a3 | RESTORE a3
! 74: movl d5, a4 | RESTORE a4
! 75: jmp _start
! 76:
! 77: | The end.
CVSweb