Annotation of sys/arch/mvme68k/stand/sboot/sboot.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: sboot.c,v 1.9 2003/08/19 10:22:30 deraadt Exp $ */
2:
3: /*
4: * Copyright (c) 1995 Theo de Raadt
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: * 2. Redistributions in binary form must reproduce the above copyright
12: * notice, this list of conditions and the following disclaimer in the
13: * documentation and/or other materials provided with the distribution.
14: *
15: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16: * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25: * SUCH DAMAGE.
26: *
27: * Copyright (c) 1995 Charles D. Cranor and Seth Widoff
28: * All rights reserved.
29: *
30: * Redistribution and use in source and binary forms, with or without
31: * modification, are permitted provided that the following conditions
32: * are met:
33: * 1. Redistributions of source code must retain the above copyright
34: * notice, this list of conditions and the following disclaimer.
35: * 2. Redistributions in binary form must reproduce the above copyright
36: * notice, this list of conditions and the following disclaimer in the
37: * documentation and/or other materials provided with the distribution.
38: * 3. All advertising materials mentioning features or use of this software
39: * must display the following acknowledgement:
40: * This product includes software developed by Charles D. Cranor
41: * and Seth Widoff.
42: * 4. The name of the author may not be used to endorse or promote products
43: * derived from this software without specific prior written permission.
44: *
45: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
46: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
48: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
49: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
51: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
52: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
53: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
54: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55: */
56:
57: #include <sys/cdefs.h>
58: #include <sys/types.h>
59: #include "sboot.h"
60:
61: int
62: main(int argc, char *argv[])
63: {
64: char buf[128], *ebuf;
65:
66: buf[0] = '0';
67: printf("\nsboot: MVME147 bootstrap program\n");
68: while (1) {
69: printf(">>> ");
70: ebuf = ngets(buf, sizeof(buf));
71: do_cmd(buf, ebuf);
72: }
73: /* not reached */
74: }
75:
76: /*
77: * exit to rom
78: */
79: void
80: callrom(void)
81: {
82: asm("trap #15; .word 0x0063");
83: }
84:
85: /*
86: * do_cmd: do a command
87: */
88: void
89: do_cmd(char *buf, char *ebuf)
90: {
91: switch (*buf) {
92: case '\0':
93: break;
94: case 'a':
95: if (rev_arp()) {
96: printf("My ip address is: %d.%d.%d.%d\n", myip[0],
97: myip[1], myip[2], myip[3]);
98: printf("Server ip address is: %d.%d.%d.%d\n", servip[0],
99: servip[1], servip[2], servip[3]);
100: } else {
101: printf("Failed.\n");
102: }
103: break;
104: case 'q':
105: printf("exiting to ROM\n");
106: callrom();
107: break;
108: case 'f':
109: if (do_get_file() == 1) {
110: printf("Download Failed\n");
111: } else {
112: printf("Download was a success!\n");
113: }
114: break;
115: case 'b':
116: le_init();
117: if (rev_arp()) {
118: printf("client IP address %d.%d.%d.%d\n", myip[0],
119: myip[1], myip[2], myip[3]);
120: printf("server IP address %d.%d.%d.%d\n", servip[0],
121: servip[1], servip[2], servip[3]);
122: } else {
123: printf("REVARP: Failed.\n");
124: return;
125: }
126: if (do_get_file() == 1) {
127: printf("Download Failed\n");
128: return;
129: } else {
130: printf("received secondary boot program.\n");
131: }
132: if (*++buf == '\0')
133: buf = " bsd";
134: go(LOAD_ADDR, buf+1, ebuf);
135: break;
136: case 'h':
137: case '?':
138: printf("valid commands\n");
139: printf("a - send a RARP\n");
140: printf("b - boot the system\n");
141: printf("q - exit to ROM\n");
142: printf("f - ftp the boot file\n");
143: printf("g - execute the boot file\n");
144: printf("h - help\n");
145: printf("i - init LANCE enet chip\n");
146: break;
147: case 'i':
148: le_init();
149: break;
150: case 'g':
151: go(LOAD_ADDR, buf+1, ebuf);
152: break;
153: default:
154: printf("sboot: %s: Unknown command\n", buf);
155: }
156: }
157:
158: /*
159: * ngets: get string from console
160: */
161: char *
162: ngets(char * str, int size)
163: {
164: int i = 0;
165:
166: while ((i < size - 1) && (str[i] = getchar()) != '\r') {
167: if (str[i] == '\b' || str[i] == 0x7F) {
168: if (i == 0)
169: continue;
170: i--;
171: printf("\b \b");
172: continue;
173: }
174: putchar(str[i]);
175: i++;
176: }
177: printf("\n");
178: str[i] = '\0';
179: return(&str[i]);
180: }
CVSweb