summaryrefslogtreecommitdiffstats
path: root/private/ntos/fw/alpha/jxboot.c
blob: 6216c4832390eea16bc8ba911ad677a4d9e52b6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
/*++

Copyright (c) 1990  Microsoft Corporation
Copyright (c) 1993  Digital Equipment Corporation

Module Name:

    jxboot.c

Abstract:

    This module implements the first pass simple-minded boot program for
    MIPS and Alpha systems.

Author:

    David N. Cutler (davec) 7-Nov-1990

Environment:

    Kernel mode only.

Revision History:

    18-May-1992         John DeRosa [DEC]

    Made Alpha/Jensen modifications.

--*/

#include "fwp.h"
#include "machdef.h"

#ifdef JENSEN
#include "jnsnrtc.h"
#else
#include "mrgnrtc.h"            // morgan
#endif

#include "string.h"
#include "led.h"
#include "fwstring.h"
#include "xxstring.h"


//
// Define local procedure prototypes.
//

ARC_STATUS
FwpFindCDROM (
    OUT PCHAR PathName
    );

ARC_STATUS
FwpEvaluateWNTInstall(
    OUT PCHAR PathName
    );

VOID
FwSetupFloppy(
    VOID
    );

VOID
FwInstallKd(
    IN VOID
    );

VOID
PutLedDisplay(
    IN UCHAR Value
    );

ULONG
SerFwPrint (
    PCHAR Format,
    ...
    );

//
// Define external references.
//

#ifdef ALPHA_FW_VDB
//
// Debugging Aid
//
extern UCHAR DebugAid[3][150];
#endif

#ifdef ALPHA_FW_SERDEB
//
// Variable that enables printing on the COM1 line.
//
extern BOOLEAN SerSnapshot;
#endif

extern ULONG ScsiDebug;
extern ULONG ProcessorCycleCounterPeriod;

//
// Global to indicate whether any errors happened during EISA bus config.
//

BOOLEAN ErrorsDuringEISABusConfiguration;


#ifdef ALPHA_FW_KDHOOKS

//
// Define external data required by the kernel debugger.
//

CCHAR KeNumberProcessors;
PKPRCB KiProcessorBlock[MAXIMUM_PROCESSORS];
KPRCB Prcb;
KPROCESS Process;
KTHREAD Thread;
ULONG KiFreezeFlag = 0;
BOOLEAN KdInstalled = FALSE;
LOADER_PARAMETER_BLOCK LoaderBlock;
KPCR KernelPcr;
PKTHREAD KiCurrentThread;
BOOLEAN KiDpcRoutineActiveFlag;
PKPCR KiPcrBaseAddress;
PKPRCB KiPrcbBaseAddress;
PKDEBUG_ROUTINE KiDebugRoutine;

#endif

//
// Saved sp
//

ULONG FwSavedSp;


//
// Break into the debugger after loading the program.
//

BOOLEAN BreakAfterLoad = FALSE;


VOID
FwBootSystem (
    VOID
    )

/*++

Routine Description:

    This routine is the main ARC firmware code.  It displays the
    boot menu and executes the selected commands.

Arguments:

    None.

Return Value:

    None.  It never returns.

--*/

