1 1.1 skrll /* $NetBSD: srt0.S,v 1.1 2014/02/24 07:23:43 skrll Exp $ */ 2 1.1 skrll 3 1.1 skrll /* $OpenBSD: srt0.S,v 1.7 2001/05/16 23:57:35 mickey Exp $ */ 4 1.1 skrll 5 1.1 skrll /* 6 1.1 skrll * Copyright (c) 1998-2004 Michael Shalayeff 7 1.1 skrll * All rights reserved. 8 1.1 skrll * 9 1.1 skrll * Redistribution and use in source and binary forms, with or without 10 1.1 skrll * modification, are permitted provided that the following conditions 11 1.1 skrll * are met: 12 1.1 skrll * 1. Redistributions of source code must retain the above copyright 13 1.1 skrll * notice, this list of conditions and the following disclaimer. 14 1.1 skrll * 2. Redistributions in binary form must reproduce the above copyright 15 1.1 skrll * notice, this list of conditions and the following disclaimer in the 16 1.1 skrll * documentation and/or other materials provided with the distribution. 17 1.1 skrll * 18 1.1 skrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 1.1 skrll * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 1.1 skrll * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 1.1 skrll * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 22 1.1 skrll * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 1.1 skrll * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 1.1 skrll * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 1.1 skrll * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 1.1 skrll * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27 1.1 skrll * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 1.1 skrll * THE POSSIBILITY OF SUCH DAMAGE. 29 1.1 skrll */ 30 1.1 skrll /* 31 1.1 skrll * Copyright 1996 1995 by Open Software Foundation, Inc. 32 1.1 skrll * All Rights Reserved 33 1.1 skrll * 34 1.1 skrll * Permission to use, copy, modify, and distribute this software and 35 1.1 skrll * its documentation for any purpose and without fee is hereby granted, 36 1.1 skrll * provided that the above copyright notice appears in all copies and 37 1.1 skrll * that both the copyright notice and this permission notice appear in 38 1.1 skrll * supporting documentation. 39 1.1 skrll * 40 1.1 skrll * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 41 1.1 skrll * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 42 1.1 skrll * FOR A PARTICULAR PURPOSE. 43 1.1 skrll * 44 1.1 skrll * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 45 1.1 skrll * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 46 1.1 skrll * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 47 1.1 skrll * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 48 1.1 skrll * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 49 1.1 skrll * 50 1.1 skrll */ 51 1.1 skrll ; 52 1.1 skrll ; Copyright (c) 1990 mt Xinu, Inc. All rights reserved. 53 1.1 skrll ; Copyright (c) 1990 University of Utah. All rights reserved. 54 1.1 skrll ; 55 1.1 skrll ; This file may be freely distributed in any form as long as 56 1.1 skrll ; this copyright notice is included. 57 1.1 skrll ; THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 58 1.1 skrll ; IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 59 1.1 skrll ; WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 60 1.1 skrll ; 61 1.1 skrll ; Utah $Hdr: srt0.c 1.3 94/12/13$ 62 1.1 skrll ; 63 1.1 skrll 64 1.1 skrll #define _LOCORE 65 1.1 skrll #include <machine/iomod.h> 66 1.1 skrll #include <machine/asm.h> 67 1.1 skrll 68 1.1 skrll /* 69 1.1 skrll * This is the ending of the begin 70 1.1 skrll */ 71 1.1 skrll ENTRY(begin,0) 72 1.1 skrll 73 1.1 skrll blr %r0,%r5 ; Get address of 'boff' into 'r5', 74 1.1 skrll ldo begin-boff(%r5),%r5 ; and subtract to get 'begin'. 75 1.1 skrll boff: 76 1.1 skrll ldil L%RELOC,%r4 77 1.1 skrll ldo R%RELOC(%r4),%r4 78 1.1 skrll ldo start-begin(%r4),%rp 79 1.1 skrll ldil L%edata,%r3 80 1.1 skrll ldo R%edata(%r3),%r3 ; Get address of edata. 81 1.1 skrll ldil L%begin,%r1 82 1.1 skrll ldo R%begin(%r1),%r1 ; Get address of begin 83 1.1 skrll sub %r3,%r1,%r3 ; Subtract to get # of bytes to copy 84 1.1 skrll copyloop: ; do 85 1.1 skrll ldwm 4(%r5),%r1 ; *r4++ = *r5++; 86 1.1 skrll addib,>= -4,%r3,copyloop ; while (--r3 >= 0); 87 1.1 skrll stwm %r1,4(%r4) 88 1.1 skrll 89 1.1 skrll ; here we zero the .bss 90 1.1 skrll ldil L%__bss_start, %r4 91 1.1 skrll ldo R%__bss_start(%r4), %r4 92 1.1 skrll ldil L%__bss_end, %r3 93 1.1 skrll ldo R%__bss_end(%r3), %r3 94 1.1 skrll zeroloop: 95 1.1 skrll combf,<,n %r3,%r4, zeroloop ; while (r4 < r3); 96 1.1 skrll stwm %r0,4(%r4) ; *r4++ = 0; 97 1.1 skrll 98 1.1 skrll ldil L%$global$,%dp 99 1.1 skrll ldo R%$global$(%dp),%dp 100 1.1 skrll ldil L%start,%r1 101 1.1 skrll ldo R%start(%r1),%r1 102 1.1 skrll sub %dp,%r1,%dp ; Subtract to get difference 103 1.1 skrll add %rp,%dp,%dp ; and relocate it. 104 1.1 skrll 105 1.1 skrll ; 106 1.1 skrll ; We have relocated ourself to RELOC. If we are running on a machine 107 1.1 skrll ; with separate instruction and data caches, we must flush our data 108 1.1 skrll ; cache before trying to execute the code starting at rp. 109 1.1 skrll ; 110 1.1 skrll ldil L%RELOC,%r22 ; Set %t1 to start of relocated code. 111 1.1 skrll ldo R%RELOC(%r22),%r22 112 1.1 skrll ldil L%edata,%r21 ; Set r21 to address of edata 113 1.1 skrll ldo R%edata(%r21),%r21 114 1.1 skrll ldil L%begin,%r1 ; set %r1 to address of begin 115 1.1 skrll ldo R%begin(%r1),%r1 116 1.1 skrll sub %r21,%r1,%r21 ; Subtract to get length 117 1.1 skrll mtsp %r0,%sr0 ; Set sr0 to kernel space. 118 1.1 skrll ldo -1(%r21),%r21 119 1.1 skrll fdc %r21(0,%r22) 120 1.1 skrll loop: addib,>,n -16,%r21,loop ; Decrement by cache line size (16). 121 1.1 skrll fdc %r21(%sr0,%r22) 122 1.1 skrll fdc 0(%sr0,%r22) ; Flush first word at addr to handle 123 1.1 skrll sync ; arbitrary cache line boundary. 124 1.1 skrll nop ; Prevent prefetching. 125 1.1 skrll nop 126 1.1 skrll nop 127 1.1 skrll nop 128 1.1 skrll nop 129 1.1 skrll nop 130 1.1 skrll nop 131 1.1 skrll bv 0(%rp) 132 1.1 skrll nop 133 1.1 skrll EXIT(begin) /* jump to relocated code */ 134 1.1 skrll 135 1.1 skrll start: 136 1.1 skrll ldil L%HEAP_LIMIT, %sp 137 1.1 skrll ldo R%HEAP_LIMIT(%sp), %sp 138 1.1 skrll 139 1.1 skrll b boot ; Call boot(), 140 1.1 skrll copy %r0, %arg0 ; use default boot device 141 1.1 skrll nop 142 1.1 skrll 143 1.1 skrll /* 144 1.1 skrll * rtt - restart the box 145 1.1 skrll */ 146 1.1 skrll LEAF_ENTRY(_rtt) 147 1.1 skrll ldil L%LBCAST_ADDR, %r25 148 1.1 skrll ldi CMD_RESET, %r26 149 1.1 skrll stw %r26,R%iomod_command(%r25) 150 1.1 skrll forever: ; Loop until bus reset takes effect. 151 1.1 skrll b,n forever 152 1.1 skrll 153 1.1 skrll bv 0(%rp) 154 1.1 skrll ldo -48(%sp),%sp 155 1.1 skrll EXIT(_rtt) 156 1.1 skrll 157 1.1 skrll .end 158