summaryrefslogtreecommitdiffstats
path: root/private/ntos/fw/alpha/omf.c
blob: 50455af6e3a394729b44659d399432e9866ba92d (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
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
// ----------------------------------------------------------------------------
//
//      Copyright (c) 1992  Olivetti
//
//      File:           omf.c
//
//      Description:    this code implements the omf protocol as defined
//                      in the ARC-EISA addendum.
//
// ----------------------------------------------------------------------------

#include "fwp.h"
#include "oli2msft.h"
#include "arceisa.h"
#include "inc.h"
#include "string.h"
#include "debug.h"

extern  BL_FILE_TABLE BlFileTable [BL_FILE_TABLE_SIZE];

#define DEVICE_DEVICE 0xDEAD


// ----------------------------------------------------------------------------
//  Declare Function Prototypes
// ----------------------------------------------------------------------------

ARC_STATUS
OmfOpen
    (
    IN PCHAR OpenPath,
    IN OPEN_MODE OpenMode,
    IN OUT PULONG FileId
    );

ARC_STATUS
OmfClose
    (
    IN ULONG FileId
    );

ARC_STATUS
OmfMount
    (
    IN PCHAR            MountPath,
    IN MOUNT_OPERATION  Operation
    );

ARC_STATUS
OmfRead
    (
    IN  ULONG   FileId,
    IN  PVOID   Buffer,
    IN  ULONG   Length,
    OUT PULONG  Count
    );

ARC_STATUS
OmfWrite
    (
    IN  ULONG  FileId,
    IN  PVOID  Buffer,
    IN  ULONG  Length,
    OUT PULONG Count
    );

ARC_STATUS
OmfGetReadStatus
    (
    IN ULONG FileId
    );

ARC_STATUS
OmfSeek
    (
    IN ULONG            FileId,
    IN PLARGE_INTEGER   Offset,
    IN SEEK_MODE        SeekMode
    );

ARC_STATUS
OmfGetFileInformation
    (
    IN  ULONG FileId,
    OUT PFILE_INFORMATION Buffer
    );

ARC_STATUS
OmfSetFileInformation
    (
    IN ULONG FileId,
    IN ULONG AttributeFlags,
    IN ULONG AttributeMask
    );

ARC_STATUS
OmfGetDirectoryEntry
    (
    IN  ULONG           FileId,
    IN  DIRECTORY_ENTRY *DirEntry,
    IN  ULONG           NumberDir,
    OUT PULONG          CountDir
    );

ARC_STATUS
OmfFileOpen
    (
    IN PCHAR            OpenPath,
    IN OPEN_MODE        OpenMode,
    IN OUT PULONG       FileId
    );

ARC_STATUS
OmfFileClose
    (
    IN ULONG FileId
    );

ARC_STATUS
OmfFileMount
    (
    IN PCHAR            MountPath,
    IN MOUNT_OPERATION  Operation
    );

ARC_STATUS
OmfFileRead
    (
    IN  ULONG  FileId,
    IN  PVOID  Buffer,
    IN  ULONG  Length,
    OUT PULONG Count
    );

ARC_STATUS
OmfFileWrite
    (
    IN  ULONG  FileId,
    IN  PVOID  Buffer,
    IN  ULONG  Length,
    OUT PULONG Count
    );

ARC_STATUS
OmfFileGetReadStatus
    (
    IN ULONG FileId
    );

ARC_STATUS
OmfFileSeek
    (
    IN ULONG            FileId,
    IN PLARGE_INTEGER   Offset,
    IN SEEK_MODE        SeekMode
    );

ARC_STATUS
OmfFileGetFileInformation
    (
    IN  ULONG FileId,
    OUT PFILE_INFORMATION Buffer
    );

ARC_STATUS
OmfFileSetFileInformation
    (
    IN ULONG FileId,
    IN ULONG AttributeFlags,
    IN ULONG AttributeMask
    );

ARC_STATUS
OmfFileGetDirectoryEntry
    (
    IN  ULONG           FileId,
    IN  DIRECTORY_ENTRY *DirEntry,
    IN  ULONG           NumberDir,
    OUT PULONG          CountDir
    );

BOOLEAN
MaxOmfFatFiles
    (
    IN OUT PCHAR MasterName,
    IN PCHAR     CheckedName
    );

BOOLEAN
OmfFileNameValidate
    (
    IN  PCHAR OpenPath,
    OUT PCHAR OmfFileName,
    OUT PCHAR OmfType
    );

BOOLEAN
CmpOmfFiles
    (
    IN PCHAR        OmfFileName,
    IN CHAR         OmfType,
    IN POMF_DIR_ENT POmfDirEnt
    );

BOOLEAN
OmfHeaderValidate
    (
    IN ULONG FileId
    );

BOOLEAN
OmfFileValidate
    (
    IN ULONG FileId
    );

VOID
ConvertOmfDirToArcDir
    (
    IN POMF_DIR_ENT     POmfDirEnt,
    OUT DIRECTORY_ENTRY *PArcDirEnt
    );

BOOLEAN
FwGetEisaId
    (
    IN  PCHAR  PathName,
    OUT PCHAR  EisaId,
    OUT PUCHAR IdInfo
    );

VOID
FwUncompressEisaId
    (
    IN  PUCHAR CompEisaId,
    OUT PUCHAR UncompEisaId
    );

BOOLEAN
FwGetEisaBusIoCpuAddress
    (
    IN  PCHAR  EisaPath,
    OUT PVOID *IoBusAddress
    );

PCHAR
FwGetEnvironmentVariable
    (
    IN PCHAR Variable
    );

PCONFIGURATION_COMPONENT
FwGetComponent
    (
    IN PCHAR Pathname
    );

LARGE_INTEGER
RtlConvertUlongToLargeInteger
    (
    IN ULONG UnsignedInteger
    );

LARGE_INTEGER
RtlLargeIntegerAdd
    (
    IN LARGE_INTEGER Addend1,
    IN LARGE_INTEGER Addend2
    );

ARC_STATUS
FwFileIdChecksum
    (
    IN ULONG FileId,
    IN LARGE_INTEGER StartingOffset,
    IN ULONG Length,
    IN OUT PUCHAR Checksum
    );

BOOLEAN
FwGetMnemonicKey
    (
    IN PCHAR  Path,
    IN PCHAR  Mnemonic,
    IN PULONG Key
    );

BOOLEAN
FwGetNextMnemonic
    (
    IN  PCHAR Path,
    IN  PCHAR Mnemonic,
    OUT PCHAR NextMnemonic
    );

BOOLEAN
FwGetMnemonicPath
    (
    IN  PCHAR Path,
    IN  PCHAR Mnemonic,
    OUT PCHAR MnemonicPath
    );

BOOLEAN
GetNextPath
    (
    IN OUT PCHAR *PPathList,
    OUT PCHAR     PathTarget
    );


// ----------------------------------------------------------------------------
//      Global Data
// ----------------------------------------------------------------------------

//
// Omf entry table.
// This is a structure that provides entry to the OMF system procedures.
// It is exported when a OMF is opened as a device.
//

BL_DEVICE_ENTRY_TABLE OmfEntryTable =
    {
        OmfClose,
        OmfMount,
        OmfOpen,
        OmfRead,
        OmfGetReadStatus,
        OmfSeek,
        OmfWrite,
        OmfGetFileInformation,
        OmfSetFileInformation,
	NULL,
        OmfGetDirectoryEntry
    };


//
// Omf file entry table.
// This is a structure that provides entry to the OMF file system procedures.
// It is exported when a OMF file is opened.
//

BL_DEVICE_ENTRY_TABLE OmfFileEntryTable =
    {
        OmfFileClose,
        OmfFileMount,
        OmfFileOpen,
        OmfFileRead,
        OmfFileGetReadStatus,
        OmfFileSeek,
        OmfFileWrite,
        OmfFileGetFileInformation,
        OmfFileSetFileInformation,
	NULL,
        OmfFileGetDirectoryEntry
    };







// ----------------------------------------------------------------------------
// PROCEDURE:   OmfOpen:
//
// DESCRIPTION: The routine opens the newest version/revision of OMF for
//              the specified Product ID.
//
//              a) It reads the EISAROM bit of the <device> component of
//                 the Path argument on the EISA bus spcified by the key of
//                 the <adapter> component of Path argument.
//              b) If this bit is one, then a byte checksum is performed on
//                 the ROM-based OMF header and OMF directory.
//                 The Product ID, Firmware Version and Revision fields
//                 values are retained for the next operations.
//              c) Next, the partitions, specified by the FWSearchPath
//                 environment variable are searched for files of the
//                 following form in the \eisa\omf  subdirectory:
//
//                        <device>"V".LF"R"
//
//                        <device> = EISA Product ID (7 chars)
//                             "V" = version  ([0-9],[A-Z])
//                             "R" = revision ([0-9],[A-Z])
//
//              d) The OMF FAT file (or ROM) with a greater value of version-
//                 revision and with a correct checksum is used.
//              f) Initialize some data structures
//
//              When Open is used to access an OMF as a raw device, all input
//              functions are permitted.  These functions include Read, Seek
//              and Close.  Read and Seek are bounded by the current OMF size.
//              For example, to read the OMF of a serial options board that was
//              in slot 3 of EISA bus 0 as raw device, create and Open a path
//              as follows:     eisa(0)serial(3)omf() .
//
// ARGUMENTS:   OpenPath        Supplies a pointer to a zero terminated device
//                              path name.
//              OpenMode        Supplies the mode of the open.
//              FileId          Supplies a pointer to a variable that specifies
//                              the file table entry that is to be filled in
//                              if the open is successful.
//
// RETURN:      ESUCCESS        is returned if the open operation is successful.
//              ENODEV          the device portion of the pathname is invalid
//
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfOpen
    (
    IN PCHAR OpenPath,
    IN OPEN_MODE OpenMode,
    IN OUT PULONG FileId
    )
{
    //
    // initialize local variables
    //

    LARGE_INTEGER Offset;               // large interger for seek operations
    ULONG SlotNumber;                   // eisa slot number
    CHAR EisaCtrlMnemonic[ MAX_MNEMONIC_LEN +1 ]; // eisa ctrl mnemonic name
    UCHAR IdInfo;                       // info id byte
    PVOID IoBusAddress;                 // eisa I/O base address (virtual)
    PUCHAR SlotAddress;                 // I/O address
    BOOLEAN OmfRomOk=FALSE;             // OMF ROM initialization flag
    BOOLEAN OmfFatFileOk=FALSE;         // OMF FAT file initialization flag
    ULONG Count;                        // # of bytes transferred
    PCHAR PFwSearchPath;                // system partitions list pointer
    CHAR OmfPathName[MAX_PATH_LEN +1];  // directory+subdirectory+file name
    CHAR OmfPathBuffer[MAX_PATH_LEN +1] = {'\0'}; // OMF path name buffer
    CHAR OmfFatFileName[]="        .LF "; // omf name (FAT format)

    ULONG OmfSubdirId;                  // file Id of \eisa\omf subdirectory
    POMF_HEADER_CONTEXT POmfHeaderContext; // OMF header context pointer
    POMF_HDR POmfHeader;                // pointer to OMF ROM/FAT file header
    DIRECTORY_ENTRY DirEntBuffer;        // ARC directory entry

    PRINTDBG("OmfOpen\n\r");            // debug support

    //
    // this is a read only device
    //

    if  ( OpenMode != ArcOpenReadOnly )
    {
        return EROFS;
    }

    //
    // The path must have the following form :  eisa(x)"mnemonic"(y)omf()
    // Get EISA ID, slot number and its I/O address space.
    //

    if  ( !FwGetNextMnemonic( OpenPath, "eisa", EisaCtrlMnemonic )
          ||
          !FwGetMnemonicKey( OpenPath, EisaCtrlMnemonic, &SlotNumber )
          ||
          !FwGetMnemonicPath( OpenPath, EisaCtrlMnemonic, OmfPathName )
          ||
          !FwGetEisaId( OmfPathName, OmfFatFileName, &IdInfo )
          ||
          !FwGetMnemonicPath( OpenPath,"eisa",OmfPathName )
          ||
          !FwGetEisaBusIoCpuAddress( OmfPathName, &IoBusAddress ) )
    {
        return ENODEV;
    }

    //
    // Initialize some variables
    //

    POmfHeaderContext   = &BlFileTable[ *FileId ].u.OmfHeaderContext;
    POmfHeader          = &POmfHeaderContext->OmfHeader;
    SlotAddress         = (PUCHAR)IoBusAddress + SlotNumber * 0x1000;
    Offset.LowPart      = 0;                    // seek operation
    Offset.HighPart     = 0;                    // seek operation

    //
    // Check EISAROM bit of the Expansion Board Control Bits field.
    // If the EISA ID is readable, the controller supports the EISA extensions
    //

    // DEBUG-DEBUG :    for now skip the OMF ROM check because
    //                  at the moment there isn't any board available
    //                  with an OMF ROM to test the routine.

#if 0
    if ( !(IdInfo & CFG_UNREADABLE_ID)  &&
           READ_PORT_UCHAR( SlotAddress + EXPANSION_BOARD_CTRL_BITS ) &
                                      EISAROMBIT )
    {
        //
        // initialize some fields to direct the OmfRead to the ROM
        //

        POmfHeaderContext->RomIndex = (PULONG)(SlotAddress+ROMINDEX);
        POmfHeaderContext->RomRead  = (PULONG)(SlotAddress+ROMREAD);
        POmfHeaderContext->FileId   = DEVICE_DEVICE;
        POmfHeader->FwSize          = 0;        // max length simulation

        //
        // check OMF ROM header, copy it in the OmfHeaderContext structure
        //

        if  ( !OmfSeek( *FileId, &Offset, SeekAbsolute)
              &&
              !OmfRead( *FileId,
                        (PVOID)POmfHeader,
                        (ULONG)sizeof(OMF_HDR),
                        &Count )
              &&
              OmfHeaderValidate( *FileId ) )
        {
            //
            // copy version and revision
            //

            ((POMF_FAT_FILE_NAME)OmfFatFileName)->Version  =
                                                        POmfHeader->FwVersion;
            ((POMF_FAT_FILE_NAME)OmfFatFileName)->Revision =
                                                        POmfHeader->FwRevision;
            //
            // OMF ROM initialization has been done
            //

            OmfRomOk=TRUE;
        }
    }
#endif

    //
    // Set the current FileId to "open" so that calls to FwOpen won't use
    // this FileId.  This will get reset later.
    //

    BlFileTable[ *FileId ].Flags.Open = 1;

    //
    // check now if there is any file that upgrades the OFM ROM firmware.
    // the partitions, specified by the FWSearchPath environment variable,
    // are searched for files of the following form in the \eisa\omf
    // subdirectory:
    //                    <device>"V".LF"R"
    //
    //                    <device> = EISA Product ID (7 chars)
    //                         "V" = version  ([0-9],[A-Z])
    //                         "R" = revision ([0-9],[A-Z])
    //

    if  ( (PFwSearchPath = FwGetEnvironmentVariable("FWSearchPath")) != NULL )
    {
        //
        // check all the directories specified by FWSearchPath
        //

        while ( GetNextPath( &PFwSearchPath, OmfPathName ))
        {
            //
            // open the directory
            //

            strcat(OmfPathName, "\\eisa\\omf" );

            if ( FwOpen( OmfPathName, ArcOpenDirectory, &OmfSubdirId ))
            {
                //
                // Go check next path
                //

                continue;
            }

            //
            // Check all files within the directory
            //

            while (!FwGetDirectoryEntry ( OmfSubdirId, &DirEntBuffer,
                                      (ULONG) 1, &Count) )
            {
                //
                // check directory flag, length of file name and file name
                //

                if  ( !( DirEntBuffer.FileAttribute & ArcDirectoryFile )
                        &&
                      DirEntBuffer.FileNameLength
                        &&
                      MaxOmfFatFiles( OmfFatFileName, DirEntBuffer.FileName ))
                {
                    //
                    // correct name, save file path
                    //

                    strcat( strcpy(OmfPathBuffer, OmfPathName), "\\" );
                    strcat(OmfPathBuffer, OmfFatFileName);
                }
            }

            //
            // close directory before opening the next
            //

            FwClose( OmfSubdirId );
        }
    }

    //
    // check for a valid OMF FAT file name
    //

    if ( OmfPathBuffer[0] )
    {
        //
        // open file
        //

        if (FwOpen(OmfPathBuffer, ArcOpenReadOnly, &POmfHeaderContext->FileId))
        {
            //
            // return with error
            //

            BlFileTable[ *FileId ].Flags.Open = 0;
            return ENODEV;
        }

        POmfHeader->FwSize=0;           // max length simulation

        //
        // validate header and copy data in the OmfHeaderContext structure
        //

        if  ( OmfSeek(  *FileId, &Offset, SeekAbsolute )
              ||
              OmfRead(  *FileId,
                        (PVOID)POmfHeader,
                        (ULONG)sizeof(OMF_HDR),
                        &Count)
              ||
              !OmfHeaderValidate( *FileId ) )
        {

            PRINTDBG("No OK\n\r");

            //
            // close file and return with error
            //

            FwClose(POmfHeaderContext->FileId);
            BlFileTable[ *FileId ].Flags.Open = 0;
            return ENODEV;
        }

        //
        // OMF FAT file initialization is done.
        //

        PRINTDBG("It's OK\n\r");

        OmfFatFileOk=TRUE;
    }

    //
    // Reset the open flag.
    //

    BlFileTable[ *FileId ].Flags.Open = 0;

    //
    // if OMF initialization not done, return error
    //

//    if ( !OmfRomOk && !OmfFatFileOk )
    if ( !OmfFatFileOk )
    {
        return ENOENT;
    }
    else
    {
        BlFileTable[ *FileId ].Position.LowPart=0;
        BlFileTable[ *FileId ].Position.HighPart=0;
        return ESUCCESS;
    }
}



// ----------------------------------------------------------------------------
// PROCEDURE:   OmfClose:
//
// DESCRIPTION: The routine closes the file table entry specified by file id.
//              If a OMF FAT file has been used, the routine calls the FwClose
//              function using its file table entry (file id).
//              the routine uses the following logic :
//
//                              if (OMF FAT file)
//                              {
//                                  close file;
//                                  if (error closing file)
//                                      return error;
//                              }
//                              reset open flag;
//                              return ok;
//
// ARGUMENTS:   FileId          Supplies a pointer to a variable that specifies
//                              the file table entry.
//
// RETURN:      ESUCCESS        is returned if the open operation is successful.
//              EBADF           invalid file descriptor
//
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfClose
    (
    IN ULONG FileId
    )
{
    //
    // initialize local variables
    //

    ARC_STATUS Status;                  // store return status from FwClose

    //
    // if OMF FAT file is used, call FwClose using its file table index
    //

    PRINTDBG("OmfClose\n\r");

    if ( BlFileTable[ FileId ].DeviceId != DEVICE_DEVICE)
    {
        return EBADF;
    }

    if  ( BlFileTable[ FileId ].u.OmfHeaderContext.FileId != DEVICE_DEVICE
          &&
          (Status = FwClose( BlFileTable[ FileId ].u.OmfHeaderContext.FileId)))
    {
        return Status;
    }

    //
    // all done, return ok
    //

    BlFileTable[ FileId ].Flags.Open = 0;
    return ESUCCESS;
}



// ----------------------------------------------------------------------------
// PROCEDURE:   OmfMount:
//
// DESCRIPTION: The routine does nothing and return EBADF.
//
// ARGUMENTS:   MountPath       device path specifier.
//              Operation       mount operation (load/unload).
//
// RETURN:      EBADF           invalid operation
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfMount
    (
    IN PCHAR            MountPath,
    IN MOUNT_OPERATION  Operation
    )
{
    //
    // return error :  invalid operation.
    //

    return EBADF;
}




// ----------------------------------------------------------------------------
// PROCEDURE:   OmfRead:
//
// DESCRIPTION: This routine implements the read operation for the ARC-EISA
//              firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies a pointer to a variable that specifies
//                              the file table entry.
//              Buffer          Supplies a pointer to a buffer where the
//                              characters read will be stored.
//              Length          Supplies the length of Buffer.
//              Count           Return the count of the characters that
//                              were read.
//
// RETURN:      ESUCCESS        is returned if the open operation is successful.
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfRead
    (
    IN  ULONG  FileId,
    IN  PVOID  Buffer,
    IN  ULONG  Length,
    OUT PULONG Count
    )
{

    //
    // initialize local variables
    //

    ARC_STATUS  Status;                 // ARC status
    POMF_HEADER_CONTEXT POmfHeaderContext; // OMF header context pointer
    ULONG       OmfSize;                // OMF firmware size (bytes)
    PLARGE_INTEGER PPosition;           // file/device position field pointer
    USHORT      ByteIndex;              // byte index within the word
    ULONG       WordBuffer;             // 1 word buffer


    PRINTDBG("OmfRead\n\r");

    //
    // Initialize some variables
    //

    POmfHeaderContext = &BlFileTable[ FileId ].u.OmfHeaderContext;

    //
    // compute OMF length in bytes
    //

    OmfSize = (ULONG)POmfHeaderContext->OmfHeader.FwSize * OMF_BLOCK_SIZE;

    if ( !OmfSize )
    {
        OmfSize = OMF_MAX_SIZE;
    }

    //
    // initialize byte count read to zero and position variable
    //

    *Count = 0;
    PPosition = &BlFileTable[ FileId ].Position;

    //
    // if length is zero or end of "file", return ESUCCESS.
    //

    if ( !Length  ||  PPosition->LowPart >= OmfSize )
    {
        return ESUCCESS;
    }

    //
    // adjust length if it is too big.
    //

    Length = MIN( Length, OmfSize );    // to prevent the add to overflow

    if ( PPosition->LowPart + Length > OmfSize )
    {
        Length = OmfSize - PPosition->LowPart;
    }

    //
    // if OMF FAT file, read from file.
    //

    if ( POmfHeaderContext->FileId != DEVICE_DEVICE )
    {
        if  ( !(Status = FwSeek( POmfHeaderContext->FileId,
                                  PPosition,
                                  SeekAbsolute ))
              &&
              !(Status = FwRead( POmfHeaderContext->FileId,
                                  Buffer,
                                  Length,
                                  Count )) )
        {
            PPosition->LowPart += *Count;
        }
        return Status;
    }

    //
    //  write word index and compute starting byte index (within a word)
    //

    WRITE_PORT_ULONG(POmfHeaderContext->RomIndex,
		     PPosition->LowPart >> WORD_2P2 );

    //
    // read OMF ROM
    // one loop per word
    //

    while ( Length )
    {
        ByteIndex = (USHORT) (PPosition->LowPart & (1<<WORD_2P2)-1);

        //
        // read the whole word if the buffer and OMF pointers are
        // word aligned.
        //                                                      //       |
        if  ( !ByteIndex                                        // DEBUG V
              &&
              !((USHORT)((PUCHAR)Buffer + *Count) & (1 << WORD_2P2) -1 ) )
        {
            while ( Length >= (1 << WORD_2P2) )
            {
                *((PULONG)( (PUCHAR)Buffer + *Count ))=
                    READ_PORT_ULONG( POmfHeaderContext->RomRead );
                *Count += 1<<WORD_2P2;
                Length -= 1<<WORD_2P2;
            }
        }

        //
        // read the word in bytes units if the buffer or the OMF pointers
        // are not word aligned or if just part of the word is needed.
        //

        if ( Length )
        {
            WordBuffer = READ_PORT_ULONG( POmfHeaderContext->RomRead );

            //
            // read just the selected bytes
            //

            while ( ByteIndex < (1 << WORD_2P2)  &&  Length-- )
            {
                *( (PUCHAR)Buffer + *Count++ )=
                  (UCHAR)( WordBuffer >> BITSXBYTE * ByteIndex++ );
            }
        }

        //
        // update OMF pointer
        //

        PPosition->LowPart += *Count;
    }

    //
    // return all done
    //

    return ESUCCESS;
}



// ----------------------------------------------------------------------------
// PROCEDURE:   OmfWrite:
//
// DESCRIPTION: This routine implements the write operation for the ARC-EISA
//              firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies a pointer to a variable that specifies
//                              the file table entry.
//              Buffer          Supplies a pointer to a buffer where the
//                              characters are read.
//              Length          Supplies the length of Buffer.
//              Count           Return the count of the characters that
//                              were written.
//
// RETURN:      EBADF           invalid operation
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfWrite
    (
    IN  ULONG  FileId,
    IN  PVOID  Buffer,
    IN  ULONG  Length,
    OUT PULONG Count
    )
{
    //
    // return error : invalid operation
    //

    return EBADF;
}



// ----------------------------------------------------------------------------
// PROCEDURE:   OmfGetReadStatus:
//
// DESCRIPTION: This routine implements the GetReadStatus operation for the
//              ARC-EISA firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies a pointer to a variable that specifies
//                              the file table entry.
//
// RETURN:      ESUCCESS        return always success.
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfGetReadStatus
    (
    IN ULONG FileId
    )
{
    //
    // return ok
    //

    return ESUCCESS;
}



// ----------------------------------------------------------------------------
// PROCEDURE:   OmfSeek:
//
// DESCRIPTION: This routine implements the Seek operation for the
//              ARC-EISA firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies a pointer to a variable that specifies
//                              the file table entry.
//              Offset          Supplies the offset in the file to position to.
//              SeekMode        Supplies the mode of the seek operation
//
// RETURN:      ESUCCESS        returned if the operation is successful.
//              EINVAL          returned otherwise.
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfSeek
    (
    IN ULONG            FileId,
    IN PLARGE_INTEGER   Offset,
    IN SEEK_MODE        SeekMode
    )
{
    //
    // local variables
    //

    LARGE_INTEGER       Point;                  // New position
    ULONG               OmfSize;                // OMF size in bytes

    PRINTDBG("OmfSeek\n\r");

    //
    // initialize some variables
    //

    OmfSize = (ULONG)BlFileTable[ FileId ].u.OmfHeaderContext.OmfHeader.FwSize *
                   OMF_BLOCK_SIZE;

    if ( !OmfSize )
    {
        OmfSize=OMF_MAX_SIZE;
    }

    //
    // compute new offset value
    //

    switch( SeekMode )
    {
        case SeekAbsolute:
            Point = *Offset;
            break;
        case SeekRelative:
            Point = RtlLargeIntegerAdd( BlFileTable[FileId].Position, *Offset );
            break;
        default:
            return EINVAL;
    }

    //
    // if the high 32 bits are not zero, return an error.
    // if new offset is valid, update position field.
    // if the position value 0-based is equal to the OMF size (1-based),
    // the EOF has been reached.  no error is returned in this case and
    // the count field is set to zero with ESUCCESS error code for any
    // successive read operation.  note that this combination (ESUCCESS and
    // count=0) is used to rappresent EOF (end of file).
    //

    if  ( Point.HighPart  ||  Point.LowPart > OmfSize )
    {
        return EINVAL;
    }
    else
    {
        BlFileTable[FileId].Position = Point;
        return ESUCCESS;
    }
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfGetFileInformation:
//
// DESCRIPTION: This routine implements the GetFileInformation for the
//              ARC-EISA firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies the file table index.
//              Buffer          Supplies the buffer to receive the file
//                              information.  Note that it must be large
//                              enough to hold the full file name.
//
// RETURN:      EBADF           invalid operation
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfGetFileInformation
    (
    IN  ULONG FileId,
    OUT PFILE_INFORMATION Buffer
    )
{
    //
    // return error :  invalid operation
    //

    return EBADF;
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfSetFileInformation:
//
// DESCRIPTION: This routine implements the SetFileInformation for the
//              ARC-EISA firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies the file table index.
//              AttributeFlags  Supplies the value (on or off) for each
//                              attribute being modified.
//              AttributeMask   Supplies a mask of the attributes being altered.
//                              All other file attributes are left alone.
//
// RETURN:      EBADF           invalid operation
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfSetFileInformation
    (
    IN ULONG FileId,
    IN ULONG AttributeFlags,
    IN ULONG AttributeMask
    )
{
    //
    // return error :  invalid operation
    //

    return EBADF;
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfGetDirectoryEntry:
//
// DESCRIPTION: This routine implements the GetDirectoryEntry for the
//              ARC-EISA firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies the file table index.
//              DirEntry        Pointer to a directory entry structure
//              NumberDir       # of entries to read
//              Count           # of entries read
//
// RETURN:      EBADF           directory operations are not supported
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfGetDirectoryEntry
    (
    IN  ULONG           FileId,
    IN  DIRECTORY_ENTRY *DirEntry,
    IN  ULONG           NumberDir,
    OUT PULONG          CountDir
    )
{
    //
    // return error :  directory operations are not supported
    //

    return EBADF;
}




// ----------------------------------------------------------------------------
// PROCEDURE:   OmfFileOpen:
//
// DESCRIPTION: The routine opens the OMF file.
//              The <extension> of the <filename> is optional. The caller can
//              make the following assumptions if the <extension> is not
//              included in the <filename> :
//              . the firmware searches for folders whose type is MIPS first.
//                This is equivalent to using '.A' as the <extension>. If
//                the requested folder of this type is found in the most recent
//                OMF, then this folder is used.
//              . If the modst recent OMF does not contain the requested folder
//                whose type is MIPS, then the SMF searches for the requested
//                folder whose type is BINARY.  This is equivalent to using '.B'
//                as the <extension>.  If the requested folder of this type is
//                found in the most recent OMF then this folder is used.
//              . If there are no folders with either type in the most recent
//                OMF, the operation fails.
//
//              When omf() is used as <protocol spec> and the filename is the
//              string "\", the path specification represents the OMF directory.
//              The only valid operation to perform on the OMF directory is to
//              Open it, then use FwGetDirectoryEntry to enumerate the folders
//              within the OMF, and then Close it.  For example, to
//              enumerate all folders that are containded in the OMF of a
//              serail options board that was in slot 3 of EISA bus0, create
//              and Open a path as follows :    eisa(0)serial(3)omf()\ .
//              To open the diagnostic folder for the above EISA option board
//              the system utilty would create and Open the path specification :
//              eisa(0)serial(3)omf()\T-SERIAL.
//
//
// ARGUMENTS:   OpenPath        Supplies a pointer to a zero terminated OMF
//                              file name.
//              OpenMode        Supplies the mode of the open.
//              FileId          Supplies the file table entry index
//
// RETURN:      ESUCCESS        is returned if the open operation is successful.
//              ENOENT          the named device or file does not exist.
//
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfFileOpen
    (
    IN PCHAR      OpenPath,
    IN OPEN_MODE  OpenMode,
    IN OUT PULONG FileId
    )
{
    //
    // initialize local variables
    //

    ARC_STATUS      Status;                     // ARC status
    ULONG           DeviceId;                   // device table entry index
    POMF_DIR_ENT    POmfDirEnt;                 // OMF directory entry pointer
    POMF_HDR        POmfHeader;                 // OMF header pointer
    LARGE_INTEGER   AbsolutePosition;           // position
    ULONG           TypeIndex,DirIndex;         // general indexes
    ULONG           Count;                      // # of bytes transferred
    CHAR            OmfFileName[OMF_FILE_NAME_LEN]; // folder name
    BOOLEAN         SearchSucceeded = FALSE;    // match flag
    BOOLEAN         IsDirectory     = FALSE;    // directory flag
    CHAR OmfType[] = {'A','B','\0'};            // default sequance of search:
                                                // relocatable MIPS I object
                                                // format binary data format
                                                // end of chain

    PRINTDBG("OmfFileOpen\n\r");                // debug support

    //
    // Initialize some variables
    //

    DeviceId    = BlFileTable[ *FileId ].DeviceId;
    POmfDirEnt  = &BlFileTable[ *FileId ].u.OmfFileContext.OmfDirEnt;
    POmfHeader  = &BlFileTable[ DeviceId ].u.OmfHeaderContext.OmfHeader;
    AbsolutePosition.HighPart=0;                // for seek operations

    //
    // initialize the file/directory pointer to zero
    //

    BlFileTable[ *FileId ].Position.LowPart=0;
    BlFileTable[ *FileId ].Position.HighPart=0;

    //
    // the first char must be the directory char, otherwise it's an error
    //

    if ( *OpenPath++ != '\\' );

    //
    // else check if the open is for the root directory
    //

    else if ( *OpenPath == '\0' )
    {
        POmfDirEnt->FolderName[0]='\0';
        SearchSucceeded = TRUE;
        IsDirectory     = TRUE;
    }

    //
    // else validate OMF file name
    //

    else if ( !OmfFileNameValidate( OpenPath, OmfFileName, OmfType ));

    //
    // then search the specified file name
    //

    else
    {
        //
        // save the omf file name
        //

        strcpy( BlFileTable[ *FileId ].FileName, OpenPath );
        BlFileTable[ *FileId ].FileNameLength = strlen( OpenPath );

        //
        // one loop per file
        //

        for (TypeIndex = 0; !SearchSucceeded && OmfType[TypeIndex]; TypeIndex++)
        {
            //
            // search the directory for the specified OMF file name
            //

            for ( DirIndex = 0, AbsolutePosition.LowPart =
                                POmfHeader->FolderDirectoryLink << WORD_2P2;

                  DirIndex < POmfHeader->FolderCount && !SearchSucceeded;

                  DirIndex++, AbsolutePosition.LowPart += sizeof(OMF_DIR_ENT) )
            {
                //
                // exit if error during seek or read.
                //

                if  ((Status = FwSeek(DeviceId, &AbsolutePosition, SeekAbsolute))
                     ||
                     (Status = FwRead(DeviceId,
                                      (PVOID)POmfDirEnt,
                                      (ULONG)sizeof(OMF_DIR_ENT),
                                      &Count )))
                {
                    return Status;
                }

                //
                // check OMF file name
                //

                SearchSucceeded = CmpOmfFiles(  OmfFileName,
                                                OmfType[TypeIndex],
                                                (PVOID)POmfDirEnt );
            }
        }

        //
        // if the search has been successful, validate file's header
        //

        if (SearchSucceeded && !OmfFileValidate( *FileId ))
        {
            SearchSucceeded = FALSE;
        }
    }

    //
    //  At this point we've cracked the name up to (an maybe including the last
    //  component).  We located the last component if the SearchSucceeded flag
    //  is true, otherwise the last component does not exist.  If we located
    //  the last component then this is like an open or a supersede, but not a
    //  create.
    //

    if (SearchSucceeded)
    {
        //
        //  Check if the last component is a directory
        //

        if (IsDirectory)
        {
            //
            //  For an existing directory the only valid open mode is
            //  OpenDirectory all other modes return an error
            //

            switch (OpenMode)
            {

                case ArcOpenReadOnly:
                case ArcOpenWriteOnly:
                case ArcOpenReadWrite:
                case ArcCreateWriteOnly:
                case ArcCreateReadWrite:
                case ArcSupersedeWriteOnly:
                case ArcSupersedeReadWrite:

                    //
                    // if we reach here then the caller got a directory but
                    // didn't want to open a directory
                    //

                    return EISDIR;

                case ArcOpenDirectory:

                    //
                    // if we reach here then the caller got a directory and
                    // wanted to open a directory.
                    //

                    BlFileTable[ *FileId ].Flags.Open = 1;
                    BlFileTable[ *FileId ].Flags.Read = 1;

                    return ESUCCESS;

                case ArcCreateDirectory:

                    //
                    // if we reach here then the caller got a directory and
                    // wanted to create a new directory
                    //

                    return EACCES;

                default:

                    //
                    // invalid open mode
                    //

                    return EINVAL;
            }
        }

        //
        //  If we get there then we have an existing file that is being opened.
        //  We can open existing files only read only.
        //

        switch (OpenMode)
        {
            case ArcOpenReadOnly:

                //
                // if we reach here then the user got a file and wanted to
                // open the file read only
                //

                BlFileTable[ *FileId ].Flags.Open = 1;
                BlFileTable[ *FileId ].Flags.Read = 1;

                return ESUCCESS;

            case ArcOpenWriteOnly:
            case ArcOpenReadWrite:
            case ArcCreateWriteOnly:
            case ArcCreateReadWrite:
            case ArcSupersedeWriteOnly:
            case ArcSupersedeReadWrite:

                //
                // if we reach here then we are trying to open a read only
                // device for write.
                //

                return EROFS;

            case ArcOpenDirectory:
            case ArcCreateDirectory:

                //
                // if we reach here then the user got a file and wanted a
                // directory
                //

                return ENOTDIR;

            default:

                //
                // invalid open mode
                //

                return EINVAL;
        }
    }

    //
    //  If we get here the last component does not exist so we are trying to
    //  create either a new file or a directory.
    //

    switch (OpenMode)
    {
        case ArcOpenReadOnly:
        case ArcOpenWriteOnly:
        case ArcOpenReadWrite:
        case ArcOpenDirectory:

            //
            // if we reach here then the user did not get a file but wanted
            // a file
            //

            return ENOENT;

        case ArcCreateWriteOnly:
        case ArcSupersedeWriteOnly:
        case ArcCreateReadWrite:
        case ArcSupersedeReadWrite:
        case ArcCreateDirectory:

            //
            // if we get hre the user wants to create something.
            //

            return EROFS;

        default:

            //
            // invalid open mode
            //

            return EINVAL;
    }
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfFileClose:
//
// DESCRIPTION: The routine closes the file table entry specified by file id.
//
// ARGUMENTS:   FileId          Supplies the file table index.
//
// RETURN:      ESUCCESS        is returned if the open operation is successful.
//
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfFileClose
    (
    IN ULONG FileId
    )
{
    PRINTDBG("OmfFileClose\n\r");

    //
    // clear flag and exit
    //

    BlFileTable[FileId].Flags.Open = 0;
    return ESUCCESS;
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfFileMount:
//
// DESCRIPTION: The routine does nothing and return EBADF.
//
// ARGUMENTS:   MountPath       device path specifier.
//              Operation       mount operation (load/unload).
//
// RETURN:      EBADF           invalid operation
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfFileMount
    (
    IN PCHAR            MountPath,
    IN MOUNT_OPERATION  Operation
    )
{
    //
    // return error :  invalid operation.
    //

    return EBADF;
}






// ----------------------------------------------------------------------------
// PROCEDURE:   OmfFileGetReadStatus
//
// DESCRIPTION: This routine implements the GetReadStatus operation for the
//              ARC-EISA firmware OMF file.
//
// ARGUMENTS:   FileId          Supplies a pointer to a variable that specifies
//                              the file table entry.
//
// RETURN:      ESUCCESS        return always success.
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfFileGetReadStatus
    (
    IN ULONG FileId
    )
{
    //
    // return ok
    //

    return ESUCCESS;
}






// ----------------------------------------------------------------------------
// PROCEDURE:   OmfFileRead:
//
// DESCRIPTION: This routine implements the read operation for the ARC-EISA
//              firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies the file table index.
//              Buffer          Supplies a pointer to a buffer where the
//                              characters read will be stored.
//              Length          Supplies the length of Buffer.
//              Count           Return the count of the characters that
//                              were read.
//
// RETURN:      ESUCCESS        is returned if the open operation is successful.
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfFileRead
    (
    IN  ULONG  FileId,
    IN  PVOID  Buffer,
    IN  ULONG  Length,
    OUT PULONG Count
    )
{

    //
    // initialize local variables
    //
    ARC_STATUS    Status;                       // ARC status
    POMF_DIR_ENT  POmfDirEnt;                   // OMF directory entry pointer
    LARGE_INTEGER AbsolutePosition;             // OMF file, logical pointer
    ULONG         OmfFileSize;                  // OMF file size in bytes

    PRINTDBG("OmfFileRead\n\r");

    //
    // initialize some variables
    //

    POmfDirEnt = &BlFileTable[ FileId ].u.OmfFileContext.OmfDirEnt;

    //
    // if directory entry, exit with error
    //

    if ( !POmfDirEnt->FolderName[0] )
    {
        return EBADF;                   // check this error code "EGI_Q"
    }

    //
    // initialize byte count read to zero
    //

    *Count=0;
    OmfFileSize = POmfDirEnt->FolderSize << WORD_2P2;

    //
    // if length is zero or EOF (end of file), return ESUCCESS.
    //

    if (!Length || BlFileTable[FileId].Position.LowPart >= OmfFileSize)
    {
        return ESUCCESS;
    }

    //
    // adjust length if it is too big.
    //

    Length = MIN( Length, OmfFileSize ); // to prevent the add to overflow

    if ( BlFileTable[ FileId ].Position.LowPart + Length > OmfFileSize )
    {
        Length = OmfFileSize - BlFileTable[ FileId ].Position.LowPart;
    }

    //
    // find OMF absolute offset from OMF file absolute offset
    //

    AbsolutePosition.HighPart = 0;
    AbsolutePosition.LowPart = BlFileTable[ FileId ].Position.LowPart +
                                ( POmfDirEnt->FolderLink << WORD_2P2 );

    //
    // seek + read command
    //

    if  ( (Status = FwSeek( BlFileTable[ FileId ].DeviceId,
                             &AbsolutePosition,
                             SeekAbsolute ))
          ||
          (Status = FwRead( BlFileTable[FileId].DeviceId,
                             Buffer,
                             Length,
                             Count )) )
    {
        return Status;
    }

    //
    // update file pointer and exit
    //

    BlFileTable[FileId].Position.LowPart += *Count;
    return ESUCCESS;
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfFileWrite:
//
// DESCRIPTION: This routine implements the write operation for the ARC-EISA
//              firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies the file table index.
//              Buffer          Supplies a pointer to a buffer where the
//                              characters are read.
//              Length          Supplies the length of Buffer.
//              Count           Return the count of the characters that
//                              were written.
//
// RETURN:      EBADF           invalid operation
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfFileWrite
    (
    IN ULONG FileId,
    IN PVOID Buffer,
    IN ULONG Length,
    OUT PULONG Count
    )
{
    //
    // return error :  invalid operation
    //

    return EBADF;
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfFileSeek:
//
// DESCRIPTION: This routine implements the Seek operation for the
//              ARC-EISA firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies the file table index.
//              Offset          Supplies the offset in the file to position to.
//              SeekMode        Supplies the mode of the seek operation
//
// RETURN:      ESUCCESS        returned if the operation is successful.
//              EINVAL          returned otherwise.
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfFileSeek
    (
    IN ULONG FileId,
    IN PLARGE_INTEGER Offset,
    IN SEEK_MODE SeekMode
    )
{
    //
    // local variables
    //

    LARGE_INTEGER       Point;                  // New position
    POMF_DIR_ENT        POmfDirEnt;             // OMF directory entry pointer

    PRINTDBG("OmfFileSeek\n\r");

    //
    // initialize some variables
    //

    POmfDirEnt = &BlFileTable[ FileId ].u.OmfFileContext.OmfDirEnt;

    //
    // The offset parameter must be zero, if directory entry.
    //

    if  ( !POmfDirEnt->FolderName[0] && ( Offset->LowPart || Offset->HighPart ))
    {
        return EINVAL;
    }

    //
    // compute new offset value
    //

    switch(SeekMode)
    {
        case SeekAbsolute:
            Point = *Offset;
            break;
        case SeekRelative:
            Point = RtlLargeIntegerAdd( BlFileTable[FileId].Position, *Offset );
            break;
        default:
            return EINVAL;
    }

    //
    // if new offset is valid, update position field.
    // if the position value 0-based is equal to the OMF size (1-based),
    // the EOF has been reached.  no error is returned in this case and
    // the count field is set to zero with ESUCCESS error code for any
    // successive read operation.  note that this combination (ESUCCESS and
    // count=0) is used to rappresent EOF (end of file).
    //

    if ( POmfDirEnt->FolderName[0] &&
        (Point.HighPart || Point.LowPart > POmfDirEnt->FolderSize << WORD_2P2))
    {
        return EINVAL;
    }
    else
    {
        BlFileTable[ FileId ].Position = Point;
        return ESUCCESS;
    }
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfFileGetFileInformation:
//
// DESCRIPTION: This routine implements the GetFileInformation for the
//              ARC-EISA firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies the file table index.
//              Buffer          Supplies the buffer to receive the file
//                              information.  Note that it must be large
//                              enough to hold the full file name.
//
// RETURN:      EBADF           invalid operation
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfFileGetFileInformation
    (
    IN  ULONG FileId,
    OUT PFILE_INFORMATION Buffer
    )
{
    //
    // define local variable
    //

    PBL_FILE_TABLE FileTableEntry = &BlFileTable[ FileId ];

    PRINTDBG("OmfFileGetFileInformation\n\r");

    //
    // if root, exit with error
    //

    if ( !FileTableEntry->u.OmfFileContext.OmfDirEnt.FolderName[0] )
    {
        return EBADF;
    }

    //
    // set output fields
    //

    RtlZeroMemory(Buffer, sizeof(FILE_INFORMATION));

    //
    // ending address (high part is already zero) and current address
    //

    Buffer->EndingAddress.LowPart    =
        FileTableEntry->u.OmfFileContext.OmfDirEnt.FolderSize << WORD_2P2;
    Buffer->CurrentPosition.LowPart  = FileTableEntry->Position.LowPart;
    Buffer->CurrentPosition.HighPart = FileTableEntry->Position.HighPart;

    //
    // device type
    //

    Buffer->Type = OtherPeripheral;

    //
    // file name length, attributes and file name string
    //

    Buffer->FileNameLength = FileTableEntry->FileNameLength;
    Buffer->Attributes = ArcReadOnlyFile;
    strcpy( Buffer->FileName, FileTableEntry->FileName );

    //
    // all done
    //

    return ESUCCESS;
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfFileSetFileInformation:
//
// DESCRIPTION: This routine implements the SetFileInformation for the
//              ARC-EISA firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies the file table index.
//              AttributeFlags  Supplies the value (on or off) for each
//                              attribute being modified.
//              AttributeMask   Supplies a mask of the attributes being altered.
//                              All other file attributes are left alone.
//
// RETURN:      EBADF           invalid operation
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfFileSetFileInformation
    (
    IN ULONG FileId,
    IN ULONG AttributeFlags,
    IN ULONG AttributeMask
    )
{
    //
    // return error :  invalid operation
    //

    return EROFS;
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfFileGetDirectoryEntry:
//
// DESCRIPTION: This routine implements the GetDirectoryEntry for the
//              ARC-EISA firmware "OMF" driver.
//
// ARGUMENTS:   FileId          Supplies the file table index.
//              DirEntry        Pointer to a directory entry structure
//              NumberDir       # of entries to read
//              Count           # of entries read
//
// RETURN:      ESUCCESS        returned if the operation is successful.
//              EINVAL          returned otherwise.
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

ARC_STATUS
OmfFileGetDirectoryEntry
    (
    IN  ULONG           FileId,
    IN  DIRECTORY_ENTRY *DirEntry,
    IN  ULONG           NumberDir,
    OUT PULONG          CountDir
    )
{
    //
    // initialize local variables
    //

    ARC_STATUS  Status;                 // ARC status
    ULONG       DeviceId;               // file table entry for the device
    POMF_HDR    POmfHeader;             // pointer to OMF ROM/FAT file header
    ULONG       CurrentDir;             // current directory entry
    LARGE_INTEGER AbsolutePosition;     // OMF file, pointer of logical pointer
    OMF_DIR_ENT OmfFileBuffer;          // buffer for directory entries
    ULONG       Count;                  // # of bytes read

    PRINTDBG("OmfFileGetDirectoryEntry\n\r");

    //
    // if not directory entry, exit with error
    //

    if ( BlFileTable[ FileId ].u.OmfFileContext.OmfDirEnt.FolderName[0] )
    {
        return EBADF;
    }

    //
    // Initialize the output count to zero
    //

    *CountDir=0;

    //
    // if NumberDir is zero, return ESUCCESS.
    //

    if ( !NumberDir )
    {
        return ESUCCESS;
    }

    //
    // initialize variables
    //

    Count=0;
    DeviceId   = BlFileTable[ FileId ].DeviceId;
    POmfHeader = &BlFileTable[ DeviceId ].u.OmfHeaderContext.OmfHeader;
    CurrentDir = BlFileTable[ FileId ].Position.LowPart/sizeof(OMF_DIR_ENT);

    //
    // if no more entries, return ENOTDIR
    //

    if ( CurrentDir >= POmfHeader->FolderCount )
    {
        return ENOTDIR;
    }

    //
    // adjust count if it is too big.
    //

    NumberDir = MIN( NumberDir, POmfHeader->FolderCount );  //avoid add overflow

    if ( CurrentDir + NumberDir > POmfHeader->FolderCount )
    {
        NumberDir = POmfHeader->FolderCount - CurrentDir;
    }

    //
    // find OMF absolute offset from OMF file absolute offset
    //

    AbsolutePosition.HighPart = 0;
    AbsolutePosition.LowPart = BlFileTable[FileId].Position.LowPart +
                                (POmfHeader->FolderDirectoryLink<<WORD_2P2);

    //
    // seek command
    //

    if ( Status = FwSeek( DeviceId, &AbsolutePosition, SeekAbsolute ))
    {
        return Status;
    }

    //
    // read command
    //

    while( NumberDir-- )
    {
        //
        // read one directory entry
        //

        if  ( Status = FwRead( DeviceId,
                                &OmfFileBuffer,
                                (ULONG)sizeof(OMF_DIR_ENT),
                                &Count ))
        {
            return Status;
        }

        //
        // if bytes read are not sizeof(OMF_DIR_ENT), return error
        //

        if ( Count != sizeof(OMF_DIR_ENT) )
        {
            return EBADF;
        }

        //
        // convert OMF directory entry in ARC directory entry
        //

        ConvertOmfDirToArcDir( &OmfFileBuffer, DirEntry++ );
        ++*CountDir;
    }

    //
    // update file pointer and exit
    //

    BlFileTable[FileId].Position.LowPart += *CountDir * sizeof(OMF_DIR_ENT);
    return ESUCCESS;
}





// ----------------------------------------------------------------------------
// PROCEDURE:   MaxOmfFatFiles:
//
// DESCRIPTION: The routine returns the most updated file name for the
//              specified product Id.
//              A FALSE is returned if the OMF FAT file name has not been
//              modified.
//
// ARGUMENTS:   MasterName      name used as base
//              CheckedName     name checked
//
// RETURN:      TRUE            is returned if the OMF FAT file name has been
//                              modified.
//              FALSE           is returned in all the other cases.
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

BOOLEAN
MaxOmfFatFiles
    (
    IN OUT PCHAR MasterName,
    IN PCHAR CheckedName
    )
{
    //
    // Define variables
    //

    CHAR MasterVersion, MasterRevision;         // master name
    CHAR CheckedVersion, CheckedRevision;       // checked name
    POMF_FAT_FILE_NAME PointerMaster;           // master name pointer
    POMF_FAT_FILE_NAME PointerChecked;          // checked name pointer

    PRINTDBG("MaxOmfFatFiles\n\r");

    //
    // save version and revision master values
    //

    PointerMaster   = (POMF_FAT_FILE_NAME)MasterName;
    MasterVersion   = PointerMaster->Version;
    MasterRevision  = PointerMaster->Revision;

    //
    // save version and revision checked values
    //

    PointerChecked  = (POMF_FAT_FILE_NAME)CheckedName;
    CheckedVersion  = PointerChecked->Version;
    CheckedRevision = PointerChecked->Revision;
    PointerChecked->Version  = MasterVersion;
    PointerChecked->Revision = MasterRevision;

    //
    // update name if new version for the same product Id
    //

    if  (strcmp(MasterName, CheckedName)
         ||
         CheckedVersion<MasterVersion
         ||
         (CheckedVersion == MasterVersion && CheckedRevision <= MasterRevision))
    {
        return FALSE;
    }
    else
    {
        PointerMaster->Version  = CheckedVersion;
        PointerMaster->Revision = CheckedRevision;
        return TRUE;
    }
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfFileNameValidate:
//
// DESCRIPTION: The routine validates the requested OMF file name.
//              The name is decomposed in Folder Name and Folder Type.
//
// ARGUMENTS:   OpenPath        Supplies a pointer to a zero terminated OMF
//                              file name.
//              OmfFileName     Supplies a pointer to an array used to store
//                              the Folder Name.
//              OmfType         Supplies a pointer to an array used to store
//                              the Folder Types.
//
// RETURN:      TRUE            is returned if the operation succeed.
//              FALSE           is returned if the OpenPath is incorrect.
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

BOOLEAN
OmfFileNameValidate
    (
    IN  PCHAR OpenPath,
    OUT PCHAR OmfFileName,
    OUT PCHAR OmfType
    )

{
    //
    // Define variables
    //

    ULONG NameIndex;                    // general index

    PRINTDBG("OmfFileNameValidate\n\r");

    //
    // name validation
    //

    for ( NameIndex = 0;
          NameIndex < OMF_FILE_NAME_LEN  &&  *OpenPath  &&  *OpenPath != '.';
          NameIndex++ )
    {
        if  (
            isupper( *OpenPath )                // upper case letter
            ||
            isdigit( *OpenPath )                // digit
            ||
            *OpenPath=='-'                      // '-' minus
            ||
            (*OpenPath=='$' && NameIndex==0)    // $ char in 1st position
            )
        {
            *OmfFileName++=*OpenPath++;
        }
        else
        {
            return FALSE;
        }
    }

    //
    // return error if name length > of OMF_FILE_NAME_LEN
    //

    if ( NameIndex == OMF_FILE_NAME_LEN  &&  *OpenPath  &&  *OpenPath != '.')
    {
        return FALSE;
    }

    //
    // fill right with null chars ('\0') if Folder Name is less than 12 chars
    //

    while( NameIndex++ < OMF_FILE_NAME_LEN )
    {
        *OmfFileName++='\0';
    }

    //
    // extension validation
    //

    if ( *OpenPath++ && *OpenPath )             // skip "null", ".null"
    {
        switch( *OpenPath )                     // check type field
        {
            case 'A':
            case 'B':
                *OmfType++ = *OpenPath++;
                *OmfType   = '\0';              // means : end of types
                break;
            default:
                return FALSE;
        }
        if( *OpenPath )                         // error if more chars
        {
            return FALSE;
        }
    }

    //
    // all done, return ok
    //

    return TRUE;
}




// ----------------------------------------------------------------------------
// PROCEDURE:   CmpOmfFiles:
//
// DESCRIPTION: The routine checks if the selected directory entry has the
//              requested OMF file name.
//
// ARGUMENTS:   OmfFileName     Requested OMF file name pointer.
//              OmfType         Requested OMF file type pointer.
//              POmfDirEnt      Directory entry to check.
//
// RETURN:      TRUE            is returned if the operation succeed.
//              FALSE           is returned if the name or type doesn't match.
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

BOOLEAN
CmpOmfFiles
    (
    IN PCHAR OmfFileName,
    IN CHAR OmfType,
    IN POMF_DIR_ENT POmfDirEnt
    )
{
    //
    // Define variables
    //

    ULONG NameIndex;                    // general index

    PRINTDBG("CmpOmfFiles\n\r");

    //
    // check name
    //

    for ( NameIndex=0; NameIndex < OMF_FILE_NAME_LEN; NameIndex++ )
    {
        if ( OmfFileName[ NameIndex ] != POmfDirEnt->FolderName[ NameIndex ] )
        {
            return FALSE;
        }
    }

    //
    // check extension
    //

    if ( OmfType != POmfDirEnt->FolderType )
    {
        return FALSE;
    }

    //
    // all done, return ok
    //

    return TRUE;
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfHeaderValidate:
//
// DESCRIPTION: The routine checks if the specified OMF header data is valid.
//
// ARGUMENTS:   FileId          file table entry index
//
// RETURN:      TRUE            is returned if file is ok.
//              FALSE           is returned if file is not correct.
//
// ASSUMPTIONS: The header data has already been copied in the
//              context data of the file table entry.
//              The size of all the OMF structures is a multiple of a word.
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

BOOLEAN
OmfHeaderValidate
    (
    IN ULONG FileId
    )
{
    //
    // local variables
    //

    POMF_HDR POmfHeader;                // pointer to the header data
    ULONG OmfDirLink;                   // directory link in words
    ULONG OmfDirLength;                 // directory size in words
    ULONG OmfSize;                      // OMF size in bytes
    UCHAR Checksum=0;                   // used to compute the checksum

    PRINTDBG("OmfHeaderValidate\n\r");

    //
    // initialize variables
    //

    POmfHeader   = &BlFileTable[FileId].u.OmfHeaderContext.OmfHeader;
    OmfDirLink   = POmfHeader->FolderDirectoryLink;

    OmfDirLength =(POmfHeader->FolderCount * sizeof(OMF_DIR_ENT))/(1<<WORD_2P2);
    OmfSize      = (ULONG)POmfHeader->FwSize * OMF_BLOCK_SIZE;
    if (!OmfSize)
    {
        OmfSize = OMF_MAX_SIZE;
    }

    //
    // check header values
    //

    if  ( POmfHeader->ID[0] != OMF_ID_1ST
          ||
          POmfHeader->ID[1] != OMF_ID_2ND
          ||
          POmfHeader->ID[2] != OMF_ID_3RD
          ||
          POmfHeader->ID[3] != OMF_ID_4TH
          ||
          !isalnum(POmfHeader->FwVersion)
          ||
          !isalnum(POmfHeader->FwRevision)
          ||
          sizeof(OMF_HDR) > OmfSize
          ||
          OmfDirLink + OmfDirLength > OmfSize/(1<<WORD_2P2)
          ||
          FwFileIdChecksum( FileId,
                            RtlConvertUlongToLargeInteger(0l),
                            (ULONG)(sizeof(OMF_HDR)),
                            &Checksum )
          ||
          FwFileIdChecksum( FileId,
                            RtlConvertUlongToLargeInteger(OmfDirLink<<WORD_2P2),
                            OmfDirLength << WORD_2P2,
                            &Checksum )
// >>> FIXME <<<
//        ||
//        Checksum
        )
    {
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}





// ----------------------------------------------------------------------------
// PROCEDURE:   OmfFileValidate:
//
// DESCRIPTION: The routine checks if the selected file is valid.
//
// ARGUMENTS:   FileId          file table entry index
//
// RETURN:      TRUE            is returned if file is ok.
//              FALSE           is returned if file is not correct.
//
// ASSUMPTIONS: the folder name and its extension (type) have already
//              been validated.
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

BOOLEAN
OmfFileValidate
    (
    IN ULONG FileId
    )
{
    //
    // local variables
    //

    POMF_DIR_ENT POmfDirEnt;            // OMF directory entry pointer
    ULONG OmfFileLength;                // file length, word count
    ULONG OmfFileLink;                  // file link, word count
    ULONG DeviceId;                     // device id file table entry
    ULONG OmfLength;                    // OMF rom length, word count
    UCHAR Checksum=0;                   // used to compute the checksum

    PRINTDBG("OmfFileValidate\n\r");

    //
    // initialize variables
    //

    POmfDirEnt    = &BlFileTable[FileId].u.OmfFileContext.OmfDirEnt;
    OmfFileLink   = POmfDirEnt->FolderLink;
    OmfFileLength = POmfDirEnt->FolderSize;
    DeviceId      = BlFileTable[FileId].DeviceId;
    OmfLength=(ULONG)BlFileTable[DeviceId].u.OmfHeaderContext.OmfHeader.FwSize *
                 OMF_BLOCK_SIZE/(1<<WORD_2P2);
    if (!OmfLength)
    {
        OmfLength = OMF_MAX_SIZE/(1<<WORD_2P2);
    }

    //
    // validate file
    //

    if  ( OmfFileLink > OMF_MAX_FILE_LINK
          ||
          OmfFileLength > OMF_MAX_FILE_LEN
          ||
          OmfFileLink + OmfFileLength > OmfLength
          ||
          FwFileIdChecksum( DeviceId,
                            RtlConvertUlongToLargeInteger(OmfFileLink<<WORD_2P2),
                            OmfFileLength << WORD_2P2,
                            &Checksum )
// >>> FIXME <<<
//        ||
//        (Checksum += POmfDirEnt->FolderChecksumByte)
        )
    {
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}




// ----------------------------------------------------------------------------
// PROCEDURE:   ConvertOmfDirToArcDir:
//
// DESCRIPTION: The routine converts the OMF directory entry in the ARC
//              directory entry format.
//
// ARGUMENTS:   OmfFileBuffer   pointer to OMF directory entry
//              DirEntry        pointer to ARC directory entry to be filled
//
// RETURN:      NONE
//
// ASSUMPTIONS: FileNameLengthMax is at least 3 chars.
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

VOID
ConvertOmfDirToArcDir
    (
    IN  POMF_DIR_ENT    POmfDirEnt,
    OUT DIRECTORY_ENTRY *PArcDirEnt
    )
{
    //
    // local variables
    //

    ULONG CharIndex;                            // name+extension length
    ULONG MaxFileName;                          // max name length

    PRINTDBG("ConvertOmfDirToArcDir\n\r");

    //
    // set attribute bit (read only file)
    //

    PArcDirEnt->FileAttribute = ArcReadOnlyFile;

    //
    // set file name (note that 3 means: '.' + extension + '\0' )
    //

    MaxFileName = MIN( 32 - 3, OMF_FILE_NAME_LEN );

    for ( CharIndex = 0;
          CharIndex < MaxFileName && POmfDirEnt->FolderName[ CharIndex ];
          CharIndex++ )
    {
         PArcDirEnt->FileName[ CharIndex ] = POmfDirEnt->FolderName[ CharIndex];
    }

    //
    // dot '.'
    //

    PArcDirEnt->FileName[ CharIndex++ ] = '.';

    //
    // extension
    //

    PArcDirEnt->FileName[ CharIndex++ ] = POmfDirEnt->FolderType;

    //
    // null char
    //

    PArcDirEnt->FileName[ CharIndex ]='\0';

    //
    // set length (note: CharIndex is 0-based)
    //

    PArcDirEnt->FileNameLength = CharIndex;

    //
    // all done, exit.
    //

    return;
}





// ----------------------------------------------------------------------------
// PROCEDURE:   FwGetEisaId:
//
// DESCRIPTION: The routine returns the requested board and info id.
//
// ARGUMENTS:   PathName        Option board path name pointer
//              EisaId          Pointer to 7 bytes space for the id
//              IdInfo          Pointer to 1 byte space for the info id
//
// RETURN:      TRUE            all done.
//              FALSE           for any error.
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

BOOLEAN
FwGetEisaId
    (
    IN  PCHAR  PathName,
    OUT PCHAR  EisaId,
    OUT PUCHAR IdInfo
    )
{
    //
    // define local variables
    //

    PCONFIGURATION_COMPONENT pComp;             // Pointer to a component struc
    EISA_SLOT_INFO SlotInfo;                    // pointer to first eisa info
    BOOLEAN GetIdStatus = FALSE;                // be pessimistic

    PRINTDBG("FwGetEisaId\n\r");                // DEBUG SUPPORT

    //
    // Check to see if the motherboard component is being accessed.  Since
    // Jensen doesn't have a motherboard id, substitute values.
    //

    if (strstr(PathName, "eisa(0)other(0)") != NULL) {
        EisaId[0] = 'J';
        EisaId[1] = 'e';
        EisaId[2] = 'n';
        EisaId[3] = 's';
        EisaId[4] = 'e';
        EisaId[5] = 'n';
        EisaId[6] = '0';
        *IdInfo = 0;
        GetIdStatus = TRUE;

    //
    // get the requested component
    //

    } else if  ( (pComp = FwGetComponent(PathName)) == NULL );

    //
    // check the configuration data length
    //

    else if ( pComp->ConfigurationDataLength < EISA_SLOT_MIN_INFO );

    //
    // get the slot info
    //

    else if ( FwGetConfigurationDataIndex( (PVOID)&SlotInfo,
                                           pComp,
                                           CONFIGDATAHEADER_SIZE,
                                           EISA_SLOT_INFO_SIZE ));

    //
    // get the requested info
    //

    else
    {
        FwUncompressEisaId( &SlotInfo.Id1stChar, EisaId );
        *IdInfo = SlotInfo.IdInfo;
        GetIdStatus = TRUE;
    }

    //
    // return status
    //

    return GetIdStatus;
}






// ----------------------------------------------------------------------------
// PROCEDURE:   FwUncompressEisaId:
//
// DESCRIPTION: The routine converts the specified compressed ID in 7 ASCII
//              chars.
//
// ARGUMENTS:   CompEisaId      Pointer to the compressed ID (4 bytes)
//              UncompEisaId    Pointer to the uncompressed ID (7 bytes)
//
// RETURN:      none
//
// ASSUMPTIONS: Compressed ID :  1st byte  bit  7   - Reserved
//                                         bits 6-2 - 1st char name comp
//                                         bits 1-0 - 2nd char name comp
//                               2nd byte  bits 7-5 - 2nd char name
//                                         bits 4-0 - 3rd char name comp
//                               3rd byte  bits 7-4 - 1st decimal number comp
//                                         bits 3-0 - 2nd decimal number comp
//                               4th byte  bits 7-4 - 3rd decimal number comp
//                                         bits 3-0 - 4th decimal number comp
//
//              Uncompressed ID: 1st byte  1st char name
//                               2nd byte  2nd char name
//                               3rd byte  3rd char name
//                               4th byte  1st decimal number
//                               5th byte  2nd decimal number
//                               6th byte  3rd decimal number
//                               7th byte  4th decimal number
//
//              Compressed -> Uncompressed :
//
//                              char comp + 'A' - 1 = char uncompressed
//                              decimal comp + '0'  = decimal uncompressed
//
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

VOID
FwUncompressEisaId
    (
    IN PUCHAR CompEisaId,
    OUT PUCHAR UncompEisaId
    )
{
    //
    // local variables
    //

    ULONG       Id;                             // used to hold the 4 bytes ID
    SHORT       i;                              // general index
    UCHAR       d;                              // hexadecimal digit

    PRINTDBG("FwUncompressEisaId\n\r");

    //
    // transform the 4 chars ID in a ULONG
    //

    Id = Fw4UcharToUlongMSB( CompEisaId );

    //
    // uncompress 4 digits, starting from the last one
    //

    for (i=3; i>=0; i--)
    {
        d = Id & ID_DIGIT_MASK;
        UncompEisaId[3+i] = (d <= 9) ? (d + '0') : (d - 0xA + 'A');
        Id >>= ID_DIGIT_SIZE;
    }

    //
    // uncompress 3 chars
    //

    for (i=2; i>=0; i--)
    {
        UncompEisaId[i] = (Id & ID_CHAR_MASK) + 'A' - 1;
        Id >>= ID_CHAR_SIZE;
    }

    //
    // exit
    //

    return;
}






// ----------------------------------------------------------------------------
// PROCEDURE:   FwGetEisaBusIoCpuAddress:
//
// DESCRIPTION: The routine returns the virtual (CPU) address for the specified
//              EISA bus.
//
// ARGUMENTS:   EisaPath        pointer to the path string
//              IoBusAddress    pointer to a PVOID variable. It used to store
//                              the computed address.
//
// RETURN:      TRUE            returned if all correct.
//              FALSE           returned for any error.
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

BOOLEAN
FwGetEisaBusIoCpuAddress
    (
    IN  PCHAR EisaPath,
    OUT PVOID *IoBusAddress
    )
{
    //
    // define local variables
    //

    PCONFIGURATION_COMPONENT PComponent;
    EISA_ADAPTER_DETAILS EisaInfo;

    PRINTDBG("FwGetEisaBusIoCpuAddress\n\r");

    //
    // get the requested component and configuration data
    //

    if  ( (PComponent = FwGetComponent( EisaPath )) == NULL  ||
          FwGetConfigurationData( (PVOID)&EisaInfo, PComponent ))
    {
        return FALSE;
    }

    //
    // Return the requested virtual (CPU) address
    //

    *IoBusAddress = EisaInfo.IoStart;
    return TRUE;
}

// ----------------------------------------------------------------------------
// PROCEDURE:   FwFileChecksum:
//
// DESCRIPTION: The routine performs a byte checksum on the specified file.
//
// ARGUMENTS:   Path            File path
//              Checksum        File checksum
//
// RETURN:      ESUCCESS        Operation completed successfully.
//              ...other        Error code.
//
// ASSUMPTIONS: none
//
// CALLS:       FwFileIdChecksum
//
// GLOBALS:     none
//
// NOTES:       The file length must be contained in a ULONG (4G -1).
// ----------------------------------------------------------------------------
//

ARC_STATUS
FwFileChecksum
    (
    IN  PCHAR  Path,
    OUT PUCHAR Checksum
    )
{
    ARC_STATUS  Status;
    ULONG       FileId;
    FILE_INFORMATION FileInfo;

    //
    // initialize checksum to zero
    //

    *Checksum = 0;

    //
    // open file
    //

    if (Status = FwOpen( Path, ArcOpenReadOnly, &FileId ))
    {
        return Status;
    }

    //
    // get file information
    //

    if (Status = FwGetFileInformation( FileId, &FileInfo ));

    //
    // return an error if file is greater than 4G - 1
    //

    else if (FileInfo.EndingAddress.HighPart != 0)
    {
        Status = EINVAL;
    }

    //
    // perform the checksum and return the status
    //

    else
    {
        Status = FwFileIdChecksum( FileId,
                                   FileInfo.StartingAddress,
                                   FileInfo.EndingAddress.LowPart,
                                   Checksum );
    }

    //
    // clase file and return status
    //

    FwClose( FileId );
    return Status;
}






// ----------------------------------------------------------------------------
// PROCEDURE:   FwChecksumByte:
//
// DESCRIPTION: The routine performs a byte checksum on the specified buffer.
//
// ARGUMENTS:   Buffer          Pointer to area to checksum.
//              Length          Length of area to checksum (bytes).
//              ChecksumByte    The pointed byte is used in input as a
//                              starting checksum value and in output as
//                              the final checksum value.
//
// RETURN:      ESUCCESS        operation completed successfully
//
// ASSUMPTIONS: none
//
// CALLS:       none
//
// GLOBALS:     none
//
// NOTES:       none
//
// ----------------------------------------------------------------------------
//

ARC_STATUS
FwChecksumByte (
    IN PUCHAR Buffer,
    IN ULONG Length,
    IN OUT PUCHAR ChecksumByte
    )
{
    //
    // checksum the buffer and exit
    //

    while (Length--)
    {
        *ChecksumByte += *Buffer++;
    }

    return ESUCCESS;
}



// ----------------------------------------------------------------------------
// PROCEDURE:   FwFileIdChecksum:
//
// DESCRIPTION: The routine performs a byte checksum within the spcified
//              range of the FileId.
//
// ARGUMENTS:   FileId          File table entry index.
//              StartingOffset  Beginning of checksum range (byte offset).
//              Length          Number of bytes to checksum.
//              Checksum        Input : start checksum value
//                              Output: image checksum
//
// RETURN:      ESUCCESS        Operation completed successfully.
//              ...other        Error code.
//
// ASSUMPTIONS: none
//
// CALLS:       FwChecksumByte
//
// GLOBALS:     none
//
// NOTES:       This routine can also be called during the "open" phase
//              (the open bit is not set), because the read and seek functions
//              are called directly using the table within the file id
//              descriptor.
// ----------------------------------------------------------------------------
//

ARC_STATUS
FwFileIdChecksum
    (
    IN ULONG FileId,
    IN LARGE_INTEGER StartingOffset,
    IN ULONG Length,
    IN OUT PUCHAR Checksum
    )
{
    ARC_STATUS Status;
    ULONG  BytesToRead;
    ULONG  Count;
    UCHAR  TempBuffer[MAXIMUM_SECTOR_SIZE + MAX_DCACHE_LINE_SIZE];
    PUCHAR TempPointer = ALIGN_BUFFER( TempBuffer );

    //
    // If buffer length is zero, return ESUCCESS
    //

    if (Length==0)
    {
        return ESUCCESS;
    }

    //
    // position the file pointer
    //

    if (Status = (BlFileTable[FileId].DeviceEntryTable->Seek)
                        (FileId, &StartingOffset, SeekAbsolute))
    {
        return Status;
    }

    //
    // perform the checksum
    //

    do
    {
        BytesToRead = MIN( Length, MAXIMUM_SECTOR_SIZE );

        //
        // fill the buffer
        //

        if (Status = (BlFileTable[FileId].DeviceEntryTable->Read)
                        (FileId, TempPointer, BytesToRead, &Count))
        {
            return Status;
        }

        //
        // make sure that we got the requested number of bytes
        //

        if (Count != BytesToRead)
        {
            return EINVAL;
        }

        //
        // checksum the area
        //

        FwChecksumByte( TempPointer, BytesToRead, Checksum);

    } while ( Length -= BytesToRead );

    //
    // all done
    //

    return Status;
}





// ----------------------------------------------------------------------------
// PROCEDURE:   FwGetMnemonicKey;
//
// DESCRIPTION: The routine returns the specified key.  The specified key
//              within the path string must be in digits, an error is returned
//              otherwise.
//
// ARGUMENTS:   Path            pointer to the pathname string
//              Mnemonic        mnemonic string
//              Key             pointer to buffer used to hold the ouput
//
// RETURN:      TRUE            returned if all correct
//              FALSE           returned invalid input parameter
//
// ASSUMPTIONS:
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

BOOLEAN
FwGetMnemonicKey
    (
    IN PCHAR  Path,
    IN PCHAR  Mnemonic,
    IN PULONG Key
    )
{
    PCHAR Tmp;
    PCHAR Tmp2;
    CHAR  Digits[ KEY_MAX_DIGITS + 1 ];
    ULONG i;
    CHAR  String[ MAX_MNEMONIC_LEN + 3 ];       // mnemonic + ')' + '(' + '\0'

    PRINTDBG("FwGetMnemonicKey\n\r");

    //
    // Construct a string of the form ")mnemonic("
    //

    String[0]=')';
    for(i=1; *Mnemonic; i++)
    {
        String[i] = * Mnemonic++;
    }
    String[i++]='(';
    String[i]='\0';

    //
    // first look for the "mnemonic(" string.
    //

    if ( (Tmp = strstr( Path, &String[1] )) == NULL)
    {
        return FALSE;
    }

    //
    // if not the begin of the path name, look for the ")mnemonic(" string.
    //

    if (Tmp != Path)
    {
        if ( (Tmp = strstr( Path, String )) == NULL)
        {
            return FALSE;
        }
    }
    else
    {
        i--;
    }

    //
    // skip the mnemonic
    //

    Tmp+=i;

    //
    // make sure that the number of digits is within the allowed range
    //

    if ((Tmp2 = strchr(Tmp, ')')) == NULL  ||  Tmp2 - Tmp > KEY_MAX_DIGITS )
    {
        return FALSE;
    }

    //
    // convert the value in between parentesis to integer
    //

    for ( i=0;  *Tmp != ')';  i++ )
    {
        if ( !isdigit( Digits[i] = *Tmp++ ))
        {
            return FALSE;
        }
    }
    Digits[i]='\0';

    //
    // return the converted number
    //

    *Key = i ? atoi(Digits) : 0;
    return TRUE;
}






// ----------------------------------------------------------------------------
// PROCEDURE:   FwGetNextMnemonic:
//
// DESCRIPTION: The routine returns the next mnemonic in the list.
//              If Mnemonic is a null string, the first mnemonic of the list
//              is returned.  The FALSE value is returned if the specified
//              mnemonic is not present or end of list.
//
//
// ARGUMENTS:   Path            pointer to the pathname string.
//              Mnemonic        mnemonic string pointer
//              NextMnemonic    next mnemonic string pointer
//
// RETURN:      TRUE            returned if all correct
//              FALSE           returned if invalid input parameter or end of
//                              list
//
// ASSUMPTIONS: The path is composed by ARC mnemonic names as follows:
//              adapter(.)..adapter(.)controller(.)peripheral(.)'\0'.
//              The NextMnemonic string is big enough to hold the mnemonic
//              name.
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

BOOLEAN
FwGetNextMnemonic
    (
    IN  PCHAR Path,
    IN  PCHAR Mnemonic,
    OUT PCHAR NextMnemonic
    )
{
    //
    // local variables
    //

    PCHAR Tmp = Path;
    PCHAR Tmp2;
    ULONG i;
    CHAR  String[ MAX_MNEMONIC_LEN + 3 ];       // mnemonic + ')' + '(' + '\0'

    PRINTDBG("FwGetNextMnemonic\n\r");

    if ( *Mnemonic )
    {
        //
        // Construct a string of the form ")mnemonic("
        //

        String[0]=')';
        for(i=1; *Mnemonic; i++)
        {
            String[i] = *Mnemonic++;
        }
        String[i++]='(';
        String[i]='\0';

        //
        // first look for the "mnemonic(" string.
        //

        if ( (Tmp = strstr( Path, &String[1] )) == NULL)
        {
            return FALSE;
        }

        //
        // if not the begin of the path name, look for the ")mnemonic(" string.
        //

        if (Tmp != Path)
        {
            if ( (Tmp = strstr( Path, String )) == NULL)
            {
                return FALSE;
            }
            Tmp++;
        }

        //
        // return an error if there is another mnemonic with same name
        //

        if (strstr( Tmp, String ) != NULL)
        {
            return FALSE;
        }

        //
        // find the start of the next mnemonic
        //

        if ( (Tmp = strchr(Tmp,')')) == NULL  )
        {
            return FALSE;
        }
        Tmp++;
    }

    //
    // find the end of the next mnemonic and copy it.
    //

    if ( (Tmp2 = strchr(Tmp,'(')) == NULL  ||  Tmp2 == Tmp  ||
          strchr( Tmp2, ')') == NULL )
    {
        return FALSE;
    }

    //
    // copy the mnemonic
    //

    while( Tmp < Tmp2 )
    {
        *NextMnemonic++ = *Tmp++;
    }
    *NextMnemonic = '\0';

    //
    // return all done
    //

    return TRUE;
}






// ----------------------------------------------------------------------------
// PROCEDURE:   FwGetMnemonicPath:
//
// DESCRIPTION: The routine returns a pointer to the mnemonic path.
//              The routine uses the first mnemoic match to built
//              the mnemonic path.
//
// ARGUMENTS:   Path            pointer to the path string.
//              Mnemonic        pointer to the mnemomic.
//              MnemonicPath    pointer to the mnemonic path string.
//
// RETURN:      TRUE            returned if all correct.
//              FALSE           returned for any error.
//
// ASSUMPTIONS: the string pointed by MnemonicPath must be enough large to
//              contain the mnemoinc path.
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

BOOLEAN
FwGetMnemonicPath
    (
    IN PCHAR  Path,
    IN PCHAR  Mnemonic,
    OUT PCHAR MnemonicPath
    )
{
    //
    // local variables
    //

    PCHAR Tmp;
    ULONG i;
    CHAR  String[ MAX_MNEMONIC_LEN + 3 ];       // mnemonic + ')' + '(' + '\0'

    PRINTDBG("FwGetMnemonicPath\n\r");

    //
    // Construct a string of the form ")mnemonic("
    //

    String[0]=')';
    for(i=1; *Mnemonic; i++)
    {
        String[i] = *Mnemonic++;
    }
    String[i++]='(';
    String[i]='\0';

    //
    // first look for the "mnemonic(" string.
    //

    if ( (Tmp = strstr( Path, &String[1] )) == NULL)
    {
        return FALSE;
    }

    //
    // if not the begin of the path name, look for the ")mnemonic(" string.
    //

    if (Tmp != Path)
    {
        if ( (Tmp = strstr( Path, String )) == NULL)
        {
            return FALSE;
        }
        Tmp++;
    }

    //
    // find the end of this mnemonic
    //

    if ( (Tmp = strchr(Tmp,')')) == NULL  )
    {
        return FALSE;
    }

    //
    // copy the mnemonic path in the output string
    //

    strncpy( MnemonicPath, Path, Tmp-Path+1 );
    MnemonicPath[ Tmp-Path+1 ] = '\0';

    //
    // all done, return
    //

    return TRUE;
}





// ----------------------------------------------------------------------------
// PROCEDURE:   GetNextPath:
//
// DESCRIPTION: The routine isolates the first path string entry form the
//              specified path string list.
//
// ARGUMENTS:   PathList        pointer to the path string list pointer.
//                              it is updated upon return to point the
//                              next path string entry.
//              PathTarget      pointer to the isolated path string.
//
//
// RETURN:      TRUE            returned if operation is successful.
//              FALSE           returned if end of list has been reached.
//
// ASSUMPTIONS: The path string list is ended with a null char ('\0') and
//              the path string entries are separated from each other with
//              the ';' char.
//              The target string has enough space to hold the isolated
//              path string.
//
// CALLS:
//
// GLOBALS:
//
// NOTES:
// ----------------------------------------------------------------------------
//

BOOLEAN
GetNextPath
    (
    IN OUT PCHAR *PPathList,
    OUT PCHAR PathTarget
    )
{
    PRINTDBG("GetNextPath\n\r");

    //
    // if end of list, retrun with error
    //

    if (!**PPathList)
    {
        return FALSE;
    }

    //
    // copy the path string and update the pointer
    //

    for (; *PathTarget=**PPathList; *PathTarget++, *(*PPathList)++)
    {
        if (**PPathList==';')
        {
            *PathTarget='\0';
            (*PPathList)++;
            break;
        }
    }
    return TRUE;
}