{
    ARC_STATUS Status;
    LONG Index;
    UCHAR Character;
    ULONG Count;
    PCHAR LoadArgv[8];
    ULONG ArgCount;
    LONG DefaultChoice = 0;
    LONG SupplementaryMenuChoice = 0;
    CHAR PathName[128];
    CHAR TempName[128];
    PCHAR TempArgs;
    CHAR SystemPartition[128];
    CHAR Osloader[128];
    CHAR OsloadPartition[128];
    CHAR OsloadFilename[128];
    CHAR OsloadOptions[128];
    CHAR LoadIdentifier[128];
    CHAR FwSearchPath[128];
    CHAR ProtectedEnvironmentVariables[5][100];
    BOOLEAN SecondaryBoot;
    PCHAR Colon;
    PCHAR EnvironmentValue;
    PCHAR LoadEnvp[MAX_NUMBER_OF_ENVIRONMENT_VARIABLES];
    BOOLEAN Timeout = TRUE;
    LONG Countdown;
    ULONG RelativeTime;
    ULONG PreviousTime;
    CHAR Choice0[128 + FW_BOOT_MSG_SIZE];
    CHAR BootChoices[5][128];
    PCHAR BootMenu[5];
    ULONG NumberOfBootChoices;
    GETSTRING_ACTION Action;
    BOOLEAN VariableFound;
    PCONFIGURATION_COMPONENT Controller;
    BOOLEAN TryOpenWithSpecialMod;
    BOOLEAN RunAProgram;
    ULONG Problems;
    UCHAR NVRAMByte;
    BOOLEAN AutoRunTheECU;

    //
    // Initialize value for the ALIGN_BUFFER macro.
    //

    BlDcacheFillSize = KeGetDcacheFillSize();

    //
    // Initialize the firmware servies.
    //

    FwInitialize(0);
    PutLedDisplay(LED_AFTER_FWINITIALIZE);

    //
    // If the NVRAM AutoRunECU bit is off, do not automatically run the ECU.
    //
    // If the NVRAM AutoRunECU bit is on but the machine is not consistent,
    // clear the AutoRunECU bit and do not automatically run the ECU.
    //
    // If the NVRAM AutoRunECU bit is on and the machine is consistent,
    // clear the AutoRunECU bit and automatically run the ECU.
    //

    AutoRunTheECU = FALSE;

    //
    // Load the environment now for FwSystemConsistencyCheck
    //

    FwEnvironmentLoad();

    PutLedDisplay(LED_ENVIRONMENT_LOADED);

#ifdef ISA_PLATFORM

    //
    // Warn the user if the system appears to be incapable of booting NT.
    //

    FwSystemConsistencyCheck (FALSE, &Problems);

#else

    FwpWriteIOChip(RTC_APORT, RTC_RAM_NT_FLAGS0);
    NVRAMByte = FwpReadIOChip(RTC_DPORT);

    if (((PRTC_RAM_NT_FLAGS_0)(&NVRAMByte))->AutoRunECU) {

        //
        // AutoRunECU is on.
        //

        ((PRTC_RAM_NT_FLAGS_0)(&NVRAMByte))->AutoRunECU = 0;
        FwpWriteIOChip(RTC_APORT, RTC_RAM_NT_FLAGS0);
        FwpWriteIOChip(RTC_DPORT, NVRAMByte);

        FwSystemConsistencyCheck(TRUE, &Problems);

        //
        // If there are no other Red problems besides the ECU bit,
        // run the ECU.
        //

        if ((Problems &
             FWP_MACHINE_PROBLEMS_RED &
             ~FWP_MACHINE_PROBLEMS_ECU) == 0) {

            AutoRunTheECU = TRUE;
        }

    }

    if (!AutoRunTheECU) {

        //
        // Warn the user if the system appears to be incapable of booting NT.
        //

        FwSystemConsistencyCheck(FALSE, &Problems);
    }

#endif // ISA_PLATFORM

    PutLedDisplay(LED_FW_INITIALIZED);

    while (TRUE) {

        //
        // Since jnsetup is now part of the firmware, load the environment
        // variables into the volatile environment.
        //
        // HACK: At some point the code should be changed to not use a
        //       volatile environment.
        //

        FwEnvironmentLoad();

        //
        // Load up default environment variable values.
        //

        strcpy(SystemPartition, BootString[SystemPartitionVariable]);
        strcpy(Osloader, BootString[OsLoaderVariable]);
        strcpy(OsloadPartition, BootString[OsLoadPartitionVariable]);
        strcpy(OsloadFilename, BootString[OsLoadFilenameVariable]);
        strcpy(OsloadOptions, BootString[OsLoadOptionsVariable]);
        strcpy(LoadIdentifier, BootString[LoadIdentifierVariable]);

        FwGetVariableSegment(0, SystemPartition);
        FwGetVariableSegment(0, Osloader);
        FwGetVariableSegment(0, OsloadPartition);
        FwGetVariableSegment(0, OsloadFilename);
        FwGetVariableSegment(0, OsloadOptions);
        FwGetVariableSegment(0, LoadIdentifier);

        if (LoadIdentifier[sizeof("LoadIdentifier=") - 1] != 0) {
            strcpy(Choice0, FW_BOOT_MSG);
            strcat(Choice0, &LoadIdentifier[sizeof("LoadIdentifier=") - 1]);
            BootMenuChoices[0] = Choice0;
        }

        strcpy(FwSearchPath, "FWSEARCHPATH");

        //
        // The default action for running a program is to try to open
        // the specified pathname without a appending .EXE extension first,
        // and then if that fails, try appending a .EXE extension.
        //

        TryOpenWithSpecialMod = TRUE;

        FwSetScreenColor( ArcColorWhite, ArcColorBlue);
        FwSetScreenAttributes( TRUE, FALSE, FALSE);

        //
        // Add floppy controller to the CDS tree if it is not already there.
        //

        FwSetupFloppy();

#ifdef EISA_PLATFORM

        //
        // If we are to automatically run the ECU, jam in some values
        // and go directly to the run-a-program code.
        //

        if (AutoRunTheECU) {

            AutoRunTheECU = FALSE;
            strcpy(PathName, FW_ECU_LOCATION);
            TempArgs = "";
            TryOpenWithSpecialMod = FALSE;
            goto ExecuteImage;
        }

#endif
        //
        // Redisplay whatever menu the user was in (Boot or Supplementary).
        //

        if (DefaultChoice != 3) {

            //
            // Display the main boot menu.
            //

            //
            // Calculate whether autoboot is active, and if so what the
            // autoboot value is.
            //

            if (Timeout &&
                ((EnvironmentValue = FwGetEnvironmentVariable("Autoload")) != NULL) &&
                (tolower(*EnvironmentValue) == 'y') &&
                ((EnvironmentValue = FwGetEnvironmentVariable("Countdown")) != NULL)) {
                Countdown = atoi(EnvironmentValue);

            } else {
                Countdown = 0;
                Timeout = FALSE;
            }

            DefaultChoice = JzGetSelection(BootMenuChoices,
                                           NUMBER_OF_BOOT_CHOICES,
                                           DefaultChoice,
                                           FW_MENU_BOOT_MSG,
                                           NULL,
                                           NULL,
                                           Countdown,
                                           FALSE);
        }

        //
        // Here when the user has made a selection, or the user was
        // previously in the supplementary menu (DefaultChoice == 3) and
        // so we will return him there, or we are automatically running
        // the ECU.
        //

        //
        // If the selection is not booting the default operating system,
        // permanently remove the timeout.
        //

        if (DefaultChoice != 0) {
            Timeout = FALSE;
        }

        switch (DefaultChoice) {

        case 0:

            //
            // Boot default operating system.
            //

            if (Osloader[sizeof("OSLOADER=") - 1] == 0) {
                FwSetPosition( 7, 5);
                FwSetScreenColor(ArcColorRed, ArcColorWhite);
                FwPrint(FW_NO_BOOT_SELECTIONS_MSG);
                FwSetScreenColor(ArcColorWhite, ArcColorBlue);
                FwRead(ARC_CONSOLE_INPUT, &Character, 1, &Count);
                continue;
            }
            strcpy(PathName, &(Osloader[sizeof("OSLOADER=") - 1]));
            break;

        case 1:

            //
            // Boot secondary operating system.
            //

            //
            // Create the menu.
            //

            for ( Index = 0 ; Index < 5  ; Index++ ) {

                SecondaryBoot = FwGetVariableSegment(Index, SystemPartition);
                SecondaryBoot = FwGetVariableSegment(Index, Osloader) ||
                                SecondaryBoot;
                SecondaryBoot = FwGetVariableSegment(Index, OsloadPartition) ||
                                SecondaryBoot;
                SecondaryBoot = FwGetVariableSegment(Index, OsloadFilename) ||
                                SecondaryBoot;
                SecondaryBoot = FwGetVariableSegment(Index, OsloadOptions) ||
                                SecondaryBoot;
                SecondaryBoot = FwGetVariableSegment(Index, LoadIdentifier) ||
                                SecondaryBoot;

                strcpy(BootChoices[Index], FW_BOOT_MSG);
                if (LoadIdentifier[sizeof("LOADIDENTIFIER=") - 1] != 0) {
                    strcat(BootChoices[Index],
                           &LoadIdentifier[sizeof("LOADIDENTIFIER=") - 1]);
                } else {
                    strcat(BootChoices[Index],
                           &OsloadPartition[sizeof("OsloadPartition=") - 1]);
                    strcat(BootChoices[Index],
                           &OsloadFilename[sizeof("OsloadFilename=") - 1]);
                }

                BootMenu[Index] = BootChoices[Index];

                if (!SecondaryBoot) {
                    break;
                }
            }

            //
            // Check if any selections are available.
            //

            if ( (Index == 0) && (Osloader[sizeof("OSLOADER=") - 1] == 0) ) {
                FwSetPosition( 7, 5);
                FwSetScreenColor(ArcColorRed, ArcColorWhite);
                FwPrint(FW_NO_BOOT_SELECTIONS_MSG);
                FwSetScreenColor(ArcColorWhite, ArcColorBlue);
                FwRead(ARC_CONSOLE_INPUT, &Character, 1, &Count);
                continue;
            }


            //
            // Mark the default choice.
            //

            strcat(BootChoices[0], FW_DEFAULT_MSG);

            //
            // Display the menu.
            //

            Index = JzDisplayMenu (BootMenu,
                                   Index + 1,
                                   (Index ? 1 : 0),
                                   7,
                                   0,
                                   FALSE);

            //
            // Continue if the escape key was pressed.
            //

            if (Index < 0) {
                continue;
            }

            //
            // Load up the chosen boot selection.
            //

            FwGetVariableSegment(Index, SystemPartition);
            FwGetVariableSegment(Index, Osloader);
            FwGetVariableSegment(Index, OsloadPartition);
            FwGetVariableSegment(Index, OsloadFilename);
            FwGetVariableSegment(Index, OsloadOptions);

            strcpy(PathName, &(Osloader[sizeof("OSLOADER=") - 1]));
            break;


        case 2:

            //
            // Run a program.
            //
            //
            // Get the name.
            //

            FwSetPosition(5, 0);
            FwPrint("%cJ", ASCII_CSI);          // Clear to end of screen
            FwPrint(FW_PROGRAM_TO_RUN_MSG);
            do {
                Action = JzGetString(TempName,
                                     sizeof(TempName),
                                     NULL,
                                     5,
                                     strlen(FW_PROGRAM_TO_RUN_MSG),
                                     FALSE);
            } while ((Action != GetStringEscape) && (Action != GetStringSuccess));

            //
            // If no program is specified, continue.
            //

            if (TempName[0] == 0) {
                continue;
            }

            //
            // Execute monitor if special program name is given.
            //

            if (strcmp(TempName, MON_INVOCATION_STRING) == 0) {

                FwClearScreen();
                FwMonitor(3);           // goes thru PALcode link routine.
                continue;
            }

            //
            // Strip off any arguments.
            //

            if ((TempArgs = strchr(TempName, ' ')) != NULL) {
                *TempArgs++ = 0;
            } else {
                TempArgs = "";
            }

            //
            // If the name does not contain a "(", then assume it is not a full
            // pathname.
            //

            if (strchr( TempName, '(') == NULL) {

                //
                // If the name contains a semicolon, look for an environment
                // variable that defines the path.
                //

                if ((Colon = strchr( TempName, ':')) != NULL) {

                    for (Index = 0; TempName[Index] != ':' ; Index++ ) {
                        PathName[Index] = tolower(TempName[Index]);
                    }

                    PathName[Index++] = ':';
                    PathName[Index++] = 0;
                    EnvironmentValue = FwGetEnvironmentVariable(PathName);
                    VariableFound = FALSE;

                    if (EnvironmentValue != NULL) {
                        strcpy( PathName, EnvironmentValue);
                        VariableFound = TRUE;
                    } else if (!strcmp(PathName, "cd:")) {
                        for ( Index = 0 ; Index < 8 ; Index++ ) {
                            sprintf(PathName, "scsi(0)cdrom(%d)fdisk(0)", Index);
                            Controller = FwGetComponent(PathName);
                            if ((Controller != NULL) && (Controller->Type == FloppyDiskPeripheral)) {
                                VariableFound = TRUE;
                                break;
                            }
                        }
                    }

                    if (!VariableFound) {
                        FwSetPosition( 17, 0);
                        FwSetScreenColor(ArcColorRed, ArcColorWhite);
                        FwPrint(FW_PATHNAME_NOT_DEF_MSG);
                        FwWaitForKeypress(TRUE);
                        FwSetScreenColor(ArcColorWhite, ArcColorBlue);
                        continue;
                    } else {
                        strcat( PathName, Colon + 1);
                    }

                } else {

                    //
                    // Loop on the FWSEARCHPATH variable.
                    //

                    Index = 0;
                    VariableFound = FALSE;
                    do {
                        SecondaryBoot = FwGetVariableSegment(Index++, FwSearchPath);
                        strcpy(PathName, &(FwSearchPath[sizeof("FWSEARCHPATH=") - 1]));
                        strcat(PathName, TempName);
                        if (FwOpen(PathName, ArcOpenReadOnly, &Count) == ESUCCESS) {
                            VariableFound = TRUE;
                            FwClose(Count);
                            break;
                        } else {
                            strcat(PathName, ".exe");
                            if (FwOpen(PathName, ArcOpenReadOnly, &Count) == ESUCCESS) {
                                VariableFound = TRUE;
                                FwClose(Count);
                                break;
                            }
                        }
                    } while (SecondaryBoot);

                    if (!VariableFound) {
                        FwSetPosition( 17, 0);
                        FwSetScreenColor(ArcColorRed, ArcColorWhite);
                        FwPrint(FW_ERROR_MSG[ENOENT - 1]);
                        FwWaitForKeypress(TRUE);
                        FwSetScreenColor(ArcColorWhite, ArcColorBlue);
                        continue;
                    }

                }

            } else {
                strcpy( PathName, TempName);
            }
            break;


        case 3:

            //
            // Bring up the supplementary menu
            //

#ifdef ALPHA_FW_VDB
    FwVideoStateDump(2);
#endif

#ifdef ALPHA_FW_SERDEB
#ifdef ALPHA_FW_VDB

{
    //
    // Graphics debugging assistance.  Print pre-init and post-init video
    // state.
    //

    ULONG H, I, J;

    SerSnapshot = TRUE;

    for (J = 0; J < 8; J++) {

        for (H = 0; H < 3; H++) {

            SerFwPrint("[%d:%d] = ", H, J*16);

            for (I = J*16; I < (J+1)*16; I++) {
                SerFwPrint("%x ", DebugAid[H][I]);
            }

            SerFwPrint("\r\n");
        }

    }

}

#endif
#endif


            SupplementaryMenuChoice = JzGetSelection (SupplementaryMenuChoices,
                                                     NUMBER_OF_SUPP_CHOICES,
                                                     SupplementaryMenuChoice,
                                                     FW_MENU_SUPPLEMENTARY_MSG,
                                                     NULL,
                                                     NULL,
                                                     0,
                                                     FALSE);

            FwClearScreen();

            switch (SupplementaryMenuChoice) {

            case 0:

                //
                // Install new firmware
                //

                //
                // If the Jensen update tool is present on the floppy,
                // run it from there, otherwise run it from CD-ROM.
                //

                TempArgs = "";

                //
                // The program string we will attempt to open already has
                // a .EXE extension, so do not waste type by trying to
                // open it first without one.
                //

                TryOpenWithSpecialMod = FALSE;

                FwSetPosition(2, 0);
                FwPrint(FW_FIRMWARE_UPDATE_SEARCH_MSG);

                if (FwOpen(FW_PRIMARY_FIRMWARE_UPDATE_TOOL,
                           ArcOpenReadOnly,
                           &Count) == ESUCCESS) {
                    FwClose(Count);
                    strcpy(PathName, FW_PRIMARY_FIRMWARE_UPDATE_TOOL);
                    break;
                } else {
                    FwpFindCDROM(PathName);
                    strcat(PathName, FW_FIRMWARE_UPDATE_TOOL_NAME);
                    break;
                }


            case 1:

                //
                // Install Windows NT from CD-ROM
                //

                if (FwpEvaluateWNTInstall(PathName) == ESUCCESS) {

                    //
                    // The program string we will attempt to open does not have
                    // a .EXE extension, and it is not supposed to, so do not
                    // waste time trying to open it to see if it is really
                    // there.
                    //

                    TryOpenWithSpecialMod = FALSE;
                    TempArgs = "";
                    break;

                } else {

                    // We cannot install Windows NT.
                    continue;
                }

            case 2:

                //
                // Execute the Jensen Setup Program
                //

                JensenSetupProgram(&RunAProgram, PathName);

                if (RunAProgram) {
                    TryOpenWithSpecialMod = FALSE;
                    TempArgs = "";
                    break;
                } else {
                    continue;
                }

            case 3:

                //
                // List available devices
                //

                FwSetPosition(2,0);
                FwDumpLookupTable();
                FwPrint(FW_CRLF_MSG);
                FwWaitForKeypress(TRUE);
                continue;

            case -1:
            case 4:
            default:

                //
                // Back to boot menu if the escape key was pressed, or
                // if Return to boot menu was selected, or if something
                // bad happened in JzDisplayMenu.
                //

                DefaultChoice = 0;
                SupplementaryMenuChoice = 0;
                continue;

            }

            //
            // If the supplementary menu switch exits, we want to exit the
            // boot menu switch as well.
            //

            break;


        default:

            //
            // User hit escape.
            //

            DefaultChoice = 0;
            continue;

        }




ExecuteImage:



        FwClearScreen();
        FwSetPosition( 0, 0);


        //
        // Get the entire environment.
        //

        LoadEnvp[0] = FwEnvironmentLoad();

        //
        // If the environment was loaded, fill out envp.
        //

        if (LoadEnvp[0] != NULL) {

            Index = 0;

            //
            // While variables still exist, find the end of each and set
            // the next envp value to point there. Note this will break
            // if the last variable has only one null after it.
            //

            while (*LoadEnvp[Index]) {
                Index++;
                LoadEnvp[Index] = strchr(LoadEnvp[Index - 1],'\0') + 1;
            }

            //
            // Load the Alpha AXP protected environment variables.
            //

            if ((Index+1+5) >= MAX_NUMBER_OF_ENVIRONMENT_VARIABLES) {
                FwSetScreenColor(ArcColorRed, ArcColorWhite);
                FwPrint(FW_INTERNAL_ERROR_ENVIRONMENT_VARS_MSG);
                FwSetScreenColor(ArcColorWhite, ArcColorBlue);
                FwWaitForKeypress(TRUE);
            } else {
                strcpy (ProtectedEnvironmentVariables[0],
                        FwGetEnvironmentVariable("PHYSICALADDRESSBITS"));
                strcpy (ProtectedEnvironmentVariables[1],
                        FwGetEnvironmentVariable("MAXIMUMADDRESSSPACENUMBER"));
                strcpy (ProtectedEnvironmentVariables[2],
                        FwGetEnvironmentVariable("SYSTEMSERIALNUMBER"));
                strcpy (ProtectedEnvironmentVariables[3],
                        FwGetEnvironmentVariable("CYCLECOUNTERPERIOD"));
                strcpy (ProtectedEnvironmentVariables[4],
                        FwGetEnvironmentVariable("PROCESSORPAGESIZE"));

                LoadEnvp[Index++] = ProtectedEnvironmentVariables[0];
                LoadEnvp[Index++] = ProtectedEnvironmentVariables[1];
                LoadEnvp[Index++] = ProtectedEnvironmentVariables[2];
                LoadEnvp[Index++] = ProtectedEnvironmentVariables[3];
                LoadEnvp[Index++] = ProtectedEnvironmentVariables[4];
            }

            //
            // No more, set the last one to NULL.
            //

            LoadEnvp[Index] = NULL;
        }

        //
        // If this is an automatic boot selection, load up the standard
        // arguments, otherwise load up the command line arguments.
        //

        LoadArgv[0] = PathName;

        if (DefaultChoice <= 1) {

            ArgCount = 1;

            //
            // Load up all the Argv parameters.
            //

            LoadArgv[1] = Osloader;
            LoadArgv[2] = SystemPartition;
            LoadArgv[3] = OsloadFilename;
            LoadArgv[4] = OsloadPartition;
            LoadArgv[5] = OsloadOptions;
            LoadArgv[6] = "CONSOLEIN=";
            LoadArgv[7] = "CONSOLEOUT=";

            //
            // Find console in and out by looking through the environment.
            //

            for ( --Index ; Index >= 0 ; Index-- ) {
                for ( ArgCount = 6; ArgCount <= 7 ; ArgCount++ ) {
                    if (strstr(LoadEnvp[Index],LoadArgv[ArgCount]) == LoadEnvp[Index]) {
                        LoadArgv[ArgCount] = LoadEnvp[Index];
                    }
                }
            }

        } else {

            //
            // Look through the pathname for arguments, by zeroing out any
            // spaces.
            //

            Index = 0;
            ArgCount = 1;

            while (TempArgs[Index] && (ArgCount < MAX_NUMBER_OF_ENVIRONMENT_VARIABLES)) {
                if (TempArgs[Index] == ' ') {
                    TempArgs[Index] = 0;
                } else {
                    if (TempArgs[Index - 1] == 0) {
                        LoadArgv[ArgCount++] = &TempArgs[Index];
                    }
                }
                Index++;
            }
        }

        //
        // Add a .exe extension if the file is not found in its current form.
        //

        if (TryOpenWithSpecialMod) {
            if (FwOpen(PathName, ArcOpenReadOnly, &Count) == ESUCCESS) {
                FwClose(Count);
            } else {
                strcat(PathName, ".exe");
            }
        }

        //
        // Attempt to load the specified file.
        //

        FwSavedSp = 0;

        Status = FwExecute(PathName, ArgCount, LoadArgv, LoadEnvp);

        //
        // Close and reopen the console in case it was changed by the user.
        // Note that we must still check to see if there was a problem
        // with either the video or keyboard hardware when we first booted.
        //

        FwClose(ARC_CONSOLE_INPUT);
        FwClose(ARC_CONSOLE_OUTPUT);
        FwOpenConsole();

        if (Status == ESUCCESS) {

            //
            // Pause if returning from a boot.  This helps see osloader error
            // messages.
            //

            if (DefaultChoice <= 1) {
                FwPrint(FW_PRESS_ANY_KEY_MSG);
                FwRead(ARC_CONSOLE_INPUT, &Character, 1, &Count);
            }

        } else {
            ParseARCErrorStatus(Status);
        }
    }
}

