<<=========================================================             00010000
=                                                         =             00015000
=                  inclvmc - a1                           =             00020000
=                                                         =             00025000
=========================================================>>             00030000
                                                                        00035000
                                                                        00040000
$page "VIRTUAL DISC SPACE MANAGEMENT : CHANGE STRING IN MAP"            00045000
procedure changestringinmap(bitmapabsbase,startingpage,length,          00050000
   offonflag);                                                          00055000
value bitmapabsbase,startingpage,length,offonflag;                      00060000
logical bitmapabsbase,startingpage,length;                              00065000
logical offonflag;                                                      00070000
option privileged,uncallable;                                           00075000
                                                                        00080000
comment                                                                 00085000
                                                                        00090000
turns a string of length bits on or off in the bit map beginning at     00095000
absolute location bitmapabsbase.  offonflag true ==> turn on bits.      00100000
                                                                        00105000
if a bit to be changed is found already to be in the changed state      00110000
a condition code of ccl is returned.  if all ok, cc:=cce.               00115000
                                                                        00120000
;                                                                       00125000
                                                                        00130000
begin                                                                   00135000
equate tsbcinstruction=%17400,                                          00140000
       trbcinstruction=%17300;                                          00145000
                                                                        00150000
logical currentwordabsaddr,                                             00155000
        firstbitinword,                                                 00160000
        bitschanged;                                                    00165000
                                                                        00170000
logical condcode:=cce;                                                  00175000
                                                                        00180000
                                                                        00185000
currentwordabsaddr:=startingpage&lsr(4)+bitmapabsbase;                  00190000
firstbitinword:=startingpage.(12:4);                                    00195000
bitschanged:=0;                                                         00200000
                                                                        00205000
if offonflag then tos:=tsbcinstruction else tos:=trbcinstruction;       00210000
                                                                        00215000
changethisword :                                                        00220000
                                                                        00225000
tos:=absolute(x:=currentwordabsaddr);                                   00230000
x:=firstbitinword;                                                      00235000
while x <= 15 and bitschanged < length do                               00240000
   begin                                                                00245000
   asmb(xeq 1);                                                         00250000
   <<bc>>                                                               00255000
   if <> and offonflag then condcode:=ccl;                              00260000
   x:=x+1;                                                              00265000
   bitschanged:=bitschanged+1;                                          00270000
   end;                                                                 00275000
absolute(currentwordabsaddr):=tos;                                      00280000
if bitschanged < length then                                            00285000
   begin                                                                00290000
   firstbitinword:=0;                                                   00295000
   currentwordabsaddr:=currentwordabsaddr+1;                            00300000
   go to changethisword;                                                00305000
   end;                                                                 00310000
status.ccfld:=condcode;                                                 00315000
end <<changestringinmap>>;                                              00320000
                                                                        00325000
                                                                        00330000
$page "VIRTUAL DISC SPACE MANAGEMENT : RELEASE SWAP REGION"             00335000
procedure releaseswapregion(dstentrynumber);                            00340000
value dstentrynumber;                                                   00345000
logical dstentrynumber;                                                 00350000
option privileged,uncallable;                                           00355000
                                                                        00360000
comment                                                                 00365000
                                                                        00370000
releases the disc domain associated with the swapsegment whose          00375000
dst entry number has been passed as calling parameter by setting        00380000
the corresponding bits in the device's virtual disc space bitmap.       00385000
                                                                        00390000
if the disc address is bad or one of the bits was on, the               00395000
condition code is set to ccl.  if all ok, cc:=cce.                      00400000
                                                                        00405000
;                                                                       00410000
                                                                        00415000
begin                                                                   00420000
logical thisentryindex,                                                 00425000
        numbertried,                                                    00430000
        entrycount,                                                     00435000
        nextentryindex,                                                 00440000
        vmpagesallocated,                                               00445000
        bitmapabsbase,                                                  00450000
        startingpage;                                                   00455000
                                                                        00460000
double ds1 = s-1;                                              <<06558>>00465000
double sectaddr;                                                        00470000
logical ldev;                                                           00475000
                                                                        00480000
logical condcode:=cce;                                                  00485000
logical notthisentry:=true;                                             00490000
                                                                        00495000
