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
|
#include "insignia.h"
#include "host_def.h"
/* INSIGNIA MODULE SPECIFICATION
-----------------------------
SccsID : @(#)emm_mngr.c 1.24 08/31/93 Copyright Insignia Solutions Ltd.
FILE NAME : emm_mngr.c
MODULE NAME : 'Middle layer' of Expanded Memory Manager
THIS PROGRAM SOURCE FILE IS SUPPLIED IN CONFIDENCE TO THE
CUSTOMER, THE CONTENTS OR DETAILS OF ITS OPERATION MUST
NOT BE DISCLOSED TO ANY OTHER PARTIES WITHOUT THE EXPRESS
AUTHORISATION FROM THE DIRECTORS OF INSIGNIA SOLUTIONS INC.
DESIGNER : J.P.Box
DATE : April '88
PURPOSE : Contains all the routines that communicate with
the arrays and data structures that hold the
necessary Expanded Memory Manager Data.
The Following Routines are defined:
1. init_expanded_memory()
2. free_expanded_memory()
3. get_new_handle()
4. free_handle()
5. reallocate_handle()
6. handle_ok()
7. set_no_pages()
8. set_EM_pageno()
9. set_map()
10. set_name()
11. get_no_pages()
12. get_EM_pageno()
13. get_map()
14. get_name()
15. alloc_page()
16. free_page()
17. map_page()
18. unmap_page()
19. map_saved()
20. save_map()
21. restore_map()
22. copy_exchange_data()
23. page_status()
The following routines just return variables to the top layer
24. get_total_pages()
25. get_unallocated_pages()
26. get_base_address()
27. get_total_handles()
28. get_total_open_handles()
29. get_no_phys_pages()
30. get_page_seg()
31. get_map_size()
=========================================================================
AMMENDMENTS :
=========================================================================
*/
#ifdef LIM
#ifdef SEGMENTATION
/*
* The following #include specifies the code segment into which this
* module will by placed by the MPW C compiler on the Mac II running
* MultiFinder.
*/
#include "SOFTPC_LIM.seg"
#endif
#include <stdio.h>
#include <string.h>
#if defined(NTVDM) && defined(MONITOR)
#include <malloc.h>
#endif
#include TypesH
#include "xt.h"
#include CpuH
#include "sas.h"
#include "host_emm.h"
#include "emm.h"
#include "gmi.h"
#include "debug.h"
#ifndef PROD
#include "trace.h"
#endif
#include "timer.h"
#ifdef NTVDM
#include "error.h"
#endif /* NTVDM */
typedef enum
{
BYTE_OP,
WORD_OP,
STR_OP
} MM_LIM_op_type;
#ifdef NTVDM
/* Local Variables */
static long
handle[MAX_NO_HANDLES], /* Array containing unique ID's */
/* for each handle, these are */
/* usually pointers, but this */
/* is host dependant */
backfill; /* backfill memory size */
static unsigned short
total_pages = 0, /* no. of EM pages available */
unallocated_pages = 0, /* no. of unallocated EM pages */
total_handles, /* no of handles available */
total_open_handles, /* no. of allocated handles */
*EM_page_mapped_array = NULL, /* EMM page mapped array */
*EM_page_mapped = NULL, /* Expanded Memory pages */
/* currently mapped in */
page_offset, /* offset in handle data at */
/* which page numbers start */
map_size, /* no of bytes rq'd to store map*/
no_phys_pages = 0, /* no. of phys. pages available */
no_altreg_sets = 0; /* no of alternative reg sets */
static unsigned short
physical_page[MAX_NO_PAGES]; /* array containing segment */
/* addresses of physical pages */
static unsigned short
EM_start, EM_end;
static IU8
* altreg_alloc_mask; /* altref allocate mask */
static unsigned short
next_free_altreg_set, /* next free altreg set #, 0 based */
free_altreg_sets, /* number of free altreg */
active_altreg_set = 0; /* current active alt reg set */
static char
name[NAME_LENGTH]; /* for storing handle name */
#define GET_EM_PAGE_MAPPED_PTR(set) (EM_page_mapped_array + \
(set * no_phys_pages))
/* get emm parameters, initialize housekeeping structures and
* reserve page frames.
*/
boolean lim_page_frame_init(PLIM_CONFIG_DATA lim_config_data)
{
int i;
unsigned short altreg_alloc_mask_size; /* altreg allocation mask array size */
no_phys_pages = get_lim_page_frames(physical_page, lim_config_data);
/* The first 4 pages must be continuous and locate above 640KB
* (the EMM primary page frame(physical pages 0, 1, 2 and 3)).
* It is then followed by other pages located above 640KB and then
* pages below 640KB(back fill)
*/
if (!no_phys_pages)
return FALSE;
no_altreg_sets = lim_config_data->total_altreg_sets;
backfill = lim_config_data->backfill;
/* each mapping register set has no_phys_pages pages */
EM_page_mapped_array = host_malloc(no_phys_pages * no_altreg_sets *
sizeof(short));
if (EM_page_mapped_array == NULL) {
host_error(EG_MALLOC_FAILURE, ERR_CONT, "");
return FALSE;
}
/* one bit for each altreg set */
altreg_alloc_mask_size = (no_altreg_sets + 7) / 8;
altreg_alloc_mask = host_malloc(altreg_alloc_mask_size);
if (altreg_alloc_mask == NULL) {
host_free(EM_page_mapped_array);
host_error(EG_MALLOC_FAILURE, ERR_CONT, "");
return FALSE;
}
/* all altreg sets are free at this moment */
for (i = 0; i < altreg_alloc_mask_size; i++)
altreg_alloc_mask[i] = 0;
next_free_altreg_set = 0;
free_altreg_sets = no_altreg_sets;
return TRUE;
}
#else
/* Local Variables */
static long
#ifdef macintosh
*handle;
#else
handle[MAX_NO_HANDLES]; /* Array containing unique ID's */
/* for each handle, these are */
/* usually pointers, but this */
/* is host dependant */
#endif /* !macintosh */
static short
total_pages = 0, /* no. of EM pages available */
unallocated_pages = 0, /* no. of unallocated EM pages */
total_handles, /* no of handles available */
total_open_handles, /* no. of allocated handles */
EM_page_mapped[MAX_NO_PAGES], /* Expanded Memory pages */
/* currently mapped in */
page_offset, /* offset in handle data at */
/* which page numbers start */
map_size, /* no of bytes rq'd to store map*/
no_phys_pages; /* no. of phys. pages available */
static unsigned int
EM_start, /* start segment for EM mapping */
EM_end; /* 1st segment past end of EM */
static unsigned short
physical_page[MAX_NO_PAGES]; /* array containing segment */
/* addresses of physical pages */
static char
name[NAME_LENGTH]; /* for storing handle name */
#endif
/*
===========================================================================
FUNCTION : init_expanded_memory
PURPOSE : This routine calls the routine to allocate the expanded
memory pages and then sets up the arrays and variables that
are used by the Expanded Memory Manager(EMM).
RETURNED STATUS : SUCCESS - manager initialised succesfully
FAILURE - Failure to allocate space for Expanded Memory
pages.
DESCRIPTION :
=========================================================================
*/
GLOBAL int init_expanded_memory IFN2(int, size, /* size of area in megabytes */
int, mem_limit /* limit of conventional memory
* 256, 512 or 640KB */ )
{
short
pages_above_640, /* no of mappable locations */
pages_below_640, /* available either side of 640*/
EM_page_no, /* page no. within exp. memory */
physical_page_no; /* page no. within map region */
unsigned short
base; /* start segment of mappable */
/* memory below 640 KB */
int i, j; /* loop counters */
if (!no_phys_pages)
return FAILURE;
/* get space for expanded memory pages */
if(host_initialise_EM(size) != SUCCESS)
{
#ifdef NTVDM
host_error(EG_EXPANDED_MEM_FAILURE, ERR_QU_CO, NULL);
#endif /* NTVDM */
return(FAILURE);
}
#ifdef macintosh
if (!handle)
{
handle = (long *)host_malloc(MAX_NO_HANDLES*sizeof(long));
}
#endif /* macintosh */
/* Initialise EMM variables */
#ifndef NTVDM
EM_start = 0xd000;
EM_end = 0xe000;
#else
EM_start = physical_page[0];
EM_end = physical_page[0] + EMM_PAGE_SIZE * 4;
#endif
total_pages = unallocated_pages = size * 0x100000 / EMM_PAGE_SIZE;
/* always allow max handles (Used to be 32 handles/Meg expanded mem) */
total_handles = MAX_NO_HANDLES;
total_open_handles = 0;
for(i = 0; i < total_handles; i++)
handle[i] = (long) NULL;
#ifdef NTVDM
map_size = no_phys_pages * NSIZE;
page_offset = MAP_OFFSET + map_size;
pages_below_640 = backfill / EMM_PAGE_SIZE;
pages_above_640 = no_phys_pages - pages_below_640;
/* initialize active mapping register to set 0 */
EM_page_mapped = EM_page_mapped_array;
allocate_altreg_set(&active_altreg_set);
for (i = 0; i < no_phys_pages; i++)
EM_page_mapped[i] = (unsigned short)EMPTY;
if (get_new_handle(0) != 0)
return FAILURE;
set_no_pages(0, 0);
#else
pages_above_640 = (effective_addr(EM_end,0) - effective_addr(EM_start,0)) / EMM_PAGE_SIZE;
pages_below_640 = ((640 - mem_limit) * 1024) / EMM_PAGE_SIZE;
no_phys_pages = pages_above_640 + pages_below_640;
map_size = no_phys_pages * NSIZE;
page_offset = MAP_OFFSET + map_size;
/*
* set up addresses and mapping status of physical pages
*/
for( i = 0; i < pages_above_640; i++ )
{
physical_page[i] = EM_start + (i * EMM_PAGE_SIZE >> 4);
EM_page_mapped[i] = EMPTY;
}
base = mem_limit * 64;
for(i = pages_above_640, j = 0; i < no_phys_pages; i++)
{
physical_page[i] = base + (j++ * EMM_PAGE_SIZE >> 4);
EM_page_mapped[i] = EMPTY;
}
/*
* Allocate handle 0 with any pages required for back filling
*/
if(get_new_handle(pages_below_640) != 0)
return(FAILURE);
for(i = 0, physical_page_no = pages_above_640; i < pages_below_640; i++)
{
if((EM_page_no = alloc_page()) == FAILURE)
return (FAILURE);
set_EMpage_no(0, i, EM_page_no);
if(map_page(EM_page_no, physical_page_no++) == FAILURE)
return(FAILURE);
}
set_no_pages(0, pages_below_640);
#endif /* NTVDM */
/*
* Set up necessary variables in Top level EMM function code
*/
reset_emm_funcs();
/*
** Map the address space taken up by LIM to RAM.
** Without LIM it would be ROM.
** The range seems to be fixed at segment D000 to F000.
** Assumed that AT's have GMI and XT's do not.
** XT's can use the old fashioned memset calls in
** delta:manager:init_struc.c
*/
#ifdef NTVDM
/* every physical page must be connected as RAM */
for (i = 0; i < pages_above_640; i++)
sas_connect_memory(effective_addr(physical_page[i], 0),
effective_addr(physical_page[i], EMM_PAGE_SIZE - 1),
SAS_RAM
);
#else
sas_connect_memory(effective_addr(EM_start,0) , effective_addr(EM_end,0) -1 , SAS_RAM );
#endif
sure_note_trace3(LIM_VERBOSE,"initialised EMM, total pages= %#x, pages above 640= %#x, pages below 640 = %#x",no_phys_pages, pages_above_640, pages_below_640);
return(SUCCESS);
}
/*
===========================================================================
FUNCTION : free_expanded_memory
PURPOSE : This routine calls frees all memory allocated for the
expanded memory manager and resets the variables that
are used by the Expanded Memory Manager(EMM).
RETURNED STATUS : SUCCESS -
DESCRIPTION : If total_pages = 0, this indicates that expanded
memory hasn't been initialised, so the routine simply
does nothing and returns.
=========================================================================
*/
GLOBAL void free_expanded_memory IFN0()
{
short handle_no;
if(total_pages == 0)
return;
/* free space allocated for each handle */
handle_no = 0;
while(total_open_handles > 0)
{
while(!handle_ok(handle_no))
handle_no++;
free_handle(handle_no++);
}
/*
* Free space for expanded memory pages
*/
host_deinitialise_EM();
total_pages = 0;
return;
}
/*
===========================================================================
FUNCTION : get_new_handle()
PURPOSE : Finds the next free handle no., allocates storage space
for recording the EMM data associated with this handle,
and stores the 'storage ID' in the handle array.
RETURNED STATUS : SUCCESS - new handle allocated successfully
FAILURE - Error occurred in trying to allocate storage
space for handle data
DESCRIPTION : see emm.h for a description of space required for
storing handle data e.g. PAGE_OFFSET & NSIZE
=========================================================================
*/
GLOBAL short get_new_handle IFN1(short, no_pages) /* No.of pages to store in handle */
{
short i; /* loop count */
short handle_no;
int data_size; /* no. of bytes of data storage */
long storage_ID; /* host dependant storage */
/* identifier, usually a ptr. */
sure_note_trace2(LIM_VERBOSE,"new handle request, current total handles= %d, pages requested = %d",total_handles, no_pages);
handle_no = 0;
do
if (handle[handle_no] == (long) NULL)
break;
while(++handle_no < total_handles);
if(handle_no >= total_handles)
return(FAILURE);
data_size = page_offset + (no_pages * NSIZE);
if ((storage_ID = host_allocate_storage(data_size)) == (long) NULL)
return(FAILURE);
handle[handle_no] = storage_ID;
for (i=0 ; i < no_phys_pages ; i++) {
set_map_no(handle_no, i, FREE);
}
total_open_handles++;
sure_note_trace1(LIM_VERBOSE,"allocation OK, return handle=%d",handle_no);
return(handle_no);
}
/*
===========================================================================
FUNCTION : free_handle
PURPOSE : frees the storage space allocated to the handle number.
Decrements the handles open count
RETURNED STATUS : SUCCESS - space freed
FAILURE - unable to free space
DESCRIPTION :
=========================================================================
*/
GLOBAL int free_handle IFN1(short, handle_no) /* No.of handle to be freed */
{
long storage_ID; /* host dependant storage */
/* identifier, usually a ptr. */
sure_note_trace2(LIM_VERBOSE, "free handle %d request, total handles = %d",handle_no, total_handles);
storage_ID = handle[handle_no];
if(host_free_storage(storage_ID) != SUCCESS)
return(FAILURE);
handle[handle_no] = (long) NULL;
total_open_handles--;
return(SUCCESS);
}
/*
===========================================================================
FUNCTION : reallocate_handle
PURPOSE : changes the number of pages allocated to a given handle
RETURNED STATUS : SUCCESS - handle reallocated
FAILURE - unable to get space for new handle data
DESCRIPTION :
=========================================================================
*/
GLOBAL int reallocate_handle IFN3(short, handle_no, /* handle to be reallocated */
short, old_page_count,/* current pages in handle */
short, new_page_count)/* required pages for handle*/
{
long storage_ID; /* host dependant storage */
/* identifier, usually a ptr. */
short size, /* size of handle data area */
new_size; /* size of new handle data area */
size = page_offset + (old_page_count * NSIZE);
new_size = page_offset + (new_page_count * NSIZE);
storage_ID = handle[handle_no];
sure_note_trace3(LIM_VERBOSE,"reallocate pages for handle %d, old size=%#x, new size= %#x",handle_no, size, new_size);
if((storage_ID = host_reallocate_storage(storage_ID, size, new_size)) ==
(long) NULL)
return(FAILURE);
handle[handle_no] = storage_ID;
return(SUCCESS);
}
/*
===========================================================================
FUNCTION : handle_ok
PURPOSE : checks to see if the handle no. is valid - this should
be called before every routine that uses a handle number
to retrieve or set data in the handle data area
RETURNED STATUS : TRUE - Handle no. is valid
FALSE - Handle no. is invalid
DESCRIPTION :
=========================================================================
*/
GLOBAL boolean handle_ok IFN1(short, handle_no)
{
#ifdef NTVDM
/* some *** applicaitons feed us a negtive handle number. Catch it and
throw it to the hell*/
if ((unsigned short)handle_no >= (unsigned short)total_handles) {
#else
if(handle_no >= total_handles || handle_no < 0) {
#endif
sure_note_trace1(LIM_VERBOSE,"invalid handle %d",handle_no);
return(FALSE);
}
if(handle[handle_no] == (long) NULL){
sure_note_trace1(LIM_VERBOSE,"invalid handle %d",handle_no);
return(FALSE);
}
return(TRUE);
}
/*
===========================================================================
FUNCTION : set_no_pages
PURPOSE : sets the no of pages variable in the specified handle
RETURNED STATUS :
DESCRIPTION :
=========================================================================
*/
GLOBAL void set_no_pages IFN2(short, handle_no, short, no_pages)
{
long storage_ID; /* host dependant storage */
/* identifier, usually a ptr. */
byte *ptr; /* pointer to storage area */
storage_ID = handle[handle_no];
ptr = USEBLOCK(storage_ID);
*(short *)ptr = no_pages;
FORGETBLOCK(storage_ID)
return;
}
/*
===========================================================================
FUNCTION : set_EMpage_no
PURPOSE : sets Expanded Memory page that is used for the specified
logical page into the handle data storage area
RETURNED STATUS :
DESCRIPTION :
=========================================================================
*/
GLOBAL void set_EMpage_no IFN3(short, handle_no,
short, logical_page_no,
short, EM_page_no)
{
long storage_ID; /* host dependant storage */
/* identifier, usually a ptr. */
byte *ptr; /* pointer to storage area */
storage_ID = handle[handle_no];
ptr = USEBLOCK(storage_ID);
/*
* offset pointer to correct position
*/
ptr += (page_offset +(logical_page_no * NSIZE));
*(short *)ptr = EM_page_no;
FORGETBLOCK(storage_ID)
return;
}
/*
===========================================================================
FUNCTION : set_map_no
PURPOSE : sets Expanded Memory page number in the map section of
the handle data storage area
RETURNED STATUS :
DESCRIPTION :
=========================================================================
*/
GLOBAL void set_map_no IFN3(short, handle_no,
unsigned char, physical_page_no,
short, EM_page_no)
{
long storage_ID; /* host dependant storage */
/* identifier, usually a ptr. */
unsigned char *ptr; /* pointer to storage area */
storage_ID = handle[handle_no];
ptr = USEBLOCK(storage_ID);
/*
* offset pointer to correct position
*/
ptr += (MAP_OFFSET +(physical_page_no * NSIZE));
*(short *)ptr = EM_page_no;
FORGETBLOCK(storage_ID)
return;
}
/*
===========================================================================
FUNCTION : set_name
PURPOSE : writes a name into the name section of the handle data
storage area
RETURNED STATUS :
DESCRIPTION :
=========================================================================
*/
GLOBAL void set_name IFN2(short, handle_no,
char *, new_name)
{
long storage_ID; /* host dependant storage */
/* identifier, usually a ptr. */
unsigned char *ptr; /* pointer to storage area */
storage_ID = handle[handle_no];
ptr = USEBLOCK(storage_ID);
/*
* offset pointer to correct position
*/
ptr += NAME_OFFSET;
strncpy((char *)ptr, new_name, NAME_LENGTH);
FORGETBLOCK(storage_ID)
return;
}
/*
===========================================================================
FUNCTION : get_no_pages
PURPOSE : gets the number of pages assigned to the specified handle
RETURNED STATUS : no of pages returned
DESCRIPTION :
=========================================================================
*/
GLOBAL short get_no_pages IFN1(short, handle_no)
{
long storage_ID; /* host dependant storage */
/* identifier, usually a ptr. */
byte *ptr; /* pointer to storage area */
short no_pages; /* no. of pages in handle */
storage_ID = handle[handle_no];
ptr = USEBLOCK(storage_ID);
no_pages = *(short *)ptr;
FORGETBLOCK(storage_ID)
return(no_pages);
}
/*
===========================================================================
FUNCTION : get_EMpage_no
PURPOSE : returns the Expanded Memory page no. used for the
specified logical page in the given handle
RETURNED STATUS : Expanded Memory page no. returned
DESCRIPTION :
=========================================================================
*/
GLOBAL short get_EMpage_no IFN2(short, handle_no,
short, logical_page_no)
{
long storage_ID; /* host dependant storage */
/* identifier, usually a ptr. */
byte *ptr; /* pointer to storage area */
short EM_page_no; /* Expanded Memory page number */
storage_ID = handle[handle_no];
ptr = USEBLOCK(storage_ID);
/*
* offset pointer to correct position
*/
ptr += (page_offset +(logical_page_no * NSIZE));
EM_page_no = *(short *)ptr;
FORGETBLOCK(storage_ID)
return(EM_page_no);
}
/*
===========================================================================
FUNCTION : get_map_no
PURPOSE : returns the Expanded Memory page no. saved in the map
attached to the given handle
RETURNED STATUS : page no. in map returned
DESCRIPTION :
=========================================================================
*/
GLOBAL short get_map_no IFN2(short, handle_no,
unsigned char, physical_page_no)
{
long storage_ID; /* host dependant storage */
/* identifier, usually a ptr. */
unsigned char *ptr; /* pointer to storage area */
short EM_page_no; /* Expanded Memory page number */
storage_ID = handle[handle_no];
ptr = USEBLOCK(storage_ID);
/*
* offset pointer to correct position
*/
ptr += (MAP_OFFSET +(physical_page_no * NSIZE));
EM_page_no = *(short *)ptr;
FORGETBLOCK(storage_ID)
return(EM_page_no);
}
/*
===========================================================================
FUNCTION : get_name
PURPOSE : returns a pointer to the name assigned to the given handle
RETURNED STATUS :
DESCRIPTION :
=========================================================================
*/
GLOBAL char *get_name IFN1(short, handle_no)
{
long storage_ID; /* host dependant storage */
/* identifier, usually a ptr. */
unsigned char *ptr; /* pointer to storage area */
storage_ID = handle[handle_no];
ptr = USEBLOCK(storage_ID);
/*
* offset pointer to correct position
*/
ptr += NAME_OFFSET;
strncpy(name, (char *)ptr, NAME_LENGTH);
FORGETBLOCK(storage_ID)
return(name);
}
/*
===========================================================================
FUNCTION : alloc_page
PURPOSE : allocates a page from expanded memory
RETURNED : >=0 = SUCCESS - EM page no. returned
<0 = FAILURE - error occured in trying to allocate page
DESCRIPTION :
=========================================================================
*/
GLOBAL short alloc_page IFN0()
{
short EM_page_no; /* EM_page_no to be returned */
if ((EM_page_no = host_alloc_page()) == FAILURE)
return(FAILURE);
unallocated_pages--;
return(EM_page_no);
}
/*
===========================================================================
FUNCTION : free_page
PURPOSE : frees a page of expanded memory for further use
RETURNED : SUCCESS - page freed successfully
FAILURE - unable to free page
DESCRIPTION :
=========================================================================
*/
GLOBAL int free_page IFN1(short, EM_page_no)
{
short physical_page_no;
if (EM_page_no > total_pages)
return(FAILURE);
/* Removed from mapped pages table */
for (physical_page_no=0; physical_page_no < no_phys_pages; physical_page_no++) {
if (EM_page_mapped[physical_page_no] == EM_page_no) {
EM_page_mapped[physical_page_no] = UNMAPPED;
break;
}
}
if (host_free_page(EM_page_no) != SUCCESS)
return(FAILURE);
unallocated_pages++;
return(SUCCESS);
}
#ifndef NTVDM
/*
========================================================================
FUNCTION : page_already_mapped
PURPOSE : function to determine whether a EMM page is already
mapped to a different physical page within intel
memory
RETURNED : count of number of pages in addition to the page
passed which are mapped to the same logical page.
The page number of one of these mirror pages is
also returned via the pointer passed as an argument.
DESCRIPTION :
========================================================================
*/
GLOBAL ULONG
page_already_mapped IFN2(short, EM_page_no,
unsigned char *, physical_page_no)
{
unsigned char page, orig_page;
ULONG map_count;
map_count = 0;
orig_page = *physical_page_no;
for( page = 0; page < (unsigned char) no_phys_pages; page++ )
{
if ((EM_page_mapped[page] == EM_page_no) &&
(page != orig_page ))
{
sure_note_trace2( LIM_VERBOSE,
"log page %x mapped to phys page %x",
EM_page_no, page);
*physical_page_no = page;
map_count++;
}
}
return( map_count );
}
LOCAL VOID
connect_MM_LIM_page IFN2( USHORT, segment, SHORT, EM_page_no )
{
ULONG eff_addr;
#ifdef PROD
UNUSED(EM_page_no);
#endif
assert2( NO, "Connecting multi-mapped page, %d, at %x",
EM_page_no, segment );
eff_addr = effective_addr( segment, 0 );
sas_connect_memory( eff_addr, eff_addr + EMM_PAGE_SIZE - 1,
SAS_MM_LIM );
}
LOCAL VOID
disconnect_MM_LIM_page IFN4( USHORT, segment, SHORT, EM_page_no,
ULONG, map_count, unsigned char, physical_page_no )
{
ULONG eff_addr;
#ifdef PROD
UNUSED(EM_page_no);
#endif
sure_note_trace2(LIM_VERBOSE,
"Unmapping multi-mapped page, %d, at %x",
EM_page_no, segment );
eff_addr = effective_addr( segment, 0 );
sas_connect_memory( eff_addr, eff_addr + EMM_PAGE_SIZE - 1, SAS_RAM );
if( map_count == 1 )
{
/*
* We have to disconnect the last page of this group,
* by connecting it as SAS_RAM.
*/
segment = physical_page[physical_page_no];
eff_addr = effective_addr( segment, 0 );
sure_note_trace2(LIM_VERBOSE,
"Unmapping last multi-mapped page, %d, at %x",
EM_page_no, segment );
sas_connect_memory( eff_addr, eff_addr + EMM_PAGE_SIZE - 1,
SAS_RAM );
}
}
#endif /* !NTVDM */
/*
========================================================================
FUNCTION : map_page
PURPOSE : maps a page from expanded memory into Intel physical
address space
RETURNED : SUCCESS - page mapped successfully
FAILURE - unable to map page
DESCRIPTION :
========================================================================
*/
GLOBAL int map_page IFN2(short, EM_page_no,
unsigned char, physical_page_no)
{
USHORT segment; /* segment address of page in */
/* physical address space */
unsigned char phys_page;
ULONG map_count;
segment = physical_page[physical_page_no];
/*
* make sure that a page is not already mapped in
* if it is - return it to Expanded Memory
*/
sure_note_trace2(LIM_VERBOSE,
"map page %#x to phys page %#x",
EM_page_no,physical_page_no);
if(EM_page_mapped[physical_page_no] != EMPTY)
{
sure_note_trace1(LIM_VERBOSE,
"phys page already mapped to page %#x",
EM_page_mapped[physical_page_no]);
if(EM_page_mapped[physical_page_no] == EM_page_no)
{
sure_note_trace0(LIM_VERBOSE,
"remap of same page, so do nothing");
return(SUCCESS);
}
#ifndef NTVDM
/*
* We want to return the current contents of this physical
* page to the logical page ( to sync up the logical page ).
* We have to check first that this physical page is not a
* mirror of some other page - if it is we have to disconnect
* it from the group of pages it is mirroring.
*/
phys_page = physical_page_no;
if( map_count = page_already_mapped(
EM_page_mapped[physical_page_no], &phys_page))
{
disconnect_MM_LIM_page( segment, EM_page_no,
map_count, phys_page );
}
/*
* We can now unmap the physical page and indicate
* that it is really unmapped.
*/
if(host_unmap_page(segment,
EM_page_mapped[physical_page_no]) != SUCCESS)
{
return(FAILURE);
}
EM_page_mapped [physical_page_no] = EMPTY;
#endif
}
#ifndef NTVDM
/*
* If this logical page is already mapped, make sure the
* new mapping has an up to date copy
*/
phys_page = physical_page_no;
if (page_already_mapped(EM_page_no, &phys_page))
{
/*
* We now want to get the LIM logical page up to date with
* the physical pages that are currently mapped to it. We
* don't want to set EM_page_mapped [phys_page] to EMPTY
* after the host_unmap_page(). If we did we wouldn't notice
* that we had a multiply-mapped page and the patch up code
* wouldn't get called.
*/
host_update_logical_page( physical_page[phys_page],
EM_page_no );
/*
* Connect new page and "mirror" page as MM_LIM. This may
* mean some pages get connected as MM_LIM multiple times
* - inefficient but not wrong otherwise. This connection
* has to be made for all hosts - even those that can do
* mapping themselves. This is to make sure that the CPU
* data structures associated with all pages get updated
* when a multi-mapped write occurs.
*/
connect_MM_LIM_page( segment, EM_page_no );
connect_MM_LIM_page( physical_page[phys_page], EM_page_no );
}
#endif
if(host_map_page(EM_page_no, segment) != SUCCESS)
return(FAILURE);
EM_page_mapped[physical_page_no] = EM_page_no;
sure_note_trace0(LIM_VERBOSE,"map OK");
return(SUCCESS);
}
/*
========================================================================
FUNCTION : unmap_page
PURPOSE : unmaps a page from Intel physical address space back to
expanded memory
RETURNED : SUCCESS - page unmapped successfully
FAILURE - error in unmapping page
DESCRIPTION :
========================================================================
*/
GLOBAL int unmap_page IFN1(unsigned char, physical_page_no)
{
short EM_page_no; /* EM_page_no currently mapped */
unsigned short segment; /* segment address of page in */
/* physical address space */
SHORT phys_page;
ULONG map_count;
sure_note_trace1( LIM_VERBOSE,
"unmap phys page %#x",physical_page_no);
segment = physical_page[physical_page_no];
if((EM_page_no = EM_page_mapped[physical_page_no]) == EMPTY)
{
/*
* Already done
*/
sure_note_trace0( LIM_VERBOSE,
"already unmapped, so do nothing");
return(SUCCESS);
}
phys_page = physical_page_no;
#ifndef NTVDM
if( map_count = page_already_mapped( EM_page_no, (unsigned char *)&phys_page ))
{
disconnect_MM_LIM_page( segment, EM_page_no,
map_count, phys_page );
}
#endif
if(host_unmap_page(segment, EM_page_no) != SUCCESS)
return(FAILURE);
EM_page_mapped[physical_page_no] = EMPTY;
sure_note_trace0(LIM_VERBOSE,"unmap OK");
return(SUCCESS);
}
/*
===========================================================================
FUNCTION : map_saved
PURPOSE : Checks to see if a map has been saved for the specified
handle
RETURNED STATUS : TRUE - A map is saved for this handle
FALSE - No map has been saved
DESCRIPTION : checks the first entry in the map for the value 'FREE'
=========================================================================
*/
GLOBAL boolean map_saved IFN1(short, handle_no)
{
long storage_ID; /* host dependant storage */
/* identifier, usually a ptr. */
unsigned char *ptr; /* pointer to storage area */
short status; /* value read from map */
storage_ID = handle[handle_no];
ptr = USEBLOCK(storage_ID);
/*
* offset pointer to correct position
*/
ptr += MAP_OFFSET;
status = *(short *)ptr;
FORGETBLOCK(storage_ID)
return((status == FREE) ? FALSE : TRUE);
}
/*
===========================================================================
FUNCTION : save_map
PURPOSE : takes a copy of the EM_page_mapped array and store it in
the map section of the handle data storage area
RETURNED STATUS : SUCCESS - everything OK
FAILURE - invalid segment no. passed in src array
DESCRIPTION : if handle_no is >= 0 the map is stored in the data area
assigned to that handle
if handle_no == -1 the map is stored in the array pointed
to by dst_segment:dst_offset
if handle_no == -2 only the pages specified by the segment
addresses in the src array (pointed to by
src_segment:src_offset) are saved in the dst array
(pointed to by dst_segment:dst_offset).
=========================================================================
*/
GLOBAL int save_map IFN5(short, handle_no,
unsigned short, dst_segment,
unsigned short, dst_offset,
unsigned short, src_segment,
unsigned short, src_offset)
{
unsigned short offset, /* temp offset variable */
segment; /* segment address to be saved */
short i, /* loop counter */
page_no, /* physical page no. */
no_to_save; /* no of pages in src array */
if(handle_no >= 0)
for (i = 0; i < no_phys_pages; i++)
set_map_no(handle_no, i, EM_page_mapped[i]);
else if(handle_no == -1)
for(i = 0; i < no_phys_pages; i++)
{
write_intel_word(dst_segment, dst_offset, EM_page_mapped[i]);
dst_offset +=2;
}
else if(handle_no == -2)
{
offset = dst_offset;
for(i = 0; i < no_phys_pages; i++)
{
#ifdef NTVDM
write_intel_word(dst_segment, offset, LEAVE);
#else
write_intel_word(dst_segment, offset, EMPTY);
#endif
offset += 2;
}
read_intel_word(src_segment, src_offset, (word *)&no_to_save);
for (i = 0; i < no_to_save; i++)
{
src_offset += 2;
read_intel_word(src_segment, src_offset, &segment);
/*
* Find Physical page no.
*/
page_no = 0;
do
if(segment == physical_page[page_no])
break;
while(++page_no < no_phys_pages);
if(page_no >= no_phys_pages)
return (FAILURE);
/*
* Save EM page number in destination array
*/
offset = dst_offset + (page_no * 2);
write_intel_word(dst_segment, offset, EM_page_mapped[page_no]);
}
}
return(SUCCESS);
}
/*
===========================================================================
FUNCTION : restore_map
PURPOSE : reads the specified map and returns 2 arrays specifying
which pages have to be mapped out and which ones have to be
mapped in
RETURNED STATUS : SUCCESS - Map read successfully
DESCRIPTION : A +ve handle number indicates that the map is stored
within the handle data area.
If the handle number is -ve the map will be read from the
data pointed to by segment:offset
Only page out - if there is a page currently mapped in and
it is not being replaced by a copy of itself or an empty
page
Only page in - if new page is different to existing one
and it is not empty
=========================================================================
*/
#ifdef ANSI
GLOBAL int restore_map (short handle_no,
unsigned short segment,
unsigned short offset,
short pages_out[],
short pages_in[])
#else
GLOBAL int restore_map (handle_no, segment, offset, pages_out, pages_in)
short handle_no;
unsigned short segment;
unsigned short offset;
short pages_out[];
short pages_in[];
#endif /* ANSI */
{
short i, /* loop counter */
new_page, /* page number read from map */
old_page; /* existing page number */
for(i = 0; i < no_phys_pages; i++)
{
if(handle_no >= 0)
new_page = get_map_no(handle_no, i);
else
{
read_intel_word(segment, offset, (word *)&new_page);
offset += 2;
#ifdef NTVDM
if(new_page < LEAVE || new_page >= total_pages)
#else
if(new_page < EMPTY || new_page >= total_pages)
#endif /* NTVDM */
return(FAILURE);
}
old_page = EM_page_mapped[i];
/*
if(old_page != EMPTY && new_page != EMPTY && old_page != new_page )
*/
/* need to do unmap to empty state case to update the page copy in the LIM
space in case of new maps of that page to other LIM slots. */
#ifdef NTVDM
if(old_page != EMPTY && old_page != new_page && new_page != LEAVE)
#else
if(old_page != EMPTY && old_page != new_page )
#endif
pages_out[i] = old_page;
else
pages_out[i] = EMPTY;
#ifdef NTVDM
if(new_page != EMPTY && new_page != old_page && new_page != LEAVE)
#else
if(new_page != EMPTY && new_page != old_page)
#endif
pages_in[i] = new_page;
else
pages_in[i] = EMPTY;
}
if(handle_no >= 0)
set_map_no(handle_no, 0, FREE);
return(SUCCESS);
}
/*
===========================================================================
FUNCTION : copy_exchange_data
PURPOSE : copies or exchanges data between conventional and
expanded memory
RETURNED STATUS : SUCCESS - everything ok
FAILURE - Error ocurred in copying data
DESCRIPTION : type - uses a bit pattern, bit 0 represents destination,
bit 1 represents source, a set bit means expanded, a clear
bit means conventional memory
bit 2 represents exchange if set or move if it is clear
e.g. 0 (0000) = move conventional to conventional
1 (0001) = move conventional to expanded
6 (0110) = exchange expanded to conventional
7 (0111) = exchange expanded to expanded
=========================================================================
*/
GLOBAL int copy_exchange_data IFN8(unsigned char, type,
short, src_handle,
unsigned short, src_seg_page,
unsigned short, src_offset,
short, dst_handle,
unsigned short, dst_seg_page,
unsigned short, dst_offset,
unsigned long, length)
{
short dst_EMpage, /* EM page no . of destination */
src_EMpage; /* EM page no. of source */
int page_no; /* phys. page no. of mapped page*/
/*
* First check to see if the expanded memory page is mapped
* if it is - change the type to deal directly with the
* physical page that it is mapped to
*/
if( type & 1)
{
dst_EMpage = get_EMpage_no(dst_handle, dst_seg_page);
if((page_no = page_status(dst_EMpage)) != UNMAPPED )
{
dst_seg_page = physical_page[page_no];
type &= 6;
}
}
if( type & 2)
{
src_EMpage = get_EMpage_no(src_handle, src_seg_page);
if((page_no = page_status(src_EMpage)) != UNMAPPED )
{
src_seg_page = physical_page[page_no];
type &= 5;
}
}
switch(type)
{
case 0: if(host_copy_con_to_con(length, src_seg_page, src_offset,
dst_seg_page, dst_offset) != SUCCESS)
return(FAILURE);
break;
case 1: if(host_copy_con_to_EM(length, src_seg_page, src_offset,
dst_EMpage, dst_offset) != SUCCESS)
return(FAILURE);
break;
case 2: if(host_copy_EM_to_con(length, src_EMpage, src_offset,
dst_seg_page, dst_offset) != SUCCESS)
return(FAILURE);
break;
case 3: if(host_copy_EM_to_EM(length, src_EMpage, src_offset,
dst_EMpage, dst_offset) != SUCCESS)
return(FAILURE);
break;
case 4: if(host_exchg_con_to_con(length, src_seg_page, src_offset,
dst_seg_page, dst_offset) != SUCCESS)
return(FAILURE);
break;
case 5: if(host_exchg_con_to_EM(length, src_seg_page, src_offset,
dst_EMpage, dst_offset) != SUCCESS)
return(FAILURE);
break;
case 6: if(host_exchg_con_to_EM(length, dst_seg_page, dst_offset,
src_EMpage, src_offset) != SUCCESS)
return(FAILURE);
break;
case 7: if(host_exchg_EM_to_EM(length, src_EMpage, src_offset,
dst_EMpage, dst_offset) != SUCCESS)
return(FAILURE);
break;
default: return(FAILURE);
}
return(SUCCESS);
}
/*
========================================================================
FUNCTION : page_status
PURPOSE : checks if a particular EM page is mapped or not
RETURNED STATUS : page_no - physical page no returned if mapped
UNMAPPED - returned if not mapped
DESCRIPTION :
========================================================================
*/
GLOBAL int page_status IFN1(short, EMpage_no)
{
short physical_page_no = 0;
/* position of page in physical memory */
do
if(EM_page_mapped[physical_page_no] == EMpage_no)
break;
while(++physical_page_no < no_phys_pages );
if(physical_page_no >= no_phys_pages)
return(UNMAPPED);
else
return(physical_page_no);
}
/*
========================================================================
FUNCTION : phys_page_from_addr
PURPOSE : determines the physical page number of a LIM page
from its Intel address.
RETURNED STATUS : The physical page containing the LIM address.
DESCRIPTION :
=======================================================================
*/
LOCAL SHORT
phys_page_from_addr IFN1( sys_addr, address )
{
sys_addr start;
start = effective_addr( EM_start, 0x0 );
return( (ULONG)(( address - start ) / EMM_PAGE_SIZE ));
}
/*
========================================================================
FUNCTION : get_total_pages
get_unallocated_pages
get_base_address
get_total_handles
get_total_open_handles
get_no_phys_pages
get_page_seg
get_map_size
PURPOSE : simply returns the reqested variables, to avoid
having to use globals
RETURNED STATUS : the following variables are returned , depending upon
the routine called:-
total_pages
unallocated_pages
base_address
total_handles
total_open_handles
no_phys_pages
physical_page[i]
map_size
DESCRIPTION :
========================================================================
*/
#ifdef SEGMENTATION
/*
* The following #include specifies the code segment into which this
* module will by placed by the MPW C compiler on the Mac II running
* MultiFinder.
*/
#include "SOFTPC_LIM2.seg"
#endif
GLOBAL short get_total_pages IFN0()
{
return(total_pages);
}
#ifdef SEGMENTATION
/*
* The following #include specifies the code segment into which this
* module will by placed by the MPW C compiler on the Mac II running
* MultiFinder.
*/
#include "SOFTPC_LIM.seg"
#endif
GLOBAL short get_unallocated_pages IFN0()
{
return(unallocated_pages);
}
GLOBAL unsigned short get_base_address IFN0()
{
#ifdef NTVDM
return(physical_page[0]);
#else
return(EM_start);
#endif
}
GLOBAL short get_total_handles IFN0()
{
return(total_handles);
}
GLOBAL short get_total_open_handles IFN0()
{
return(total_open_handles);
}
GLOBAL short get_no_phys_pages IFN0()
{
return(no_phys_pages);
}
GLOBAL unsigned short get_page_seg IFN1(unsigned char, page_no)
{
return(physical_page[page_no]);
}
GLOBAL short get_map_size IFN0()
{
return(map_size);
}
#ifdef NTVDM
GLOBAL short get_segment_page_no(unsigned short segment)
{
#if defined(LARGE_FRAME) && !defined(MONITOR)
short i
for (i = 0; i < no_phys_pages; i++)
if (physical_page[i] == segment)
break;
return(i);
#else
return((segment - physical_page[0]) / EMM_PAGE_SIZE);
#endif
}
GLOBAL unsigned short get_no_altreg_sets(void)
{
return(no_altreg_sets);
}
GLOBAL unsigned short get_active_altreg_set(void)
{
return(active_altreg_set);
}
GLOBAL boolean altreg_set_ok(unsigned short set)
{
return(set < no_altreg_sets &&
(altreg_alloc_mask[set >> 3] & (1 << (set & 0x07))));
}
#if defined (NTVDM) && defined(MONITOR) && !defined(PROD)
/* these functions are provided for monitor to verify that
* it has the same definitions of EMM_PAGE_SIZE and INTEL_PAGE_SIZE as
* ours.
*/
GLOBAL unsigned short get_emm_page_size(void)
{
return ((unsigned short)EMM_PAGE_SIZE);
}
GLOBAL unsigned short get_intel_page_size(void)
{
return ((unsigned short) INTEL_PAGE_SIZE);
}
#endif
/* allocate a free alt mapping register set */
GLOBAL boolean allocate_altreg_set(unsigned short *altreg_set)
{
short byte_offset, bit_offset;
short *page_mapped_ptr;
IU8 mask;
int i;
/* this check is very important because we ** probably ** have
* several unused bits in the allocation mask array
*/
if (free_altreg_sets == 0)
return (FALSE);
/* use quick and dirty way to allocate a set */
if (next_free_altreg_set < no_altreg_sets) {
altreg_alloc_mask[next_free_altreg_set >> 3] |=
(0x1 << (next_free_altreg_set & 0x07));
*altreg_set = next_free_altreg_set++;
}
else {
for (byte_offset = 0; byte_offset < no_altreg_sets; byte_offset++) {
if (altreg_alloc_mask[byte_offset] != 0xFF) {
mask = altreg_alloc_mask[byte_offset];
bit_offset = 0;
while (mask & (1 << bit_offset))
bit_offset++;
break;
}
}
altreg_alloc_mask[byte_offset] |= (1 << bit_offset);
*altreg_set = byte_offset * 8 + bit_offset;
}
/* a new alt reg set is just allocated, initialize its
* mapping register to the current active set
*/
page_mapped_ptr = GET_EM_PAGE_MAPPED_PTR(*altreg_set);
for (i = 0; i < no_phys_pages; i++)
page_mapped_ptr[i] = EM_page_mapped[i];
return TRUE;
}
/* free the given alt mapping register set */
GLOBAL boolean deallocate_altreg_set(short set)
{
/* can not deallocate set 0 or active set */
if (set != 0 && set != active_altreg_set && set < no_altreg_sets &&
altreg_alloc_mask[set >> 3] & (1 << (set &0x07))) {
altreg_alloc_mask[set >> 3] &= (0xFE << (set & 0x07));
free_altreg_sets++;
if (free_altreg_sets == (no_altreg_sets - 1))
next_free_altreg_set = 1;
return TRUE;
}
return FALSE;
}
/* This function activate the given alt mapping register set
* input: alt reg set to be activated.
* output: TRUE if the given set is activated.
* FALSE if the given set is not activated.
*/
GLOBAL boolean activate_altreg_set(unsigned short set, short * page_in)
{
int i;
short * page_out, *page_in_ptr;
short new_page, old_page, segment;
if (active_altreg_set == set && page_in == NULL)
return TRUE;
/* get the mapping array to be mapped in*/
page_in_ptr = GET_EM_PAGE_MAPPED_PTR(set);
/* if no page-in override, use the altreg set current mapping */
if (page_in == NULL)
page_in = page_in_ptr;
/* the active altreg is being paged out */
page_out = GET_EM_PAGE_MAPPED_PTR(active_altreg_set);
for ( i = 0; i < no_phys_pages; i++) {
new_page = page_in[i];
old_page = page_out[i];
segment = physical_page[i];
if (old_page != EMPTY && old_page != new_page) {
if (host_unmap_page(segment, old_page) != SUCCESS)
return FALSE;
}
if(new_page != EMPTY && new_page != old_page) {
if (host_map_page(new_page, segment) != SUCCESS)
return FALSE;
}
/* update the active-to-be set mapping */
page_in_ptr[i] = new_page;
}
active_altreg_set = set;
EM_page_mapped = page_in_ptr;
return TRUE;
}
#endif /* NTVDM */
#ifndef NTVDM
/*
========================================================================
FUNCTION : LIM_b_write,
LIM_w_write,
LIM_str_write
patch_pages
PURPOSE : LIM byte, word & string - called from write check
failure code in the CPU when a write to a multi-mapped
LIM page is detected.
patch_pages - generic code called from the other
three routines.
RETURNED STATUS : None.
DESCRIPTION :
========================================================================
*/
LOCAL VOID
patch_one_page_partial IFN4( sys_addr, intel_addr, sys_addr, eff_addr,
MM_LIM_op_type, type, ULONG, data )
{
ULONG check_len;
UNUSED( intel_addr ); /* Used in patch_one_page_full() */
switch( type )
{
case BYTE_OP:
check_len = 1;
break;
case WORD_OP:
check_len = 2;
break;
case STR_OP:
check_len = data;
break;
}
sas_overwrite_memory( eff_addr, check_len );
}
LOCAL VOID
patch_one_page_full IFN4( sys_addr, intel_addr, sys_addr, eff_addr,
MM_LIM_op_type, type, ULONG, data )
{
sys_addr check_addr;
ULONG check_len;
switch( type )
{
case BYTE_OP:
check_addr = eff_addr;
check_len = 1;
sas_store_no_check( eff_addr, data );
break;
case WORD_OP:
check_addr = eff_addr;
check_len = 2;
sas_storew_no_check( eff_addr, data );
break;
case STR_OP:
check_addr = eff_addr;
check_len = data;
do
{
sas_store_no_check( eff_addr,
sas_hw_at_no_check(
intel_addr ));
intel_addr++;
eff_addr++;
}
while( --data );
break;
}
sas_overwrite_memory( check_addr, check_len );
}
LOCAL VOID
patch_pages IFN6( MM_LIM_op_type, type, ULONG, offset,
SHORT, EM_page_no, SHORT, phys_page_no,
ULONG, data, sys_addr, intel_addr )
{
LONG cnt01;
sys_addr eff_addr;
for( cnt01 = 0; cnt01 < get_no_phys_pages(); cnt01++ )
{
if(( EM_page_mapped[cnt01] == EM_page_no ) &&
( cnt01 != phys_page_no ))
{
eff_addr = effective_addr( get_page_seg(cnt01),
offset );
host_patch_one_page( intel_addr, eff_addr, type, data );
sure_note_trace1(LIM_VERBOSE,
"MM LIM write type %d", type );
sure_note_trace2(LIM_VERBOSE,
"log page 0x%x, phs page 0x%x",
EM_page_no, cnt01 );
}
}
}
GLOBAL VOID
LIM_b_write IFN1( sys_addr, intel_addr )
{
ULONG limdata;
SHORT EM_page_no, phys_page_no;
word offset;
phys_page_no = phys_page_from_addr( intel_addr );
offset = intel_addr -
effective_addr( get_page_seg(phys_page_no), 0x0 );
EM_page_no = EM_page_mapped[phys_page_no];
/*
* Get the data written in order to patch up this
* page's buddy pages.
*/
limdata = (ULONG) sas_hw_at_no_check( intel_addr );
patch_pages( BYTE_OP, offset, EM_page_no, phys_page_no,
limdata, intel_addr );
/*
* Tell the CPU that this page has been written to.
*/
sas_overwrite_memory( intel_addr, 1 );
}
GLOBAL VOID
LIM_w_write IFN1( sys_addr, intel_addr )
{
ULONG limdata;
SHORT EM_page_no, phys_page_no;
word offset;
phys_page_no = phys_page_from_addr( intel_addr );
offset = intel_addr -
effective_addr( get_page_seg(phys_page_no), 0x0 );
EM_page_no = EM_page_mapped[phys_page_no];
limdata = (ULONG) sas_w_at_no_check( intel_addr );
patch_pages( WORD_OP, offset, EM_page_no, phys_page_no,
limdata, intel_addr );
sas_overwrite_memory( intel_addr, 2 );
}
GLOBAL VOID
LIM_str_write IFN2( sys_addr, intel_addr, ULONG, length )
{
SHORT EM_page_no, phys_page_no;
word offset;
phys_page_no = phys_page_from_addr( intel_addr );
offset = intel_addr -
effective_addr( get_page_seg(phys_page_no), 0x0 );
EM_page_no = EM_page_mapped[phys_page_no];
patch_pages( STR_OP, offset, EM_page_no, phys_page_no,
length, intel_addr );
sas_overwrite_memory( intel_addr, length );
}
#endif /* !NTVDM */
#ifndef PROD
/*
===========================================================================
FUNCTION : print_handle_data
PURPOSE : used for debugging only - prints all the data stored
for a given handle
RETURNED STATUS : none
DESCRIPTION :
=========================================================================
*/
GLOBAL void print_handle_data IFN1(short, handle_no)
{
long storage_ID;
byte *ptr;
short no_pages, i;
char *name_ptr;
short *map_ptr;
short *page_ptr;
if ((storage_ID = handle[handle_no]) == 0)
{
printf("Unassigned handle - No. %d\n",handle_no);
return;
}
ptr = USEBLOCK(storage_ID);
name_ptr = (char *)ptr + NAME_OFFSET;
map_ptr = (short *)(ptr + MAP_OFFSET);
page_ptr = (short *)(ptr + page_offset);
no_pages = *(short *)ptr;
printf("Handle No. %d\n",handle_no);
printf("No. of Pages = %d\n",no_pages);
printf("Name = '");
for(i=0;i<8;i++)
printf("%c",*name_ptr++);
printf("'\n");
printf("Map = ");
for(i=0;i<no_phys_pages;i++)
printf(" %d",*map_ptr++);
printf("\n");
for(i=0;i<no_pages;i++)
printf("Page (%d) = %d\n",i,*page_ptr++);
FORGETBLOCK(storage_ID);
return;
}
#endif /* !PROD */
#endif /* LIM */
|