Home | History | Annotate | Line # | Download | only in libsa
      1 /*	$NetBSD: SRT1.c,v 1.8 2009/01/12 07:00:59 tsutsui Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Gordon W. Ross.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /* SRT1.c - Stand-alone Run-time startup code, part 1 */
     33 
     34 #include <sys/types.h>
     35 #include <sun68k/mon.h>
     36 
     37 #include "libsa.h"
     38 #include "dvma.h"
     39 
     40 int _is2 = 0;
     41 int _is3x = 0;
     42 struct sunromvec *_romvec = 0;
     43 void *chain_to_func = 0;
     44 
     45 /*
     46  * These are the function pointers for sun2 vs sun3 vs sun3x stuff.
     47  */
     48 char *	(*dev_mapin_p)(int, u_long, int);
     49 char *	(*dvma_alloc_p)(int);
     50 void	(*dvma_free_p)(char *, int);
     51 char *	(*dvma_mapin_p)(char *, int);
     52 void	(*dvma_mapout_p)(char *, int);
     53 
     54 /*
     55  * This is called by SRT0.S
     56  * to do final prep for main
     57  */
     58 void
     59 _start(void)
     60 {
     61 	void **vbr;
     62 	int x;
     63 
     64 	/*
     65 	 * Determine sun2 vs sun3 vs sun3x by looking where the
     66 	 * vector base register points.  The PROM always
     67 	 * points that somewhere into [MONSTART..MONEND]
     68 	 * which is a different range on each.
     69 	 */
     70 
     71 	vbr = getvbr();
     72 	x = (int)vbr & 0xFFF00000;
     73 	if (x == SUN3X_MONSTART)
     74 		_is3x = 1;
     75 	else if (x == 0)
     76 		_is2 = 1;
     77 
     78 	/* Find the PROM vector. */
     79 	if (_is3x)
     80 		x = SUN3X_PROM_BASE;
     81 	else if (_is2)
     82 		x = SUN2_PROM_BASE;
     83 	else
     84 		x = SUN3_PROM_BASE;
     85 	_romvec = ((struct sunromvec *) x);
     86 
     87 	/* Setup trap 14 for use as a breakpoint. */
     88 	vbr[32+14] = _romvec->abortEntry;
     89 
     90 	/* Initialize sun3 vs sun3x function pointers. */
     91 	if (_is3x)
     92 		sun3x_init();
     93 	else if (_is2)
     94 		sun2_init();
     95 	else
     96 		sun3_init();
     97 
     98 	main();
     99 	exit(0);
    100 }
    101 
    102 void
    103 breakpoint(void)
    104 {
    105 	__asm volatile ("trap #14");
    106 }
    107 
    108 void
    109 chain_to(void *func)
    110 {
    111 
    112 	/*
    113 	 * If set, this pointer is jumped-to by exit
    114 	 * after carefully restoring the PROM stack.
    115 	 */
    116 	chain_to_func = func;
    117 	ICIA();
    118 	exit(0);
    119 }
    120