|
|
1.1 ! root 1: #include "u.h" ! 2: #include "lib.h" ! 3: #include "mem.h" ! 4: #include "dat.h" ! 5: #include "fns.h" ! 6: #include "io.h" ! 7: ! 8: #include "dosfs.h" ! 9: ! 10: typedef struct Type Type; ! 11: typedef struct Medium Medium; ! 12: typedef struct Mode Mode; ! 13: ! 14: enum { ! 15: Maxdev = 7, ! 16: Dany = -1, ! 17: Nmedia = 16, ! 18: }; ! 19: ! 20: enum { /* type */ ! 21: Tfloppy = 0x00, ! 22: Thard = 0x01, ! 23: Tscsi = 0x02, ! 24: Tether = 0x03, ! 25: NType = 0x04, ! 26: ! 27: Tany = -1, ! 28: }; ! 29: ! 30: enum { /* flag and name */ ! 31: Fnone = 0x00, ! 32: ! 33: Fdos = 0x01, ! 34: Ndos = 0x00, ! 35: Fboot = 0x02, ! 36: Nboot = 0x01, ! 37: Fbootp = 0x04, ! 38: Nbootp = 0x02, ! 39: NName = 0x03, ! 40: ! 41: Fany = Fbootp|Fboot|Fdos, ! 42: ! 43: Fini = 0x10, ! 44: Freverse = 0x20, ! 45: Fprobe = 0x80, ! 46: }; ! 47: ! 48: enum { /* mode */ ! 49: Mauto = 0x00, ! 50: Mlocal = 0x01, ! 51: Manual = 0x02, ! 52: NMode = 0x03, ! 53: }; ! 54: ! 55: enum ! 56: { ! 57: CGAWIDTH = 160, ! 58: CGAHEIGHT = 24, ! 59: ! 60: NLINES = 10, ! 61: NWIDTH = 60, ! 62: WLOCX = 5, ! 63: WLOCY = 5, ! 64: ! 65: MENUATTR = 7, ! 66: HIGHMENUATTR = 112, ! 67: }; ! 68: ! 69: typedef struct Type { ! 70: int type; ! 71: int flag; ! 72: int (*init)(void); ! 73: long (*read)(int, void*, long); ! 74: long (*seek)(int, long); ! 75: Partition* (*setpart)(int, char*); ! 76: char* name[NName]; ! 77: ! 78: int mask; ! 79: Medium* media; ! 80: } Type; ! 81: ! 82: typedef struct Medium { ! 83: Type* type; ! 84: int flag; ! 85: Partition* partition; ! 86: Dos; ! 87: ! 88: Medium* next; ! 89: } Medium; ! 90: ! 91: typedef struct Mode { ! 92: char* name; ! 93: int mode; ! 94: } Mode; ! 95: ! 96: static Type types[NType] = { ! 97: { Tfloppy, ! 98: Fini|Fdos, ! 99: floppyinit, floppyread, floppyseek, 0, ! 100: { "fd", } ! 101: }, ! 102: }; ! 103: ! 104: static Medium media[Nmedia]; ! 105: static Medium *curmedium = media; ! 106: ! 107: static Mode modes[NMode+1] = { ! 108: [Mauto] { "auto", Mauto, }, ! 109: [Mlocal] { "local", Mlocal, }, ! 110: [Manual] { "manual", Manual, }, ! 111: }; ! 112: ! 113: static Medium* ! 114: allocm(Type *tp) ! 115: { ! 116: Medium **l; ! 117: ! 118: if(curmedium >= &media[Nmedia]) ! 119: return 0; ! 120: ! 121: for(l = &tp->media; *l; l = &(*l)->next) ! 122: ; ! 123: *l = curmedium++; ! 124: return *l; ! 125: } ! 126: ! 127: void ! 128: xclrscrn(int attr) ! 129: { ! 130: int i; ! 131: ! 132: for(i = 0; i < CGAWIDTH*CGAHEIGHT; i += 2) { ! 133: cga[i] = ' '; ! 134: cga[i+1] = attr; ! 135: } ! 136: } ! 137: ! 138: void ! 139: xprint(int x, int y, int attr, char *fmt, ...) ! 140: { ! 141: uchar *p; ! 142: int out, i; ! 143: char buf[CGAWIDTH]; ! 144: ! 145: x *= 2; ! 146: ! 147: out = doprint(buf, buf+sizeof(buf), fmt, DOTDOT) - buf; ! 148: p = (uchar*)(cga + x + (y*CGAWIDTH)); ! 149: for(i = 0; i < out; i++) { ! 150: *p++ = buf[i]; ! 151: *p++ = attr; ! 152: } ! 153: } ! 154: ! 155: void ! 156: xputc(int x, int y, int attr, int c) ! 157: { ! 158: uchar *p; ! 159: ! 160: x *= 2; ! 161: p = (uchar*)(cga + x + (y*CGAWIDTH)); ! 162: p[0] = c; ! 163: p[1] = attr; ! 164: } ! 165: ! 166: Medium* ! 167: probe(int type, int flag, int dev) ! 168: { ! 169: Type *tp; ! 170: int d, i, m; ! 171: Medium *mp; ! 172: ! 173: for(tp = types; tp < &types[NType]; tp++){ ! 174: if(type != Tany && type != tp->type) ! 175: continue; ! 176: ! 177: if(flag != Fnone){ ! 178: for(mp = tp->media; mp; mp = mp->next){ ! 179: if((flag & mp->flag) && (dev == Dany || dev == mp->dev)) ! 180: return mp; ! 181: } ! 182: } ! 183: ! 184: if((tp->flag & Fprobe) == 0){ ! 185: tp->flag |= Fprobe; ! 186: tp->mask = (*tp->init)(); ! 187: } ! 188: ! 189: for(i = 0; tp->mask; i++){ ! 190: if(tp->flag & Freverse){ ! 191: m = 1<<(Maxdev-i); ! 192: d = (Maxdev-i); ! 193: } ! 194: else{ ! 195: m = 1<<i; ! 196: d = i; ! 197: } ! 198: if((tp->mask & m) == 0) ! 199: continue; ! 200: tp->mask &= ~m; ! 201: ! 202: if((mp = allocm(tp)) == 0) ! 203: continue; ! 204: ! 205: mp->dev = d; ! 206: mp->flag = tp->flag; ! 207: mp->seek = tp->seek; ! 208: mp->read = tp->read; ! 209: mp->type = tp; ! 210: ! 211: if(mp->flag & Fboot){ ! 212: if((mp->partition = (*tp->setpart)(d, "boot")) == 0) ! 213: mp->flag &= ~Fboot; ! 214: (*tp->setpart)(d, "disk"); ! 215: } ! 216: ! 217: if((mp->flag & Fdos) && (dosinit(mp) < 0)) ! 218: mp->flag &= ~(Fini|Fdos); ! 219: ! 220: if((flag & mp->flag) && (dev == Dany || dev == d)) ! 221: return mp; ! 222: } ! 223: } ! 224: ! 225: return 0; ! 226: } ! 227: ! 228: char n1[] = "System Boot Program"; ! 229: char n2[] = " Plan 9 (TM) Copyright (c) 1995 AT&T Bell Laboratories"; ! 230: ! 231: void ! 232: main(void) ! 233: { ! 234: Medium *mp; ! 235: int port; ! 236: char scsi[64], line[80], *p; ! 237: ! 238: i8042a20(); ! 239: memset(m, 0, sizeof(Mach)); ! 240: trapinit(); ! 241: clockinit(); ! 242: alarminit(); ! 243: spllo(); ! 244: ! 245: consinit(); ! 246: if((ulong)&end > (KZERO|(640*1024))) ! 247: panic("install.com too big\n"); ! 248: ! 249: xclrscrn(17); ! 250: xprint(0, 0, 116, "%-80s", n1); ! 251: xprint(0, 23, 116, "%-80s", n2); ! 252: ! 253: /* ! 254: * look for a floppy with DOS (should be us) and boot 9dos ! 255: */ ! 256: mp = probe(Tfloppy, Fdos, Dany); ! 257: if(mp == 0){ ! 258: print("Can't find the installation floppy\n"); ! 259: delay(15000); ! 260: panic("Rebooting\n"); ! 261: } ! 262: ! 263: /* ! 264: * get configuration info ! 265: */ ! 266: *BOOTARGS = 0; ! 267: ! 268: print("\n\nBooting the Plan 9 kernel, wait...\n"); ! 269: ! 270: sprint(BOOTLINE, "%s!%d!9dos", mp->type->name[Ndos], mp->dev); ! 271: dosboot(mp, "9dos"); ! 272: print("Can't boot 9dos\n"); ! 273: delay(15000); ! 274: panic("Rebooting"); ! 275: } ! 276: ! 277: int ! 278: getfields(char *lp, char **fields, int n, char sep) ! 279: { ! 280: int i; ! 281: ! 282: for(i=0; lp && *lp && i<n; i++){ ! 283: while(*lp == sep) ! 284: *lp++=0; ! 285: if(*lp == 0) ! 286: break; ! 287: fields[i]=lp; ! 288: while(*lp && *lp != sep) ! 289: lp++; ! 290: } ! 291: return i; ! 292: } ! 293: ! 294: void* ! 295: ialloc(ulong n, int align) ! 296: { ! 297: ! 298: static struct { ! 299: ulong addr; ! 300: } palloc; ! 301: ulong p; ! 302: ! 303: if(palloc.addr == 0) ! 304: palloc.addr = ((ulong)&end)&~KZERO; ! 305: if(align) ! 306: palloc.addr = PGROUND(palloc.addr); ! 307: if((palloc.addr <= 640*1024) && (palloc.addr + n > 640*1024)) ! 308: palloc.addr = 2*1024*1024; ! 309: ! 310: memset((void*)(palloc.addr|KZERO), 0, n); ! 311: p = palloc.addr; ! 312: palloc.addr += n; ! 313: if(align) ! 314: palloc.addr = PGROUND(palloc.addr); ! 315: ! 316: return (void*)(p|KZERO); ! 317: } ! 318: ! 319: enum { ! 320: Paddr= 0x70, /* address port */ ! 321: Pdata= 0x71, /* data port */ ! 322: }; ! 323: ! 324: uchar ! 325: nvramread(int offset) ! 326: { ! 327: outb(Paddr, offset); ! 328: return inb(Pdata); ! 329: } ! 330: ! 331: char* ! 332: getconf(char*) ! 333: { ! 334: return 0; ! 335: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.