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