pdisable;                                                               00500000
tos:=dst(dstentrynumber&lsl(2)+2);                                      00505000
ldev:=ls0.(0:8);                                                        00510000
tos:=tos.(8:8);  <<hoda>>                                               00515000
tos:=dst(x:=x+1);  <<loda>>                                             00520000
sectaddr:=tos;                                                          00525000
vmpagesallocated:=dst(dstentrynumber&lsl(2)+1).vmalloc;                 00530000
                                                                        00535000
thisentryindex:=vdsmtab(startentryinxword);                             00540000
entrycount:=vdsmtab(vmsvolumecntword);                                  00545000
numbertried:=0;                                                         00550000
while numbertried <> entrycount and notthisentry do                     00555000
   begin                                                                00560000
   numbertried:=numbertried+1;                                          00565000
   if vdsmtab(thisentryindex+ldevword) = ldev then notthisentry:=false  00570000
   else thisentryindex:=vdsmtab(thisentryindex+nextinlistword);         00575000
   end;                                                                 00580000
                                                                        00585000
if vdsmtab(thisentryindex+ldevword) <> ldev then condcode:=ccl else     00590000
   begin <<found vdsmtab entry for device>>                             00595000
   tos:=sectaddr;                                                       00600000
   tos:=vdsmtab(thisentryindex+hostartsectorword);                      00605000
   tos:=vdsmtab(thisentryindex+lostartsectorword);                      00610000
   asmb(dsub);                                                          00615000
   if < then condcode:=ccl else                                         00620000
      begin                                                             00625000
    startingpage := integer(ds1/double(sectorspervmpage));     <<06558>>00630000
      if startingpage+vmpagesallocated > vdsmtab(thisentryindex+        00635000
         totalpagesword) then condcode:=ccl else                        00640000
         begin                                                          00645000
         bitmapabsbase:=sysbase+absolute(sysvdsmtab)                    00650000
                        +thisentryindex+offsettovdsbitmap;              00655000
         changestringinmap(bitmapabsbase,startingpage,vmpagesallocated, 00660000
            turnon);                                                    00665000
         if < then condcode:=ccl else                                   00670000
            begin <<pages properly deallocated>>                        00675000
            x:=totalvmpagesword;                                        00680000
            vdsmtab(x):=vdsmtab(x)+vmpagesallocated; <<global cnt>>     00685000
            tos:=vdsmtab(thisentryindex+availpagesword);                00690000
            tos:=tos+vmpagesallocated;                                  00695000
            vdsmtab(x):=ls0;                                            00700000
            vdsmtab(thisentryindex+smallestmissword):=tos;              00705000
            end;                                                        00710000
         end;                                                           00715000
      end;                                                              00720000
   end;                                                                 00725000
status.ccfld:=condcode;                                                 00730000
penable;                                                                00735000
end  <<releaseswapregion>>;                                             00740000
                                                                        00745000
                                                                        00750000
                                                                        00755000
                                                                        00760000
$page "VIRTUAL DISC SPACE MANAGEMENT : GET SWAP REGION"                 00765000
double procedure getswapregion(dstentrynumber,numberofwords,ldev);      00770000
value dstentrynumber,numberofwords,ldev;                                00775000
logical dstentrynumber,numberofwords,ldev;                              00780000
option privileged,uncallable;                                           00785000
                                                                        00790000
begin                                                                   00795000
                                                                        00800000
comment                                                                 00805000
                                                                        00810000
getswapregion allocates a region of virtual disc space from a           00815000
virtual memory supporting (vms) device.  the caller has acquired an     00820000
entry from the dst which is to be associated with the swap region,      00825000
and passes this entry number, along with the number of words of         00830000
swap region required, as calling parameters.  the caller may also       00835000
specify the ldev # on which the domain is to reside.                    00840000
                                                                        00845000
getswapregion checks the bitmap of the available virtual memory         00850000
space on the specified device or on the next device in the circular     00855000
list of vms devices for a set of contiguous free pages which will       00860000
satisfy the request.  if none is available and no device was            00865000
specified, the next device in the list is checked.  if the request      00870000
cannot be satisfied, 0d is returned.  otherwise, the ldev # and         00875000
disc address are returned, and the number of pages allocated for        00880000
the dst is recorded in the dst entry word 1.                            00885000
                                                                        00890000