VOID
ParseARCErrorStatus(
    IN ARC_STATUS Status
    )

/*++

Routine Description:

    This routine prints out an ARC error message and waits until the user
    hits a key on the keyboard.

Arguments:

    None.

Return Value:

    None.

--*/

{
    UCHAR Character;
    ULONG Count;

    FwSetScreenColor(ArcColorRed, ArcColorWhite);
    FwPrint(FW_ERROR2_MSG);

    if (Status <= EROFS) {
        FwPrint(FW_ERROR_MSG[Status - 1]);
    } else {
        FwPrint(FW_ERROR_CODE_MSG, Status);
    }

    FwPrint(FW_PRESS_ANY_KEY2_MSG);
    FwSetScreenColor(ArcColorWhite, ArcColorBlue);
    FwRead(ARC_CONSOLE_INPUT, &Character, 1, &Count);
}



VOID
FwErrorTopBoarder(
    VOID
    )

/*++

Routine Description:

    This routine clears the screen and prints out the top boarder of a
    major firwmare error message.

Arguments:

    None.

Return Value:

    None.

--*/

{
    FwSetPosition(4,5);

    FwPrint("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»");

}


VOID
FwErrorBottomBoarder(
    IN ULONG StartAtRow,
    IN BOOLEAN RedProblems
    )

