TargetArchitectureImpl.mesa
Copyright Ó 1989 by Xerox Corporation. All rights reserved.
Peter B. Kessler, September 1, 1989 4:55:02 pm PDT
DIRECTORY
TargetArchitecture,
RuntimeError;
TargetArchitectureImpl: CEDAR PROGRAM
IMPORTS RuntimeError
EXPORTS TargetArchitecture
~ {
IsNullAddress: PUBLIC PROCEDURE [address: TargetArchitecture.Address]
RETURNS [BOOLEAN] ~ {
isNullAddress: BOOLEAN ~ (address = TargetArchitecture.nullAddress);
RETURN [isNullAddress];
};
AddressFromDisplacement: PUBLIC PROCEDURE [
address: TargetArchitecture.Address,
displacement: TargetArchitecture.Displacement]
RETURNS [TargetArchitecture.Address] ~ {
ordAddress: CARD32 ~ LOOPHOLE[address];
ordTarget: CARD32 ← 0;
displaced: TargetArchitecture.Address ← TargetArchitecture.nullAddress;
IF displacement >= 0
THEN {
absDisplacement: CARD32 ~ displacement;
IF LAST[CARD32] - ordAddress < absDisplacement THEN {
Check first for possible overflow.
ERROR RuntimeError.BoundsFault;
};
ordTarget ← ordAddress + absDisplacement;
}
ELSE {
absDisplacement: CARD32 ~ -displacement;
IF ordAddress < absDisplacement THEN {
Check first for possible underflow.
ERROR RuntimeError.BoundsFault;
};
ordTarget ← ordAddress - absDisplacement;
};
displaced ← LOOPHOLE[ordTarget];
RETURN [displaced];
};
DisplacementFromAddresses: PUBLIC PROCEDURE [
here: TargetArchitecture.Address,
there: TargetArchitecture.Address] RETURNS [TargetArchitecture.Displacement] ~ {
See section 2.5.1.1 of the Mesa manual for rules on unsigned arithmetic.
ordHere: CARD32 ~ LOOPHOLE[here];
ordThere: CARD32 ~ LOOPHOLE[there];
displacement: TargetArchitecture.Displacement ~
IF ordThere >= ordHere
THEN ordThere - ordHere
ELSE -(ordHere - ordThere);
RETURN [displacement];
};
NextInstruction: PUBLIC PROCEDURE [pc: TargetArchitecture.Address]
RETURNS [TargetArchitecture.Address] ~ {
nextAddress: TargetArchitecture.Address ~ AddressFromDisplacement[
address: pc, displacement: +BYTES[TargetArchitecture.Instruction]];
RETURN [nextAddress];
};
PrevInstruction: PUBLIC PROCEDURE [pc: TargetArchitecture.Address]
RETURNS [TargetArchitecture.Address] ~ {
prevAddress: TargetArchitecture.Address ~ AddressFromDisplacement[
address: pc, displacement: -BYTES[TargetArchitecture.Instruction]];
RETURN [prevAddress];
};
InstructionFromContents: PUBLIC PROCEDURE [contents: TargetArchitecture.Contents]
RETURNS [TargetArchitecture.Instruction] ~ {
instruction: TargetArchitecture.Instruction ~ LOOPHOLE[contents];
RETURN [instruction];
};
ContentsFromInstruction: PUBLIC PROCEDURE [instruction: TargetArchitecture.Instruction]
RETURNS [TargetArchitecture.Contents] ~ {
contents: TargetArchitecture.Contents ~ LOOPHOLE[instruction];
RETURN [contents];
};
}.