1 /* 2 * Copyright (c) 1992 OMRON Corporation. 3 * Copyright (c) 1992 The Regents of the University of California. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * OMRON Corporation. 8 * 9 * %sccs.include.redist.c% 10 * 11 * @(#)boot.c 7.2 (Berkeley) 01/12/93 12 */ 13 14 /* 15 * boot.c -- boot program 16 * by A.Fujita, MAR-01-1992 17 */ 18 19 #include <sys/param.h> 20 #include <sys/reboot.h> 21 #include <sys/exec.h> 22 #include <machine/stinger.h> 23 #include <luna68k/stand/saio.h> 24 #include <luna68k/stand/status.h> 25 26 extern struct KernInter *kiff; 27 28 int howto; 29 int devtype = MAKEBOOTDEV(4, 0, 6, 0, 0); 30 31 char *copyunix(); 32 33 struct exec header; 34 char default_file[] = "sd(0,0)vmunix"; 35 36 char *how_to_info[] = { 37 "RB_ASKNAME ask for file name to reboot from", 38 "RB_SINGLE reboot to single user only", 39 "RB_NOSYNC dont sync before reboot", 40 "RB_HALT don't reboot, just halt", 41 "RB_INITNAME name given for /etc/init (unused)", 42 "RB_DFLTROOT use compiled-in rootdev", 43 "RB_KDB give control to kernel debugger", 44 "RB_RDONLY mount root fs read-only" 45 }; 46 47 int 48 how_to_boot(argc, argv) 49 int argc; 50 char *argv[]; 51 { 52 int i, h = howto; 53 54 if (argc < 2) { 55 printf("howto: 0x%s\n\n", hexstr(howto, 2)); 56 57 if (h == 0) { 58 printf("\t%s\n", "RB_AUTOBOOT flags for system auto-booting itself"); 59 } else { 60 for (i = 0; i < 8; i++, h >>= 1) { 61 if (h & 0x01) { 62 printf("\t%s\n", how_to_info[i]); 63 } 64 } 65 } 66 67 printf("\n"); 68 } 69 } 70 71 int 72 get_boot_device(s) 73 char *s; 74 { 75 register int unit = 0; 76 register int part = 0; 77 register char *p = s; 78 79 while (*p != '(') { 80 if (*p == '\0') 81 goto error; 82 p++; 83 } 84 85 while (*++p != ',') { 86 if (*p == '\0') 87 goto error; 88 if (*p >= '0' && *p <= '9') 89 unit = (unit * 10) + (*p - '0'); 90 } 91 92 while (*++p != ')') { 93 if (*p == '\0') 94 goto error; 95 if (*p >= '0' && *p <= '9') 96 part = (part * 10) + (*p - '0'); 97 } 98 99 return(MAKEBOOTDEV(4, 0, (6 - unit), unit, part)); 100 101 error: 102 return(MAKEBOOTDEV(4, 0, 6, 0, 0)); 103 } 104 105 int 106 boot(argc, argv) 107 int argc; 108 char *argv[]; 109 { 110 register int io; 111 char *line; 112 113 if (argc < 2) 114 line = default_file; 115 else 116 line = argv[1]; 117 118 devtype = get_boot_device(line); 119 120 printf("Booting %s\n", line); 121 122 io = open(line, 0); 123 if (io >= 0) { 124 bootunix(howto, devtype, io); 125 close(io); 126 } 127 } 128 129 int 130 load(argc, argv) 131 int argc; 132 char *argv[]; 133 { 134 register int io; 135 char *line; 136 137 if (argc < 2) 138 line = default_file; 139 else 140 line = argv[1]; 141 142 printf("loading %s\n", line); 143 144 io = open(line, 0); 145 if (io >= 0) { 146 copyunix(io); 147 printf("\n"); 148 close(io); 149 } 150 } 151 152 int 153 bootunix(howto, devtype, io) 154 register howto; /* d7 contains boot flags */ 155 register devtype; /* d6 contains boot device */ 156 register io; 157 { 158 register char *load; /* a5 contains load addr for unix */ 159 160 load = copyunix(io); 161 162 printf(" start 0x%x\n", load); 163 asm(" movl %0,d7" : : "d" (howto)); 164 asm(" movl %0,d6" : : "d" (devtype)); 165 asm(" movl %0,a5" : : "a" (kiff)); 166 (*((int (*)()) load))(); 167 } 168 169 char * 170 copyunix(io) 171 register io; 172 { 173 174 register int i; 175 register char *load; /* a5 contains load addr for unix */ 176 register char *addr; 177 178 /* 179 * Read a.out file header 180 */ 181 182 i = read(io, (char *)&header, sizeof(struct exec)); 183 if (i != sizeof(struct exec) || 184 (header.a_magic != 0407 && header.a_magic != 0413 && header.a_magic != 0410)) { 185 printf("illegal magic number ... 0x%x\n"); 186 printf("Bad format\n"); 187 return(0); 188 } 189 190 load = addr = (char *) (header.a_entry & 0x00FFFFFF); 191 192 printf("%d", header.a_text); 193 if (header.a_magic == 0413 && lseek(io, 0x400, 0) == -1) 194 goto shread; 195 196 /* 197 * Load TEXT Segment 198 */ 199 200 if (read(io, (char *)addr, header.a_text) != header.a_text) 201 goto shread; 202 addr += header.a_text; 203 if (header.a_magic == 0413 || header.a_magic == 0410) 204 while ((int)addr & CLOFSET) 205 *addr++ = 0; 206 207 /* 208 * Load DATA Segment 209 */ 210 211 printf("+%d", header.a_data); 212 if (read(io, addr, header.a_data) != header.a_data) 213 goto shread; 214 215 /* 216 * Clear BSS Segment 217 */ 218 219 addr += header.a_data; 220 printf("+%d", header.a_bss); 221 header.a_bss += 128*512; /* slop */ 222 for (i = 0; i < header.a_bss; i++) 223 *addr++ = 0; 224 225 return(load); 226 227 shread: 228 printf(" Short read\n"); 229 return(0); 230 } 231 232