sboot.c revision 1.1 1 /*
2 *
3 * Copyright (c) 1995 Charles D. Cranor and Seth Widoff
4 * All rights reserved.
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 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Charles D. Cranor
17 * and Seth Widoff.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 /*
33 * main driver, plus machdep stuff
34 */
35
36 #include "sboot.h"
37
38 void sboot()
39
40 {
41 char * mesg;
42 char buf[128];
43 buf[0] = '0';
44 consinit();
45 printf("\nsboot: serial line bootstrap program (&end = %x)\n\n", &end);
46 if (reboot) { /* global flag from AAstart.s */
47 reboot = 0;
48 printf("[rebooting...]\n");
49 do_cmd("b");
50 }
51 while (1) {
52 printf(">>> ");
53 ngets(buf, sizeof(buf));
54 do_cmd(buf);
55 }
56 /* not reached */
57 }
58
59 /*
60 * exit to rom
61 */
62
63 void callrom ()
64 {
65 asm("trap #15; .word 0x0063");
66 }
67
68 /*
69 * do_cmd: do a command
70 */
71
72 void do_cmd(buf)
73
74 char *buf;
75
76 {
77 switch (*buf) {
78 case '\0':
79 return;
80 case 'a':
81 if ( rev_arp() ) {
82 printf ("My ip address is: %d.%d.%d.%d\n", myip[0],
83 myip[1], myip[2], myip[3]);
84 printf ("Server ip address is: %d.%d.%d.%d\n", servip[0],
85 servip[1], servip[2], servip[3]);
86 } else {
87 printf ("Failed.\n");
88 }
89 return;
90 case 'e':
91 printf("exiting to ROM\n");
92 callrom();
93 return;
94 case 'f':
95 if (do_get_file() == 1) {
96 printf("Download Failed\n");
97 } else {
98 printf("Download was a success!\n");
99 }
100 return;
101 case 'b':
102 le_init();
103 if ( rev_arp() ) {
104 printf ("My ip address is: %d.%d.%d.%d\n", myip[0],
105 myip[1], myip[2], myip[3]);
106 printf ("Server ip address is: %d.%d.%d.%d\n", servip[0],
107 servip[1], servip[2], servip[3]);
108 } else {
109 printf ("REVARP: Failed.\n");
110 return;
111 }
112 if (do_get_file() == 1) {
113 printf("Download Failed\n");
114 return;
115 } else {
116 printf("Download was a success!\n");
117 }
118 go(buf);
119 return;
120 case 'h':
121 case '?':
122 printf("valid commands\n");
123 printf("a - send a RARP\n");
124 printf("b - boot the system\n");
125 printf("e - exit to ROM\n");
126 printf("f - ftp the boot file\n");
127 printf("g - execute the boot file\n");
128 printf("h - help\n");
129 printf("i - init LANCE enet chip\n");
130 return;
131 case 'i':
132 le_init();
133 return;
134 case 'g':
135 go(buf);
136 return;
137 default:
138 printf("sboot: %s: Unknown command\n", buf);
139 }
140 }
141
142 go(buf)
143 char *buf;
144
145 {
146 void (*entry)() = (void (*)) LOAD_ADDR ;
147 printf("Start @ 0x%x ... \n", entry);
148 (*entry)(buf);
149 }
150
151