/*++

Routine Description:

    This routine prints out the bottom boarder of a major firwmare error
    message at the current screen position, and then either stall or wait
    for the user to type a character.

Arguments:

    StartAtRow  -       The screen row to start outputting at.

    RedProblems -       TRUE if Red problems exist.

Return Value:

    None.

--*/

{
    UCHAR Character;
    ULONG Count;

    FwSetPosition(StartAtRow++, 5);
    FwPrint("º                                                          º");

    if (RedProblems) {
        FwSetPosition(StartAtRow++, 5);
        FwPrint(FW_RED_BANNER_PRESSKEY_MSG);
    }

    FwSetPosition(StartAtRow++, 5);
    FwPrint("ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ");

    if (RedProblems) {
        FwRead(ARC_CONSOLE_INPUT, &Character, 1, &Count);
    } else {
        FwStallExecution(4 * 1000 * 1000);
    }

}


BOOLEAN
FwpLookForEISAChildIdentifier(
    IN PCONFIGURATION_COMPONENT Component,
    IN PCHAR Identifier
    )

/*++

Routine Description:

    This looks for a child of Component with an identifier of Identifier.

Arguments:

    Component           Pointer to a node in the CDS tree.

    Identifier          Identifier string to match against.


Return Value:

    TRUE if no match found.
    FALSE if match found.

--*/

{
    Component = FwGetChild(Component);

    while (Component != NULL) {
        if ((Component->IdentifierLength != 0) &&
            (strcmp(Component->Identifier, Identifier) == 0)) {
            return (FALSE);
        }
        Component = FwGetPeer(Component);
    }

    return (TRUE);
}


BOOLEAN
FwpLookForEISAChildClassType(
    IN PCONFIGURATION_COMPONENT Component,
    IN CONFIGURATION_CLASS Class,
    IN CONFIGURATION_TYPE Type
    )

/*++

Routine Description:

    This looks for a child of Component with a class and type equal to
    Class and Type.

Arguments:

    Component           Pointer to a node in the CDS tree.

    Class               The class to match against.

    Type                The type to match against.


Return Value:

    TRUE if no match found.
    FALSE if match found.

--*/

