SoftcardUtilImpl.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
written by Ch. Le Cocq, August 4, 1988
Christian Le Cocq October 10, 1988 10:56:52 am PDT
Low level communication between CP (6085 mesa processor) and Sparc, assuming Big [Big Endian] byte order (hh, hl, lh, ll) which is not the PrincOps CARD32 byte order (lh, ll, hh, hl).
DIRECTORY
Basics USING [Card32FromF, HighHalf, LowHalf, Card16FromH, HighByte],
DoveInputOutput USING [Peek, Poke],
SoftcardUtil;
SoftcardUtilImpl: CEDAR PROGRAM
IMPORTS Basics, DoveInputOutput
EXPORTS SoftcardUtil
~ BEGIN
Address: TYPE ~ SoftcardUtil.Address;
Error: PUBLIC ERROR ~ CODE;
FillZones: PUBLIC PROC [base: Address, len: CARD32, w: UNSPECIFIED ← 0] ~ {
FOR i: CARD32 IN [0..len) DO
DoveInputOutput.Poke[base.a+i, w];
ENDLOOP;
};
GetCard32: PUBLIC PROC [base: Address] RETURNS [val: CARD32] ~ {
val ← Basics.Card32FromF[[hi: LOOPHOLE[DoveInputOutput.Peek[base.a]], lo: LOOPHOLE[DoveInputOutput.Peek[base.a+1]]]];
};
PutCard32: PUBLIC PROC [base: Address, val: CARD32] ~ {
DoveInputOutput.Poke[base.a, Basics.HighHalf[val]];
DoveInputOutput.Poke[base.a+1, Basics.LowHalf[val]];
};
CopyTo: PUBLIC PROC [from: REF TEXT, start, len: CARD32, base: Address] ~ {
wordLen: CARD32 ← len/2;
IF len=0 THEN RETURN;
IF start MOD 2#0 THEN Error;
the buffer is supposed to be aligned on a word (16b) boundary.
IF wordLen>0 THEN TRUSTED {
p: LONG POINTER TO UNSPECIFIEDLOOPHOLE[from, LONG POINTER TO UNSPECIFIED]+SIZE[TEXT[start]]; --@from.text[start]];
limit: LONG POINTER TO UNSPECIFIED ← p+wordLen*SIZE[UNSPECIFIED];
b: CARD32 ← base.a;
DO
DoveInputOutput.Poke[b, p^];
b ← b+1;
p ← p+SIZE[UNSPECIFIED];
IF p=limit THEN EXIT;
ENDLOOP;
};
IF len MOD 2#0 THEN {
w: CARD16 ← Basics.Card16FromH[[hi: LOOPHOLE[from.text[start+len-1]], lo: 0 ]];
DoveInputOutput.Poke[base.a+wordLen, w];
};
};
CopyFrom: PUBLIC PROC [to: REF TEXT, start, len: CARD32, base: Address] ~ {
wordLen: CARD32 ← len/2;
IF len=0 THEN RETURN;
IF start MOD 2#0 THEN Error;
the buffer is supposed to be aligned on a word (16b) boundary.
IF wordLen>0 THEN TRUSTED {
p: LONG POINTER TO UNSPECIFIEDLOOPHOLE[to, LONG POINTER TO UNSPECIFIED]+SIZE[TEXT[start]]; --@from.text[start]];
limit: LONG POINTER TO UNSPECIFIED ← p+wordLen*SIZE[UNSPECIFIED];
b: CARD32 ← base.a;
DO
p^ ← DoveInputOutput.Peek[b];
b ← b+1;
p ← p+SIZE[UNSPECIFIED];
IF p=limit THEN EXIT;
ENDLOOP;
};
IF len MOD 2#0 THEN {
w: CARD16 ← DoveInputOutput.Peek[base.a+wordLen];
to.text[start+len-1] ← LOOPHOLE[Basics.HighByte[w]];
};
};
END.