1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17: 18: 19:
20:
21: #include "cmdsvc.h"
22:
23: 24: 25: 26: 27:
28: LOCAL BootInfo bootInfo;
29:
30: 31: 32: 33:
34: LOCAL W loadPBoot( const UB *devnm, DISKCB **dcb_p )
35: {
36: W retry = 2;
37: W pno;
38: DISKCB *dcb;
39: ER err;
40:
41: while ( --retry >= 0 ) {
42:
43:
44: pno = openDisk(devnm, &dcb);
45: if ( pno < E_OK ) {
46: err = pno;
47: if ( err == E_IO ) continue;
48: return err;
49: }
50:
51:
52: if ( pno == 0 ) pno = dcb->boot;
53:
54:
55: err = (*dcb->rwdisk)(dcb, dcb->part[pno].sblk, 1,
56: PBootAddr, FALSE);
57: if ( err < E_OK ) {
58: if ( err == E_IO ) continue;
59: return err;
60: }
61:
62:
63: if ( *(UH*)(PBootAddr + 510) != BootSignature ) return E_BOOT;
64:
65: *dcb_p = dcb;
66: return pno;
67: }
68:
69: return E_IO;
70: }
71:
72: 73: 74: 75: 76: 77:
78: EXPORT ER bootDisk( const UB *devnm )
79: {
80: DISKCB *dcb;
81: W pno, i, c;
82: ER err;
83:
84: if ( devnm != NULL ) {
85:
86: pno = loadPBoot(devnm, &dcb);
87: if ( pno < E_OK ) return pno;
88: } else {
89:
90: pno = E_BOOT;
91: for ( i = 0;; i++ ) {
92: devnm = bootDevice(i);
93: if ( devnm == NULL ) break;
94:
95: pno = loadPBoot(devnm, &dcb);
96: if ( pno >= 0 ) break;
97: }
98: }
99: if ( pno >= 0 ) {
100:
101: i = strlen(devnm);
102: c = devnm[i - 1];
103: if ( i >= 2 && c >= '0' && c <= '3' ) --i;
104:
105:
106: strncpy(bootInfo.devnm, devnm, L_DEVNM);
107: bootInfo.devnm[i] = '\0';
108: bootInfo.part = pno - 1;
109: bootInfo.start = dcb->part[pno].sblk;
110: bootInfo.secsz = dcb->blksz;
111:
112:
113: setUpBoot(PBootAddr, &bootInfo);
114:
115: } else {
116: 117:
118: err = bootROM();
119: if ( err < E_OK ) {
120: if ( err != E_ABORT ) err = pno;
121: return err;
122: }
123: }
124:
125: return E_OK;
126: }