{
    Component = FwGetChild(Component);

    while (Component != NULL) {
        if ((Component->Class == Class) &&
            (Component->Type == Type)) {
            return (FALSE);
        }
        Component = FwGetPeer(Component);
    }

    return (TRUE);
}


VOID
FwSystemConsistencyCheck (
    IN BOOLEAN Silent,
    OUT PULONG Problems
    )

/*++

Routine Description:

    This routine checks the state of the volatile copies of the ROM firmware
    data block, and the system time.  On an error, it can optionally output
    an error message.

    A volatile check is made to facilitate using this function in the
    built-in ROM setup utility.  When this is called during the power-up
    initialization, the volatile areas will not have been loaded if
    the ROM had a bad checksum, so this indirectly checks the ROM state
    includint the checksums.

    This consistency check is not exaustive.

Arguments:

    Silent              FALSE if messages should be sent to the console.
                        TRUE if this should run silently.

    Problems            A pointer to the variable that should receive the
                        indicatation of what problems were found.  Zero
                        (0) indicates no problems.

Return Value:

    None.

--*/

{
    UCHAR Floppy;
    UCHAR Floppy2;
    PCONFIGURATION_COMPONENT Component;
    BOOLEAN FoundBootProblems;
    PTIME_FIELDS SystemTime;
    ULONG TempX;
    ULONG Index;
    ULONG LineNumber;

    *Problems = FWP_MACHINE_PROBLEMS_NOPROBLEMS;

    //
    // Check system time
    //

    SystemTime = FwGetTime();

    if ((SystemTime->Year < 1993) ||
        (SystemTime->Month < 1) || (SystemTime->Month > 12) ||
        (SystemTime->Day < 1) || (SystemTime->Day > 31) ||
        (SystemTime->Hour < 0) || (SystemTime->Hour > 23) ||
        (SystemTime->Minute < 0) || (SystemTime->Minute > 59) ||
        (SystemTime->Second < 0) || (SystemTime->Second > 59) ||
        (SystemTime->Milliseconds < 0) || (SystemTime->Milliseconds > 999) ||
        (SystemTime->Weekday < 0) || (SystemTime->Weekday > 6)) {
        *Problems = FWP_MACHINE_PROBLEMS_TIME;
    }

    //
    // Check environment variables.
    //

    if (FwGetVolatileEnvironmentVariable("CONSOLEIN") == NULL) {
        *Problems |= FWP_MACHINE_PROBLEMS_EV;
    }

    //
    // Check the CDS
    //

    Component = FwGetComponent("cpu");

    if ((Component == NULL) ||
        (Component->Class != ProcessorClass) ||
        (Component->Type != CentralProcessor)) {

        //
        // If the CPU node is not valid, then the entire tree is probably bad.
        //

        *Problems |= FWP_MACHINE_PROBLEMS_CDS;
    }

    //
    // Check Floppy environment variables, which are set up by initing
    // the configuration.
    //

    if ((FwGetVolatileEnvironmentVariable("FLOPPY") == NULL) ||
        (FwGetVolatileEnvironmentVariable("FLOPPY2") == NULL)) {

        *Problems |= FWP_MACHINE_PROBLEMS_CDS;

    } else {

        //
        // Check the first character of the floppy environment variables.
        //

        Floppy = *FwGetVolatileEnvironmentVariable("FLOPPY");
        Floppy2 = *FwGetVolatileEnvironmentVariable("FLOPPY2");

        if ((Floppy < '0') || (Floppy > '2') ||
            ((Floppy2 != 'N') && ((Floppy2 < '0') || (Floppy2 > '2')))) {
            *Problems |= FWP_MACHINE_PROBLEMS_CDS;
        }
    }

    //
    // Check boot selections
    //

    JzCheckBootSelections(TRUE, &FoundBootProblems);
    if (FoundBootProblems) {
        *Problems |= FWP_MACHINE_PROBLEMS_BOOT;
    }

#ifdef EISA_PLATFORM

    //
    // If there were any errors discovered by the EISAini code, or the
    // minimum required children of the EISA adapter are not present,
    // indicate an EISA configuration error.  The three required children
    // are the system board, aha1742, and floppy.
    //

    if (ErrorsDuringEISABusConfiguration == TRUE) {

        *Problems |= FWP_MACHINE_PROBLEMS_ECU;
    }

    Component = FwGetComponent("eisa()");

    if ((Component == NULL) ||
        (Component->Class != AdapterClass) ||
        (Component->Type != EisaAdapter)) {

        *Problems |= FWP_MACHINE_PROBLEMS_CDS;
        *Problems |= FWP_MACHINE_PROBLEMS_ECU;

    } else {

        //
        // Look for the three required children of the EISA adapter.
        //

        //
        // System board and AHA1742
        //

        if (FwpLookForEISAChildIdentifier(Component, "DEC2400") ||
            FwpLookForEISAChildIdentifier(Component, "ADP0002")) {
            *Problems |= FWP_MACHINE_PROBLEMS_ECU;
        }

        //
        // SCSI adapter
        //

        if (FwpLookForEISAChildClassType(Component,
                                         AdapterClass,
                                         ScsiAdapter)) {
            *Problems |= FWP_MACHINE_PROBLEMS_ECU;
        }

    }

#endif


    if (!Silent && (*Problems != FWP_MACHINE_PROBLEMS_NOPROBLEMS)) {

        //
        // Tell the user what problems were found.
        //

        FwClearScreen();
        FwSetScreenColor(ArcColorBlue, ArcColorWhite);
        FwErrorTopBoarder();

        LineNumber = 5;

        for (Index = 0;
             Index < FW_SYSTEM_INCONSISTENCY_WARNING_MSG_SIZE;
             Index++) {
            FwSetPosition(LineNumber++, 5);
            FwPrint(FW_SYSTEM_INCONSISTENCY_WARNING_MSG[Index]);
        }

        TempX = *Problems;
        Index = 0;

        while (TempX != 0) {

            //
            // The check against a NULL MachineProblemAreas pointer is for
            // debugging and could be removed in the final product.
            //

            if ((((TempX & 1) != 0) || ((TempX & 0x10000) != 0)) &&
                (MachineProblemAreas[Index] != NULL)) {

                FwSetPosition(LineNumber++,5);

                // For effect, print out all the error areas in yellow.
                FwPrint(           %c3%dm%s%c3%dm         º",
                        ASCII_CSI,
                        ArcColorYellow,
                        MachineProblemAreas[Index],
                        ASCII_CSI,
                        ArcColorBlue);
            }

            TempX = ((TempX & FWP_MACHINE_PROBLEMS_RED) >> 1) |
                    (((TempX & FWP_MACHINE_PROBLEMS_YELLOW) >> 17) << 16);
            Index++;
        }

        //
        // LineNumber contains the line that we should next print on, and
        // the screen colors are Blue on White.
        //

        for (Index = 0;
             Index < FW_SYSTEM_INCONSISTENCY_WARNING_HOWTOFIX_MSG_SIZE;
             Index++) {
            FwSetPosition(LineNumber++, 5);
            FwPrint(FW_SYSTEM_INCONSISTENCY_WARNING_HOWTOFIX_MSG[Index]);
        }

        //
        // Print the bottom of the error message.  Stall if only yellow
        // errors were found, otherwise wait for a keypress.
        //

        FwErrorBottomBoarder(LineNumber,
                             (*Problems & FWP_MACHINE_PROBLEMS_RED));

        FwSetScreenColor(ArcColorWhite, ArcColorBlue);

    }

    return;
}