;                                                                       00895000
                                                                        00900000
logical gotit:=false,                                                   00905000
        giveup:=false;                                                  00910000
                                                                        00915000
logical bitmapabsbase,                                                  00920000
        thisentryinx,                                                   00925000
        wordinmap,                                                      00930000
        totalwordsinmap,                                                00935000
        numbertried,                                                    00940000
        entrycount,                                                     00945000
        bitinword,                                                      00950000
        thisdevicenumber,                                               00955000
        startingpage,                                                   00960000
        stringlength,                                                   00965000
        swappagesreq;                                                   00970000
                                                                        00975000
subroutine locatestringofones;                                          00980000
                                                                        00985000
comment                                                                 00990000
                                                                        00995000
scans the bitmap which begins at absolute cell = bitmapabsbase          01000000
starting at bit 0 for a string of swappagesreq contiguous bits          01005000
which are on. if such a string is found, gotit is set                   01010000
to true, the bits are turned off, and the starting bit number           01015000
of the first allocated bit is recorded.                                 01020000
                                                                        01025000
;                                                                       01030000
                                                                        01035000
begin                                                                   01040000
                                                                        01045000
gotit:=false;                                                           01050000
wordinmap:=0;                                                           01055000
                                                                        01060000
tos:=absolute(bitmapabsbase+wordinmap);                                 01065000
                                                                        01070000
locatenextonbit:                                                        01075000
                                                                        01080000
asmb(test);                                                             01085000
while = and wordinmap < totalwordsinmap do                              01090000
   begin                                                                01095000
   wordinmap:=wordinmap+1;                                              01100000
   asmb(del);                                                           01105000
   tos:=absolute(x:=bitmapabsbase+wordinmap);                           01110000
   end;                                                                 01115000
                                                                        01120000
if wordinmap >= totalwordsinmap then asmb(del) else                     01125000
   begin <<this word has some available pages>>                         01130000
   asmb(scan);                                                          01135000
   startingpage:=logical(x)+wordinmap&lsl(4);                           01140000
   stringlength:=1;                                                     01145000
   bitinword:=x:=x+1;                                                   01150000
   tos:=tos&lsr(x);                                                     01155000
                                                                        01160000
   scanones :                                                           01165000
                                                                        01170000
   x:=bitinword;                                                        01175000
   asmb(trbc 0,x);                                                      01180000
   while <> and stringlength < swappagesreq and x <= 15                 01185000
   do                                                                   01190000
      begin                                                             01195000
      stringlength:=stringlength+1;                                     01200000
      x:=x+1;                                                           01205000
      asmb(trbc 0,x);                                                   01210000
      end;                                                              01215000
   if stringlength = swappagesreq then                                  01220000
      begin                                                             01225000
      asmb(del);                                                        01230000
      changestringinmap(bitmapabsbase,startingpage,swappagesreq,        01235000
        turnoff);                                                       01240000
if <> then suddendeath(632);                                   <<04293>>01245000
      gotit:=true;                                                      01250000
      end                                                               01255000
   else if x<>16 or absolute(bitmapabsbase+wordinmap).(15:1)<>1         01260000
   then go locatenextonbit <<hit end of string>> else                   01265000
      begin  <<end of word>>                                            01270000
      asmb(del);                                                        01275000
      wordinmap:=wordinmap+1;                                           01280000
      if wordinmap < totalwordsinmap then                               01285000
         begin <<continue scan>>                                        01290000
         tos:=absolute(bitmapabsbase+wordinmap);                        01295000
         bitinword:=0;                                                  01300000
         go to scanones;                                                01305000
         end;                                                           01310000
      end;                                                              01315000
   end;                                                                 01320000
end <<subroutine locatestringofones>>;                                  01325000
                                                                        01330000
pdisable;                                                               01335000
                                                                        01340000
