Home | History | Annotate | Line # | Download | only in common
      1  1.3    isaki /*	$NetBSD: exec_image.S,v 1.3 2024/01/07 07:58:34 isaki Exp $	*/
      2  1.1  minoura 
      3  1.1  minoura /*
      4  1.1  minoura  * Copyright (c) 2001 Minoura Makoto.
      5  1.1  minoura  * All rights reserved.
      6  1.1  minoura  *
      7  1.1  minoura  * Redistribution and use in source and binary forms, with or without
      8  1.1  minoura  * modification, are permitted provided that the following conditions
      9  1.1  minoura  * are met:
     10  1.1  minoura  * 1. Redistributions of source code must retain the above copyright
     11  1.1  minoura  *    notice, this list of conditions and the following disclaimer.
     12  1.1  minoura  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  minoura  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  minoura  *    documentation and/or other materials provided with the distribution.
     15  1.1  minoura  *
     16  1.1  minoura  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1  minoura  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.1  minoura  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.1  minoura  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.1  minoura  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  1.1  minoura  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  1.1  minoura  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  1.1  minoura  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  1.1  minoura  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  1.1  minoura  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  1.1  minoura  */
     27  1.1  minoura 
     28  1.1  minoura #include <machine/asm.h>
     29  1.1  minoura 
     30  1.1  minoura #ifndef LASTADDR
     31  1.1  minoura #define LASTADDR	(0x00ed0008)
     32  1.1  minoura #endif
     33  1.1  minoura 
     34  1.1  minoura 	.text
     35  1.1  minoura 	.even
     36  1.1  minoura 
     37  1.1  minoura ENTRY_NOPROFILE(exec_image)
     38  1.1  minoura ||	void exec_image(loaded,executed,entry,size,bootdev,boothowto)
     39  1.3    isaki ||	unsigned int loaded;
     40  1.1  minoura ||	unsigned int executed;
     41  1.1  minoura ||	unsigned int entry;
     42  1.1  minoura ||	int size;
     43  1.1  minoura ||	int bootdev;
     44  1.1  minoura ||	int boothowto;
     45  1.1  minoura 	addl		#4,%sp			| throw away the return address
     46  1.1  minoura 	moveml		%sp@+,%a4-%a6
     47  1.1  minoura 	moveml		%sp@+,%d5-%d7
     48  1.1  minoura 
     49  1.1  minoura /* copy the trampoline to the last physical page. */
     50  1.1  minoura 	moval		LASTADDR,%sp		| tmpstack from end of physmem
     51  1.2  minoura 	lea		%sp@(-4096),%a3		| use last phys page as tramp
     52  1.1  minoura 
     53  1.1  minoura 	movl		#(end_trampoline-trampoline),%sp@-
     54  1.2  minoura 	pea		%pc@(trampoline)
     55  1.2  minoura 	pea		%a3@
     56  1.1  minoura 	jbsr		_C_LABEL(memcpy)	| memcpy() is still alive
     57  1.2  minoura 	lea		%sp@(12),%sp
     58  1.1  minoura 
     59  1.1  minoura 	jmp		%a3@			| jump to tramp
     60  1.1  minoura 
     61  1.1  minoura ASENTRY_NOPROFILE(trampoline)
     62  1.1  minoura ||	%a4:	loaded
     63  1.1  minoura ||	%a5:	executed
     64  1.1  minoura ||	%a6:	entry
     65  1.1  minoura ||	%d5:	size
     66  1.1  minoura ||	%d6:	bootdev
     67  1.1  minoura ||	%d7:	boothowto
     68  1.1  minoura 	movl		%d5,%sp@-		| push last arg (esym)
     69  1.1  minoura 	movel		LASTADDR,%sp@-		| second arg (physsize)
     70  1.2  minoura 	pea		%a5@			| first arg (firstpa)
     71  1.1  minoura 
     72  1.1  minoura 	cmpl		%a4,%a5			| if (l == x)
     73  1.1  minoura 	beq		L1			|	copy not required
     74  1.1  minoura 
     75  1.1  minoura /* this may overwrite the trap vectors; disable interrupt. */
     76  1.1  minoura 	oriw		#0x2700,%sr
     77  1.1  minoura 
     78  1.1  minoura L0:	movb		%a4@+,%a5@+		| copy kern to x
     79  1.1  minoura 	subql		#1,%d5
     80  1.1  minoura 	bne		L0
     81  1.1  minoura 
     82  1.1  minoura L1:
     83  1.1  minoura 	movq		#0,%d0			| reg arg (unused)
     84  1.1  minoura 	movq		#0,%d1			| reg arg (unused)
     85  1.1  minoura 	movq		#0,%d2			| reg arg (unused)
     86  1.1  minoura 	movq		#0,%d3			| reg arg (unused)
     87  1.1  minoura 	movq		#0,%d4			| reg arg (unused)
     88  1.1  minoura 	movq		#0,%d5			| reg arg (unused)
     89  1.1  minoura 						| bootdev(%d6) is already set
     90  1.1  minoura 						| boothowto(%d7) is already set
     91  1.1  minoura 	moval		%a6,%a0			| entry
     92  1.1  minoura 	moval		%d0,%a1			| reg arg (unused)
     93  1.1  minoura 	moval		%d0,%a2			| reg arg (unused)
     94  1.1  minoura 	moval		%d0,%a3			| reg arg (unused)
     95  1.1  minoura 	moval		%d0,%a4			| reg arg (unused)
     96  1.1  minoura 	moval		%d0,%a5			| reg arg (unused)
     97  1.1  minoura 	moval		%d0,%a6			| reg arg (unused)
     98  1.1  minoura 	movec		%a1,%vbr		| clear vbr
     99  1.1  minoura 
    100  1.1  minoura 	jsr		%a0@			| here we go!
    101  1.1  minoura 
    102  1.1  minoura 	/* NOTREACHED */
    103  1.1  minoura end_trampoline:
    104