VOID
FwInitialize (
    IN ULONG MemSize
    )

/*++

Routine Description:

    This routine initializes the system parameter block which is located
    in low memory. This structure contains the firmware entry vector and
    the restart parameter block.  This routine also initializes the io devices,
    the configuration, and opens standard in/out.

    Note: the system parameter block is initialized early in selftest.c.
    This was needed in the Jazz code because of how the Jazz video prom code
    worked; it is mainted here for code compatibility reasons.

Arguments:

    MemSize - Not Used. For compatibility with definitions in bldr\firmware.h

Return Value:

    None.

--*/

{
    ULONG Fid;
    ULONG Index;
    CHAR DiskPath[40];
    BOOLEAN BadROMType = FALSE;

    FwPrint(FW_INITIALIZING_MSG);

    //
    // Initialize Signal vector. And set default signal.
    //
//    (PARC_SIGNAL_ROUTINE)SYSTEM_BLOCK->FirmwareVector[SignalRoutine] = FwSignal;

    //
    // Initialize Vendor Must be done before Calling FwAllocatePool.  Also
    // initialize the system ID and time.
    //

    FwVendorInitialize();
    FwSystemIdInitialize();
    FwTimeInitialize();

#ifdef JENSEN

    //
    // Determine the type of ROM in the machine.
    //

    if (FwROMDetermineMachineROMType() != ESUCCESS) {
        FwPrint(FW_UNKNOWN_ROM_MSG);
        BadROMType = TRUE;
    }

#endif

    //
    // Initialize the Fw loadable services.
    //

    FwLoadInitialize();

    //
    // Not needed for Jensen, since the SROM disables interrupts.
    //
    // Disable the I/O device interrupts.
    //
//    WRITE_PORT_USHORT(&((PINTERRUPT_REGISTERS)INTERRUPT_VIRTUAL_BASE)->Enable,0);

    // Not needed for Alpha/Jensen.
    //
    // Initialize the firmware exception handling.
    // This also enables interrupts in the psr and clears BEV
    //
//    FwExceptionInitialize();

    //
    // Initialize the termination function entry points in the transfer vector
    //
    FwTerminationInitialize();

    //
    // Initialize configuration
    //

    FwConfigurationInitialize();

    //
    // Initialize the environment.
    //

    FwEnvironmentInitialize();

    //
    // Initialize IO structures and display driver.
    //

    FwIoInitialize1();

    //
    // Load the environment, because HardDiskInitialize will make a call
    // to FwSaveConfiguration.
    //

    FwEnvironmentLoad();

    //
    // Initialize the I/O services.
    //

    FwIoInitialize2();

    //
    // Open the std in and out device. The path name should be taken
    // from ConsoleIn and ConsoleOut environment variables.
    //
    // N.B. FwGetEnvironmentVariable cannot be called again between the
    //      ConsoleName assignment and its use.
    //

    FwOpenConsole();
    FwConsoleInitialized = TRUE;

    FwPrint(FW_OK_MSG);
    FwPrint(FW_CRLF_MSG);

#ifdef ALPHA_FW_KDHOOKS

    //
    // Break into the debugger if the EisaBreak environment variable
    // is defined.
    //

    if (FwGetEnvironmentVariable("EisaBreak") != NULL) {
        FwPrint("\r\n Breaking into the debugger... \r\n");
        FwInstallKd();
        DbgBreakPoint();
    }

#endif  // ALPHA_FW_KDHOOKS

    //
    // Initialize the EISA routines
    //

    ErrorsDuringEISABusConfiguration = FALSE;
    EisaIni();

    if (ErrorsDuringEISABusConfiguration || BadROMType) {
        FwPrint(FW_CRLF_MSG);
        FwWaitForKeypress(FALSE);
    }

    //
    // Initialize the Restart Block.
    //

    FwInitializeRestartBlock();

    //
    // Spin up all of the disks, if necessary.
    //

    FwPrint(FW_SPIN_DISKS_MSG);
    for (Index = 0; Index < 8 ; Index++ ) {
        FwPrint(".");
        sprintf(DiskPath,"scsi(0)disk(%1d)rdisk(0)partition(0)", Index);
        if (FwOpen(DiskPath,ArcOpenReadWrite,&Fid) == ESUCCESS) {
            FwClose(Fid);
        }
    }
    FwPrint(FW_OK_MSG);
    FwPrint(FW_CRLF_MSG);
    return;
}

#ifdef ALPHA_FW_KDHOOKS

VOID
FwInstallKd(
    IN VOID
    )

/*++

Routine Description:

    This routine installs the kernel debugger exception handlers and
    initializes it.

Arguments:

    None.

Return Value:

    None.

--*/
{
    STRING NameString;

    //
    // Initialize data structures used by the kernel debugger.
    //

    Prcb.Number = 0;
    Prcb.CurrentThread = &Thread;
    KiProcessorBlock[0] = &Prcb;
    Process.DirectoryTableBase[0] = 0xffffffff;
    Process.DirectoryTableBase[1] = 0xffffffff;
    Thread.ApcState.Process = &Process;
    KeNumberProcessors = 1;

    KiCurrentThread = &Thread;
    KiDpcRoutineActiveFlag = FALSE;
    KiPcrBaseAddress = &KernelPcr;
    KernelPcr.FirstLevelDcacheSize = 0x2000;
    KernelPcr.FirstLevelDcacheFillSize = 32;
    KernelPcr.FirstLevelIcacheSize = 0x2000;
    KernelPcr.FirstLevelIcacheFillSize = 32;
    KernelPcr.CycleClockPeriod = ProcessorCycleCounterPeriod;
    KiPrcbBaseAddress = &Prcb;

    KdInitSystem(NULL, FALSE);
    KdInstalled = TRUE;

    //
    // Stop in the debugger after asking for the symbols to be loaded.
    // The computation in the DbgLoadImageSymbols call is because the
    // kernel debugger cannot read a normal "-rom" linked firmware .exe image,
    // so a dual was linked without the "-rom" switch.  The proper reading
    // of this file requires a -0x400 offset.
    //

#ifdef JENSEN
    RtlInitString(&NameString, "jensfw.exe");
#endif // JENSEN

#ifdef MORGAN
    RtlInitString(&NameString, "mrgnfw.exe");
#endif // MORGAN

    DbgLoadImageSymbols(&NameString, (0x80704000-0x400), (ULONG)-1);
    DbgBreakPoint();
}

#endif


VOID
FwOpenConsole(
    IN VOID
    )