swappagesreq:=(numberofwords-1)/vmpagesize+1;                           01345000
entrycount:=vdsmtab(vmsvolumecntword);                                  01350000
thisentryinx:=vdsmtab(startentryinxword);                               01355000
numbertried:=0;                                                         01360000
do                                                                      01365000
   begin <<try to get a region of sufficient size off this device>>     01370000
   numbertried:=numbertried+1;                                          01375000
   thisdevicenumber:=vdsmtab(thisentryinx+ldevword);                    01380000
   if ldev <> 0 and ldev <> thisdevicenumber then                       01385000
      begin <<skip this entry>>                                         01390000
      if numbertried=entrycount then giveup:=true                       01395000
      else thisentryinx:=vdsmtab(thisentryinx+nextinlistword);          01400000
      end                                                               01405000
   else                                                                 01410000
      begin                                                             01415000
      if vdsmtab(thisentryinx+availpagesword) < swappagesreq            01420000
      or vdsmtab(thisentryinx+smallestmissword) <= swappagesreq then    01425000
         begin <<this device is no good>>                               01430000
         thisentryinx:=vdsmtab(thisentryinx+nextinlistword);            01435000
         if ldev <> 0 and ldev = thisdevicenumber then giveup:=true;    01440000
         end                                                            01445000
      else                                                              01450000
         begin <<got a chance with this device>>                        01455000
         bitmapabsbase:=absolute(sysvdsmtab)+sysbase                    01460000
            +thisentryinx+offsettovdsbitmap;                            01465000
         totalwordsinmap:=vdsmtab(thisentryinx+wordsinbitmapword);      01470000
         locatestringofones;                                            01475000
         if not gotit then                                              01480000
            begin <<failed>>                                            01485000
            vdsmtab(thisentryinx+smallestmissword):=swappagesreq;       01490000
            thisentryinx:=vdsmtab(thisentryinx+nextinlistword); <<next>>01495000
            end;                                                        01500000
         end;                                                           01505000
      end;                                                              01510000
   end                                                                  01515000
until giveup or gotit or numbertried=entrycount;                        01520000
                                                                        01525000
if gotit then                                                           01530000
   begin <<successfully allocated a swap domain>>                       01535000
                                                                        01540000
   <<update number of pages available globally and on device>>          01545000
                                                                        01550000
   vdsmtab(totalvmpagesword):=vdsmtab(totalvmpagesword)-swappagesreq;   01555000
   if vdsmtab(totalvmpagesword) < vdsmtab(globleastavailpagesword)      01560000
   then vdsmtab(globleastavailpagesword):=vdsmtab(totalvmpagesword);    01565000
   x:=thisentryinx+availpagesword;                                      01570000
   vdsmtab(x):=vdsmtab(x)-swappagesreq;                                 01575000
if < then suddendeath(632);                                    <<04293>>01580000
   if vdsmtab(thisentryinx+availpagesword) < vdsmtab(thisentryinx+      01585000
   devleastavailpagesword)                                     <<jb.19>>01590000
   then vdsmtab(thisentryinx+devleastavailpagesword)           <<jb.19>>01595000
      :=vdsmtab(thisentryinx+availpagesword);                           01600000
                                                                        01605000
   <<advance the cyclic pointer for vm device selection>>               01610000
                                                                        01615000
   vdsmtab(startentryinxword):=vdsmtab(thisentryinx+nextinlistword);    01620000
                                                                        01625000
   <<calculate and return disc address>>                                01630000
                                                                        01635000
   tos:=vdsmtab(thisentryinx+hostartsectorword);                        01640000
   tos:=vdsmtab(thisentryinx+lostartsectorword);                        01645000
   tos:=0;                                                              01650000
   tos:=startingpage;                                                   01655000
   tos:=0;                                                              01660000
   tos:=sectorspervmpage;                                               01665000
   asmb(dmul;dadd); <<starting sector>>                                 01670000
   ls1.(0:8):=thisdevicenumber;                                         01675000
   getswapregion:=tos;                                                  01680000
   dst(dstentrynumber&lsl(2)+1).vmalloc:=swappagesreq;                  01685000
   end                                                                  01690000
else getswapregion:=0d;                                                 01695000
penable;                                                                01700000
end  <<getswapregion>>;                                                 01705000
                                                                        01710000
                                                                        01715000
<<=========================================================             01720000
=                                                         =             01725000
=                  end inclvmc                            =             01730000
=                                                         =             01735000
=========================================================>>             01740000
