AssignBDVM:
PUBLIC
PROC [realAddressByte, byteSize:
CARD32]
RETURNS [translationBase:
CARD32] ~
TRUSTED {
a real address for the 6085 is a virtual address for the softcard.
virtualAddressByte: CARD32 ← SoftcardBDVMPrivate.firstBDRealAd;
pageRealAd: CARD32 ← (realAddressByte/softcardPage)*softcardPage; --Round it
lastRealAd: CARD32 ← realAddressByte+byteSize;
nPages: CARD32 ← (lastRealAd-pageRealAd)/softcardPage;
IF nPages*softcardPage#(lastRealAd-pageRealAd) THEN nPages ← nPages+1;
IF nPages*softcardPage>SoftcardBDVMPrivate.maxBDVMBytes THEN ERROR;
translationBase ← pageRealAd;
IF debug THEN SoftcardBDVMCheck.Check[];
THROUGH [0..nPages)
DO
mapEntry: SparcSoftcardMap.MapEntry
← [
flags: [],
vMSpace: [name: cP],
virtualAddressByte: virtualAddressByte,
realAddressByte: pageRealAd
];
SparcSoftcardMap.WriteMapEntry[mapEntry];
virtualAddressByte ← virtualAddressByte+softcardPage;
pageRealAd ← pageRealAd+softcardPage;
ENDLOOP;
IF debug THEN SoftcardBDVMCheck.Check[];
};
RealFromAddress:
PUBLIC
PROC [address: Address]
RETURNS [realAddress:
CARD32] ~ {
roundAd: CARD32 ← ((2*address.a)/softcardPage)*softcardPage;
leftOver: CARD32 ← 2*address.a-roundAd;
mapEntry: SparcSoftcardMap.MapEntry ← [
flags: [],
vMSpace: [name: cP],
virtualAddressByte: roundAd,
realAddressByte: 0
];
TRUSTED {mapEntry ← SparcSoftcardMap.ReadMapEntry[mapEntry]};
realAddress ← mapEntry.realAddressByte+leftOver;
};
DoWithTranslation:
PUBLIC
ENTRY PROC [realAddressByte, byteSize:
CARD32, action:
PROC[Basics.UnsafeBlock]] ~ {
ENABLE UNWIND => NULL;
firstPageRealAd: CARD32 ← (realAddressByte/softcardPage)*softcardPage; --Round it
firstPageOffset: CARD32 ← realAddressByte-firstPageRealAd;
totalSize: CARD32 ← firstPageOffset+byteSize;
chunk: CARD32 ← MIN[totalSize, SoftcardBDVMPrivate.maxBDVMBytes]-firstPageOffset;
WHILE byteSize>0
DO
translationBase: CARD32 ← AssignBDVM[realAddressByte, chunk];
action[[SoftcardBDVMPrivate.firstBDVMAd, realAddressByte-translationBase, chunk]];
byteSize ← byteSize - chunk;
realAddressByte ← realAddressByte+chunk;
chunk ← MIN[byteSize, SoftcardBDVMPrivate.maxBDVMBytes];
ENDLOOP;
};