/*++

Routine Description:

     This opens the console input and output devices.

Arguments:

     None.


Return Value:

     None.

--*/
{
    ULONG Fid;
    PCHAR ConsoleName;

    //
    // Open the std in and out device. The path name should be taken
    // from ConsoleIn and ConsoleOut environment variables.
    //
    // N.B. FwGetEnvironmentVariable cannot be called again between the
    //      ConsoleName assignment and its use.
    //

    if (SerialOutput) {
        ConsoleName=FW_SERIAL_0_DEVICE;
    } else {
        if ((FwGetEnvironmentVariable("ConsoleOut") == NULL) ||
            ((ConsoleName = FwGetEnvironmentVariable("ConsoleIn")) == NULL)){
                ConsoleName=FW_KEYBOARD_IN_DEVICE;
        }
    }

    if (FwOpen(ConsoleName,ArcOpenReadOnly,&Fid) != ESUCCESS) {

        FwPrint(FW_CONSOLE_IN_ERROR_MSG);
        FwPrint(FW_CONSOLE_TRYING_TO_OPEN_MSG, FW_KEYBOARD_IN_DEVICE);

        if (FwOpen(FW_KEYBOARD_IN_DEVICE,ArcOpenReadOnly,&Fid) != ESUCCESS) {
            FwPrint(FW_CONSOLE_IN_FAILSAFE_ERROR_MSG);
            FwPrint(FW_CONTACT_FIELD_SERVICE_MSG);
        } else {
            FwPrint(FW_OK_MSG);
            FwPrint(FW_CRLF_MSG);
            FwPrint(FW_CONSOLE_IN_PLEASE_REPAIR_MSG);
        }

        FwStallExecution(5000000);
    }

    if (Fid != ARC_CONSOLE_INPUT) {
        FwPrint(FW_CONSOLE_IN_ERROR2_MSG);
    }

    if (SerialOutput) {
        ConsoleName=FW_SERIAL_0_DEVICE;
    } else {
        if ((FwGetEnvironmentVariable("ConsoleIn") == NULL) ||
            ((ConsoleName = FwGetEnvironmentVariable("ConsoleOut")) == NULL)) {
            ConsoleName=FW_CONSOLE_OUT_DEVICE;
        }
    }

    if (FwOpen(ConsoleName,ArcOpenWriteOnly,&Fid) != ESUCCESS) {
        FwPrint(FW_CONSOLE_OUT_ERROR_MSG);
        FwPrint(FW_CONSOLE_TRYING_TO_OPEN_MSG, FW_CONSOLE_OUT_DEVICE);

        if (FwOpen(FW_CONSOLE_OUT_DEVICE,ArcOpenWriteOnly,&Fid) != ESUCCESS) {
            FwPrint(FW_CONSOLE_OUT_FAILSAFE_ERROR_MSG);
            FwPrint(FW_CONTACT_FIELD_SERVICE_MSG);
        } else {
            FwPrint(FW_OK_MSG);
            FwPrint(FW_CRLF_MSG);
            FwPrint(FW_CONSOLE_OUT_PLEASE_REPAIR_MSG);
        }

        FwStallExecution(5000000);
    }

    if (Fid != ARC_CONSOLE_OUTPUT) {
        FwPrint(FW_CONSOLE_OUT_ERROR2_MSG);
    }
}

VOID
FwSetupFloppy(
    VOID
    )
/*++

Routine Description:

     Because the NT floppy driver expects the floppy disk controller node
     as a child of an EISA or ISA Adapter, and the EISA Configuration Utility
     deletes all children of the EISA Adapter before it configures the
     EISA bus, the firmware must add the floppy disk controller information
     after the ECU has been run on an EISA-based machine.  We will also
     do this on an ISA-based machine to keep the code simple.

     The configuration requirements for the floppy have been stored in
     environment variables by configuration code in the jnsetcfg.c module.

     This function adds in the floppy nodes, if configuration information
     exists and the nodes are not already in the tree.

Arguments:

     None.


Return Value:

     None.

--*/
{
    UCHAR Floppy;
    UCHAR Floppy2;
    PCONFIGURATION_COMPONENT FloppyControllerLevel;
    PCONFIGURATION_COMPONENT FloppyParentAdapterLevel;
    CONFIGURATION_COMPONENT Component;
    UCHAR Buffer[sizeof(CM_PARTIAL_RESOURCE_LIST) +
                 (sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 5) +
                 MAXIMUM_DEVICE_SPECIFIC_DATA];
    PCM_PARTIAL_RESOURCE_LIST Descriptor = (PCM_PARTIAL_RESOURCE_LIST)&Buffer;
    ULONG DescriptorSize;
    CM_FLOPPY_DEVICE_DATA FloppyDeviceData;

    //
    // Return if:
    //
    // If the floppy environment variables do not exist
    // (FwSystemConsistencyCheck has already reported this).
    //
    // If a floppy controller node already exists.
    //
    // If the floppy parent node (eg, the EISA adapter on an EISA machine)
    // does not exist. (FwSystemConsistencyCheck has already reported this.)
    //

    if ((FwGetEnvironmentVariable("FLOPPY") == NULL) ||
        (FwGetEnvironmentVariable("FLOPPY2") == NULL) ||
        (((FloppyControllerLevel = FwGetComponent(FW_FLOPPY_0_DEVICE))
         != NULL) &&
         (FloppyControllerLevel->Class == PeripheralClass) &&
         (FloppyControllerLevel->Type == FloppyDiskPeripheral)) ||
        ((FloppyParentAdapterLevel = FwGetComponent(FW_FLOPPY_PARENT_NODE)) == NULL)) {
        return;
    }

    //
    // Get the first character of the floppy environment variables.
    //

    Floppy = *FwGetEnvironmentVariable("FLOPPY");
    Floppy2 = *FwGetEnvironmentVariable("FLOPPY2");

    //
    // Now add the floppy controller and one or two peripherals to the
    // CDS tree.
    //
    // This is needed for both non-ECU and ECU-supporting firmware packages
    // because the NT floppy driver is incapable of finding and parsing
    // configuration information stored in the Registry at the EISAAdapter
    // node.  All nodes under the EISAAdapter node in the Component Data
    // Structure are collapsed into one EISAAdapter Registry node by the
    // CM, so we must hardwire the floppy controller node into the ARC
    // tree.  A side-effect of this is that Jensen can support only one
    // ISA floppy controller.
    //

    DescriptorSize =
        JzMakeDescriptor (Descriptor,                   // Descriptor
                          TRUE,                         // Port
                          FLOPPY_ISA_PORT_ADDRESS,      // PortStart
                          8,                            // PortSize
                          TRUE,                         // Interrupt
                          CM_RESOURCE_INTERRUPT_LATCHED, // InterruptFlags
                          FLOPPY_LEVEL,                 // Level
#ifdef EISA_PLATFORM
                          0,                            // Vector
#else
                          ISA_FLOPPY_VECTOR,            // Vector
#endif

                          FALSE,                        // Memory
                          0,                            // MemoryStart
                          0,                            // MemorySize
                          TRUE,                         // Dma
                          FLOPPY_CHANNEL,               // Channel
                          FALSE,                        // SecondChannel
                          FALSE,                        // DeviceSpecificData
                          0,                            // Size
                          NULL                          // Data
                          );

    JzMakeComponent(&Component,
                    ControllerClass,    // Class
                    DiskController,     // Type
                    FALSE,              // Readonly
                    FALSE,              // Removeable
                    FALSE,              // ConsoleIn
                    FALSE,              // ConsoleOut
                    TRUE,               // Input
                    TRUE,               // Output
                    0,                  // Key
                    DescriptorSize,     // ConfigurationDataLength
                    FW_FLOPPY_CDS_IDENTIFIER    // Identifier
                    );

    FloppyControllerLevel = FwAddChild(FloppyParentAdapterLevel,
                                       &Component,
                                       Descriptor);

    //
    // Add the floppy disk itself as a child of the floppy disk controller.
    //

    FloppyDeviceData.Version = ARC_VERSION;
    FloppyDeviceData.Revision = ARC_REVISION;

    //
    // This switch is tied to the order of the strings in the
    // FloppyChoices array, defined at the beginning of jnsetmak.c.
    //

    switch (Floppy) {

    case '0':
        FloppyDeviceData.Size[0] = '5';
        FloppyDeviceData.Size[1] = '.';
        FloppyDeviceData.Size[2] = '2';
        FloppyDeviceData.Size[3] = '5';
        FloppyDeviceData.Size[4] = 0;
        FloppyDeviceData.Size[5] = 0;
        FloppyDeviceData.Size[6] = 0;
        FloppyDeviceData.Size[7] = 0;
        FloppyDeviceData.MaxDensity = 1200;
        FloppyDeviceData.MountDensity = 0;
        break;

    case '1':
    case '2':
    default:
        FloppyDeviceData.Size[0] = '3';
        FloppyDeviceData.Size[1] = '.';
        FloppyDeviceData.Size[2] = '5';
        FloppyDeviceData.Size[3] = 0;
        FloppyDeviceData.Size[4] = 0;
        FloppyDeviceData.Size[5] = 0;
        FloppyDeviceData.Size[6] = 0;
        FloppyDeviceData.Size[7] = 0;

        if (Floppy == '1') {
            FloppyDeviceData.MaxDensity = 1440;
        } else {
            FloppyDeviceData.MaxDensity = 2880;
        }
        FloppyDeviceData.MountDensity = 0;
        break;
    }

    DescriptorSize =
        JzMakeDescriptor (Descriptor,                   // Descriptor
                          FALSE,                        // Port
                          0,                            // PortStart
                          0,                            // PortSize
                          FALSE,                        // Interrupt
                          0,                            // InterruptFlags
                          0,                            // Level
                          0,                            // Vector
                          FALSE,                        // Memory
                          0,                            // MemoryStart
                          0,                            // MemorySize
                          FALSE,                        // Dma
                          0,                            // Channel
                          FALSE,                        // SecondChannel
                          TRUE,                         // DeviceSpecificData
                          sizeof(CM_FLOPPY_DEVICE_DATA), // Size
                          (PVOID)&FloppyDeviceData      // Data
                          );

    JzMakeComponent(&Component,
                    PeripheralClass,    // Class
                    FloppyDiskPeripheral,  // Type
                    FALSE,              // Readonly
                    TRUE,               // Removeable
                    FALSE,              // ConsoleIn
                    FALSE,              // ConsoleOut
                    TRUE,               // Input
                    TRUE,               // Output
                    0,                  // Key
                    DescriptorSize,     // ConfigurationDataLength
                    NULL                // Identifier
                    );

    FwAddChild( FloppyControllerLevel, &Component, Descriptor );


    //
    // Add a second floppy disk as a child of the floppy disk controller.
    //

    if (Floppy2 != 'N') {

        FloppyDeviceData.Version = ARC_VERSION;
        FloppyDeviceData.Revision = ARC_REVISION;

        switch (Floppy2) {

        case '0':
            FloppyDeviceData.Size[0] = '5';
            FloppyDeviceData.Size[1] = '.';
            FloppyDeviceData.Size[2] = '2';
            FloppyDeviceData.Size[3] = '5';
            FloppyDeviceData.Size[4] = 0;
            FloppyDeviceData.Size[5] = 0;
            FloppyDeviceData.Size[6] = 0;
            FloppyDeviceData.Size[7] = 0;
            FloppyDeviceData.MaxDensity = 1200;
            FloppyDeviceData.MountDensity = 0;
            break;

        case '1':
        case '2':
        default:
            FloppyDeviceData.Size[0] = '3';
            FloppyDeviceData.Size[1] = '.';
            FloppyDeviceData.Size[2] = '5';
            FloppyDeviceData.Size[3] = 0;
            FloppyDeviceData.Size[4] = 0;
            FloppyDeviceData.Size[5] = 0;
            FloppyDeviceData.Size[6] = 0;
            FloppyDeviceData.Size[7] = 0;
            if (Floppy2 == '1') {
                FloppyDeviceData.MaxDensity = 1440;
            } else {
                FloppyDeviceData.MaxDensity = 2880;
            }
            FloppyDeviceData.MountDensity = 0;
            break;
        }

        DescriptorSize =
            JzMakeDescriptor (Descriptor,                   // Descriptor
                              FALSE,                        // Port
                              0,                            // PortStart
                              0,                            // PortSize
                              FALSE,                        // Interrupt
                              0,                            // InterruptFlags
                              0,                            // Level
                              0,                            // Vector
                              FALSE,                        // Memory
                              0,                            // MemoryStart
                              0,                            // MemorySize
                              FALSE,                        // Dma
                              0,                            // Channel
                              FALSE,                        // SecondChannel
                              TRUE,                         // DeviceSpecificData
                              sizeof(CM_FLOPPY_DEVICE_DATA), // Size
                              (PVOID)&FloppyDeviceData      // Data
                              );

        JzMakeComponent(&Component,
                        PeripheralClass,    // Class
                        FloppyDiskPeripheral,  // Type
                        FALSE,              // Readonly
                        TRUE,               // Removeable
                        FALSE,              // ConsoleIn
                        FALSE,              // ConsoleOut
                        TRUE,               // Input
                        TRUE,               // Output
                        1,                  // Key
                        DescriptorSize,     // ConfigurationDataLength
                        NULL                // Identifier
                        );

        FwAddChild( FloppyControllerLevel, &Component, Descriptor );

    }

    return;

}

