Text preview for : Segments.mesa_Oct77.pdf part of xerox Segments.mesa Oct77 xerox mesa 3.0_1977 listing Segments.mesa_Oct77.pdf



Back to : Segments.mesa_Oct77.pdf | Home

segments.mESA 24-0CT-77 18:44:36 Page 1


-- Segments.Mesa Edited by Sandman on August 16. 1977 8:41 AM
DIRECTORY
AltoDefs: FROM "altodefs".
AltoFileDefs: FROM "altofiledefs",
BootDefs: FROM "bootdefs",
DiskDefs: FROM "diskdeFs",
InlineDefs: FROM "inlinedefs",
ProcessDefs: FROM "processdefs",
SegmentDeFs: FROM "segmentdeFs",
SystemDefs: FROM "systemdefs":
DEFINITIONS FROM AltoFileDeFs, BootDefs, SegmentDefs:
Segments: PROGRAM
IMPORTS BootOefs, DiskDefs, SegmentDefs
EXPORTS BootDefs, SegmentDefs, SystemDefs SHARES SegmentDefs = BEGIN
InvalidSegmentSize: PUBLIC SIGNAL [pages:PageCount] = CODE;
NewFileSegment: PUBLIC PROCEDURE [
file:FileHandle, base:PageNumber. pages:PageCount, access:AccessOptions]
RETURNS [seg:FlleSegmentHandle] =
BEGIN OPEN TnlineDefs;
IF access = DefaultAccess THEN access ~ Read:
IF file.segcount = MaxSegs THEN ERROR FileError[file];
IF BITAND[access,Append]HO THEN ERROR FileAccessError[file]:
seg ~ AllocateFileSegment[FileSegmentTable];
BEGIN ENABLE UNWIND =>
LiberateFileSegment[FileSegmentTable,seg]:
IF base = OefaultBase THEN base ~ 1;
IF pages = DefaultPages THEN
pages ~ GetEndOFFile[file].page-base+l:
IF pages ~IN (O .. AltoDefs.MaxVMPage+l] THEN
ERROR InvalidSegmentSize[pages]:
SetFileAccess[file,access]:
END;
segt ~ Object [ TRUE, FALSE,
Segment [ FALSE, BITAND[access,Read]#O,
BITAND[access,Write]HO, other, 0, pages,
0, file, base, FileHint[eofOA,O]]]:
file.segcount ~ file.segcount+l:
RETURN
END:
BootFileSegment: PUBLIC PROCEDURE [
file:FileHandle, base: PageNumber ,
pages:PageCount, access:AccessOptions, addr:POINTER]
RETURNS [seg:FileSegmentHandle] = BEGIN
vm: PageNumber;
seg ~ NewFileSegment[file,base,pages,access];
IF addr H NIL THEN
BEGIN
seg.VMpage ~ vm ~ PageFromAddress[addr];
-- Disablelnterrupts[];
FOR vm IN [vm .. vm+pages) DO
IF PageFree[vm] TIIEN ERROR:
ENDLOOP;
seg.swappedin ~ TRUE;
seg. lock ~ seg.lock+l;
file.swapcount ~ file.swapcount+l;
-- [nableInterrupts[];
[NO;
RrTURN
rNO;
OeleterileSegmenL: PUBLIC PROCrDUR[ [seg:FileSegmentllandle]
BrGIN
file: rileHandle ~ seg.file;
ValidateFileSegment[FileSegmentTable.seg];
SwapOut[seg];
llberaterileSegment[FileSegmenLTable,seg];
file.segcount .. rile.segcount-l;
If rile.segcounL = 0 THrN ReleaseFile[file];
RrTURN
[NO;
segments.mESA 24-0CT-77 18:44:36 Page 2



FileSegmentAddress: PUBLIC PROCEDURE [seg:FileSagmentHandle]
RETURNS [POINTER] = BEGIN
IF -seg.swappedin THEN ERROR SwapError[seg];
RETURN[AddressFromPage[seg.VMpage]]
END;

-- Window Segments (such as they ara)
MoveFilaSegment: PUBLIC PROCEDURE [
seg:FileSegmentHandle, bnse:PageNumber, pages:PageCount] =
BEGIN ValidateFileSegment[FileSegmentTable,seg];
IF base = DefaultBase THEN base ~ 1;
IF pages = DefaultPages THEN
pages ~ GetEndOfFile[seg.file].page-base+1;
IF pages -IN (0 .. Al+oDefs.MaxVMPage+1] THEN
ERROR InvalidSegmentSize[pages];
SwapOut[seg]; seg.base ~ base;
seg.pages ~ pages;
RETURN
END;
MapFileSegment: PUBLIC PROCEDURE [
seg:FileSegmentHandle, file:FileHandle, base:PageNumber]
BEGIN
wasin, waswrite: BOOLEAN;
old: FileHandle = seg.file;
ValidateFileSegment[FileSegmentTable,seg]:
IF -old.read THEN ERROR FileAccessError[old];
IF -file.write THEN ERROR FileAccessError(file];
IF base = DefaultBase THEN base ~ 1;
wasin ~ seg.swappedin; waswrite ~ seg.write:
IF -wasin THEN SwapIn[seg]:
-- DisableInterrupts[];
old.swapcount ~ old.swapcount-1:
old.segcount ~ old.segcount-1:
seg.file ~ file; seg.base ~ base:
seg.hint ~ FileHint[eofDA,O];
seg.write ~ TRUE;
file.segcount ~ file.segcount+l:
file.swapcount ~ file.swapcount+l;
-- EnableInterrupts[];
IF wasin OR -waswrite THEN SwapUp[seg];
seg.write ~ waswrite;
IF -wasin THEN
BEGIN Unlock[seg]; SwapOut[seg] END:
IF old.segcount=O THEN ReleaseFile[old];
RETURN
END;
segments.mESA 24-0CT-77 18:44:36 Page 3


-- Segment Positioning
PositionSeg: PUBLIC PROCEDURE [seg:FileSegmentHandle, useseg:BOOLEAN]
RETURNS [BOOLEAN] = BEGIN
-- returns TRUE if it read a non-null page into the segment.
efa: CFA; buf: DataSegmentHandle; buffer: POINTER;
IF seg.hint.da = eofDA AND seg.base > 8
AND seg.file.segeount > 1 THEN FindSegHint[seg];
IF seg.hint.da = eofDA OR seg.hint.page # seg.base THEN
BEGIN
buffer ~
IF useseg THEN AddressFromPage[seg.VMpage]
ELSE DataSegmentAddress[buf ~ NewDataSegment[DefaultBase,1]];
efa.fp ~ seg.file.fp;
efa.fa ~ FA[seg.hint.da,seg.hint.page,O];
[] p JumpToPage[@efa.seg.base.buffer
! UNWIND =) IF -useseg THEN DeleteDataSegment[buf]]:
IF -useseg THEN DeleteDataSegment[buf]:
IF efa.Fa.page # seg.base THEN ERROR SwapError[seg]:
seg.hint p FileHint[eFa.fa.da.efa.Fa.page]:
RETURN[useseg AND efa.fa.byte#O];
END:
RETURN[FALSE]
END:
FindSegHint: PUBLIC PROCEDURE [seg:FileSegmentHandle] =
BEGIN
hint: FileHint ~ seg.hint;
CheekHint: PROCEDURE [other:FileSegmentHandle] RETURNS [BOOLEAN]
BEGIN
IF other.file = seg.file AND other.hint.da # eofDA
AND other.hint.page IN (hint.page .. seg.base] THEN
hint p other.hint;
RETURN[hint.page=seg.base]
END;
[] p EnumerateFileSegments[CheekHint);
seg.hint ~ hint;
RETURN
END;
GetFileSegmentDA: PUBLIC PROCEDURE [seg:FileSegmentHandle] RETURNS [vDA]
BEGIN
[] ~ PositionSeg[seg.FALSE);
RETURN[seg.hint.da)
END;
SetFileSegmentDA: PUBLIC PROCEDURE [seg:FileSegmentHandle, da:vDA)
BEGIN
seg.hint p FileHint[da.seg.base):
RETURN
END;
segments.mESA 24-0CT-77 18:44:36 Page 4


-- Segment Initialization
CopyDataToFileSegment: PU8LIC PROCEDURE [
dataseg: DataSegmentHandle, fileseg: Fi1eSegmentHand1e]