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