ARC_STATUS
FwpFindCDROM (
    OUT PCHAR PathName
    )
/*++

Routine Description:

     This function finds the first CD-ROM in the machine, and returns
     an ARC pathstring to it.

Arguments:

     PathName           A pointer to a buffer area that can receive
                        the CDROM pathname string.

Return Value:

     ESUCCESS if the PathName was loaded.

     Otherwise, an error code.  On an error return, PathName is loaded
     with "scsi(0)cdrom(4)fdisk(0)".

--*/
{
    PCONFIGURATION_COMPONENT Controller;
    BOOLEAN VariableFound = FALSE;
    ULONG Index;

    for ( Index = 0 ; Index < 8 ; Index++ ) {
        sprintf(PathName, "scsi(0)cdrom(%d)fdisk(0)", Index);
        Controller = FwGetComponent(PathName);
        if ((Controller != NULL) &&
            (Controller->Type == FloppyDiskPeripheral)) {
            VariableFound = TRUE;
            break;
        }
    }

    if (VariableFound) {
        return (ESUCCESS);
    } else {
        sprintf(PathName, "scsi0)cdrom(4)fdisk(0)");
        return (EIO);
    }
}

ARC_STATUS
FwpEvaluateWNTInstall(
    OUT PCHAR PathName
    )
/*++

Routine Description:

     This function checks to see if this machine is ready to install
     NT.  If so, it finds the SCSI ID of the CD-ROM drive, and returns
     the pathname to be used.

     If there is a problem, error messages are output to the screen.

Arguments:

     PathName           A pointer to a buffer area that can receive
                        the setupldr pathname string.

Return Value:

     ESUCCESS if the PathName string should be used to try to run
     setupldr.

     Otherwise, an error code.

--*/
{
    PCONFIGURATION_COMPONENT Component;
    ULONG Problems;

    //
    // If the Red machine state is inconsistent, or there is no CD-ROM,
    // do an error return.
    //

    FwSystemConsistencyCheck(FALSE, &Problems);

    if (((Problems & FWP_MACHINE_PROBLEMS_RED) != 0) ||
        (FwpFindCDROM(PathName) != ESUCCESS)) {

        //
        // If there are no Red machine consistency problems, we must be
        // here because FwpFindCDROM gave an error return.
        //

        if ((Problems & FWP_MACHINE_PROBLEMS_RED) == 0) {
            FwPrint(FW_NO_CDROM_DRIVE_MSG);
        }

        FwPrint(FW_WNT_INSTALLATION_ABORTED_MSG);
        FwWaitForKeypress(FALSE);
        return (EIO);
    }

    //
    // We found the CD-ROM drive.  Append the setupldr string to the
    // CD-ROM string and return.
    //

    strcat (PathName, "\\alpha\\setupldr");
    return (ESUCCESS);
}