Trailing-Edge
-
PDP-10 Archives
-
BB-J845A-SM
-
source/stgman.p11
There are 30 other files named stgman.p11 in the archive. Click here to see a list.
.SBTTL STORAGE MANAGEMENT
;
; THIS SET OF SUBROUTINES GETS AND FREES CHUNKS AND MESSAGES.
; ALSO INCLUDED IN THIS SECTION ARE SUBROUTINES TO GET
; AND FREE TASK CONTROL BLOCKS.
;
.REPT 0
COPYRIGHT (c) 1980, 1979
DIGITAL EQUIPMENT CORPORATION, maynard, mass.
THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE
INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER
COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY
TRANSFERRED.
THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE
AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT
CORPORATION.
DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS
SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
.ENDR
;
;
;
; REVISION HISTORY
;
;
; 4(001) BS ADDED EDIT NUMBERS
;
;
;
VSTGMN=001
;
VEDIT=VEDIT+VSTGMN
;
;
;
; SUBROUTINE TO GET A TASK CONTROL BLOCK.
;
; ON RETURN:
;
; R0 = POINTER TO TCB. CALLER MUST FILL IN INITIAL
; ADDRESS AND PUT IN A TASK LIST.
;
; ON SUCCESS, C IS CLEAR. ON FAILURE, C IS SET.
;
GETTCB: MOV #TCSIZE,R0 ;LENGTH OF A TCB
JSR PC,GETSTG ;GET CORE FOR IT
BCS 12$ ;NOT AVAILABLE
MOV R0,-(SP) ;SAVE POINTER
MOV #STKLEN,R0 ;GET LENGTH OF TASK STACK
JSR PC,GETSTG ;GET STACK SPACE
BCS 11$ ;NOT AVAILABLE
MOV (SP)+,R1 ;GET TCB BACK
MOV R0,TCSPT(R1) ;STORE POINTER TO STACK BASE
ADD #STKLEN,R0 ;POINT TO END OF STACK
MOV R0,TCSP(R1) ;INITIALIZE STACK POINTER
MOV R1,R0 ;PUT TCB POINTER IN R0
.IIF NE,FTRACE,MOV TRCFLG,TCPS(R0) ;SET TRACE BIT IF REQUESTED
CLC ;FLAG SUCCESS
RTS PC ; AND RETURN.
;
; HERE IF THERE IS NOT SPACE FOR THE STACK. FREE THE TCB
; AND GIVE THE ERROR RETURN.
;
11$: MOV (SP)+,R0 ;GET POINTER TO TCB
JSR PC,FRESTG ;FREE IT
;
; HERE TO GIVE ERROR RETURN.
;
12$: SEC ;FLAG ERROR
RTS PC ; AND RETURN.
;
; SUBROUTINE TO FREE A TCB. R0 POINTS TO THE TCB.
;
FRETCB: MOV R0,-(SP) ;SAVE TCB POINTER
MOV TCSPT(R0),R0 ;POINT TO STACK
JSR PC,FRESTG ;FREE IT
MOV (SP)+,R0 ;GET BACK TCB POINTER
JSR PC,FRESTG ;FREE IT
RTS PC ; AND RETURN.
;
.SBTTL CHUNK PROCESSING
;
; SUBROUTINE TO GET A CONTINUOUS BLOCK FROM FREE STORAGE.
; IT GETS ENOUGH CONTIGUOUS CHUNKS TO MAKE UP THE
; NECESSARY AMOUNT.
;
; R0 CONTAINS THE NUMBER OF BYTES TO GET
; R5 POINTS TO THE TASK CONTROL BLOCK, OR 0 FOR
; INITIALIZATION.
;
; ON RETURN:
;
; R0 POINTS TO THE STORAGE, IF IT WAS AVAILABLE.
;
; C IS SET ON FAILURE, CLEAR ON SUCCESS
;
GETSTG: ADD #3,R0 ;INCREASE AMOUNT BY TWO...
BIC #1,R0 ; AND ROUND UP TO NEAREST WORD.
CLR -(SP) ; 10(SP) = TEMP CELL FOR LAST CHUNK WE TRIED FOR
MOV R0,-(SP) ; 6(SP) = FUDGED LENGTH
MOV R2,-(SP) ; 4(SP) = SAVED R2
CLR -(SP) ; 2(SP) = LIST OF CHUNKS GOTTEN ALREADY
CLR -(SP) ; (SP) = TEMP CELL FOR # BYTES TO GET
TST R5 ;ARE WE INITIALIZING?
BEQ 11$ ;YES.
MOV #10.,TCGMC(R5) ;NO, SET ERROR COUNTER.
11$: MOV CHHGH,R0 ;GET ADDRESS OF HIGHEST CHUNK
MOV R0,10(SP) ;REMEMBER LAST CHUNK WE TRIED FOR
JSR PC,14$ ;SEE IF CHUNK ON THE FREE LIST
BCS 18$ ;IT ISN'T.
JSR PC,GETCHK ;IT IS, TRY TO GET THE CHUNK
BCS 18$ ;BRANCH IF WE FAILED.
12$: MOV R0,2(SP) ;WE GOT IT, SAVE IT.
MOV 6(SP),(SP) ;SET NUMBER OF BYTES TO GET
13$: SUB #CHSIZE,(SP) ;NOTE WE GOT CHSIZE BYTES
BLE 21$ ;BRANCH IF WE HAVE ENOUGH
SUB #CHSIZE,R0 ;CALC ADDR OF PREV CHUNK IF ADJACENT
MOV R0,10(SP) ;SAVE ADDRESS OF LAST CHUNK WE TRIED FOR
JSR PC,14$ ;IS THIS CHUNK ON THE FREE LIST?
BCS 18$ ;NO, HOLE IN THE FREE LIST
JSR PC,GETCHK ;YES, TRY TO GET IT.
BCS 18$ ;IT'S NOT THERE
MOV 2(SP),(R0) ;GOT IT, PUT ON FRONT OF LIST
MOV R0,2(SP) ;STORE LONGER LIST
BR 13$ ;SEE IF THAT IS ENOUGH YET.
;
;
; SUBROUTINE TO VERIFY THAT THE DESIRED CHUNK IS ACTUALLY ON
; THE FREE LIST.
;
; R0 = POINTER TO CHUNK TO TEST
;
; ON RETURN:
;
; R0 STILL CONTAINS THE POINTER TO THE CHUNK
; C SET -- CHUNK IS NOT ON FREE LIST
; C CLEAR -- CHUNK IS ON FREE LIST.
;
14$: MOV CHFST,R1 ;GET POINTER TO FIRST CHUNK
BEQ 16$ ;NONE--NO FREE LIST(?)
15$: CMP R1,R0 ;IS IT THIS CHUNK?
BEQ 17$ ;YES, TRY TO GET IT.
MOV (R1),R1 ;NO, POINT TO NEXT CHUNK
BIT #1,R1 ;IS IT FREE?
BEQ 14$ ;NO, SEARCH THE LIST AGAIN
BIC #1,R1 ;YES, CLEAR "FREE" BIT
BNE 15$ ;IF NOT END OF LIST, CHECK THIS CHUNK
16$: SEC ;THIS CHUNK IS NOT ON THE FREE LIST
RTS PC ;GIVE ERROR RETURN.
;
; HERE IF THE CHUNK IS ON THE FREE LIST
;
17$: CLC ;OK RETURN
RTS PC ;RETURN.
;
;
; HERE WHEN WE HIT A HOLE IN THE FREE LIST. RELEASE WHAT WE'VE
; GOT AND TRY AGAIN.
;
18$: MOV 2(SP),R0 ;POINT TO LAST CHUNK WE GOT
BEQ 19$ ;NO MORE.
MOV (R0),2(SP) ;PICK OFF FRONT ITEM ON LIST
JSR PC,FRECHK ;FREE THIS CHUNK
BR 18$ ;FREE THE REST.
;
19$: TST R5 ;ARE WE INITIALIZING?
BEQ 25$ ;YES.
JSR PC,IDLTTM ;GETTING BEHIND?
BCC 25$ ;NO, DONT WAIT
MOV #2,TCTIM(R5) ;YES, WAIT 2 TICKS ONLY
MOV #EBTIME!EBWAIT,(R5) ;MARK WAITING
MOV R4,-(SP) ;SAVE R4
JSR PC,WAIT ;DO WAITING
MOV (SP)+,R4 ;RESTORE R4
25$:
MOV 10(SP),R0 ;POINT TO LAST CHUNK WE TRIED FOR
SUB #CHSIZE,R0 ;COMPUTE ADDRESS OF ADJACENT CHUNK
CMP R0,#FIRZER ;BEYOND END OF CHUNKS?
BLO 20$ ;YES, QUIT.
MOV R0,10(SP) ;NO, SAVE CHUNK ADDRESS
JSR PC,14$ ;SEE IF THIS CHUNK IS ON THE FREE LIST
BCS 19$ ;IT ISN'T. TRY NEXT.
JSR PC,GETCHK ;IT IS, TRY TO GET IT
BCS 19$ ;FAILED, TRY FOR ADJACENT CHUNK
BR 12$ ;SUCCESS, TRY TO GET SPACE FROM HERE.
;
; HERE WHEN WE HAVE RUN ALL THE WAY DOWN TO THE END OF THE
; FREE LIST WITHOUT FINDING ENOUGH SPACE. GIVE OTHER TASKS
; SOME CPU TIME AND TRY AGAIN FROM THE BEGINNING.
;
20$: TST R5 ;ARE WE INITIALIZING?
BEQ 23$ ;YES, FATAL ERROR.
MOV #2,TCTIM(R5) ;TIME TO WAIT
DEC TCGMC(R5) ;DECREMENT LOOP COUNTER
BEQ 23$ ;DONE IT ENOUGH, GIVE ERROR RETURN.
MOV #EBTIME!EBWAIT,(R5) ;MARK WAITING FOR TIME TO PASS
JSR PC,WAIT ;DO THE WAITING
BR 11$ ;IN 1-2 JIFFIES, TRY AGAIN.
;
;
; HERE WHEN WE FIND ENOUGH SPACE
;
21$: MOV (SP)+,R2 ;DELETE TEMP CELL FROM STACK
MOV (SP)+,R0 ;ADDRESS OF AREA GOTTEN
MOV 2(SP),R2 ;GET LENGTH IN BYTES (FUDGED)
MOV R2,(R0)+ ;STORE LENGTH AT -2 FROM AREA
SUB #2,R2 ;DECREMENT COUNT
ASR R2 ;MAKE WORD COUNT
MOV R0,R1 ;COPY ADDRESS
22$: CLR (R1)+ ;CLEAR A WORD IN THE AREA
SOB R2,22$ ; AND ALL THE REST
CLC ;CLEAR C TO INDICATE SUCCESS
BR GETST4 ;ALL DONE.
;
; HERE WHEN WE HAVE TRIED TOO OFTEN AND FAILED TO GET THE
; SPACE. CLEAR R0 AND SET C AS FLAGS.
;
23$: MOV (SP)+,R2 ;FIX THE STACK
MOV (SP)+,R2
SEC ;C FLAGS ERROR
;
; HERE WHEN IT IS TIME TO EXIT FROM GETSTG. REGISTER
; R0 CONTAINS EITHER THE AREA ADDRESS (WITH THE LENGTH WORD
; IN -2(R0) FOR FRESTG) OR A ZERO IF THE AREA IS NOT AVAILABLE.
;
GETST4: MOV (SP)+,R2 ;RESTORE R2
MOV (SP)+,R1 ;THROW AWAY LENGTH
MOV (SP)+,R1 ;THROW AWAY ADDRESS OF LAST CHUNK WE TRIED FOR
RTS PC ;RETURN FROM SUBROUTINE.
;
;
; SUBROUTINE TO RETURN AN AREA OF CORE TO FREE STORAGE.
; AT -2 OFFSET FROM THE START OF THE BLOCK IS THE LENGTH, FUDGED UP
; BY GETSTG. THE AREA IS DIVIDED INTO CHUNKS
; AND THE CHUNKS ARE RETURNED TO THE FREE LIST.
;
; R0 POINTS TO THE AREA TO BE FREED
;
FRESTG: MOV R1,-(SP) ;SAVE R1
TST -(R0) ;BACK UP ADDRESS TO COVER WHOLE AREA
MOV R0,-(SP) ;SAVE R0
MOV R2,-(SP) ;SAVE R2
MOV (R0),-(SP) ;NUMBER OF BYTES TO FREE
11$: MOV 4(SP),R0 ;CURRENT ADDRESS
JSR PC,FRECHK ;FREE THAT CHUNK
ADD #CHSIZE,4(SP) ;INCREMENT BASE ADDRESS
SUB #CHSIZE,0(SP) ;DECREMENT COUNT
BGT 11$ ;BRANCH IF MORE TO FREE
MOV (SP)+,R2 ;DISCARD TEMP CELL
MOV (SP)+,R2 ;RESTORE R2
MOV (SP)+,R0 ;DISCARD AREA ADDRESS
MOV (SP)+,R1 ;RESTORE R1
RTS PC ;RETURN TO CALLER
;
;
; SUBROUTINE TO REMOVE A CHUNK FROM THE FREE LIST
;
; R0 POINTS TO THE CHUNK TO BE REMOVED
;
; ON RETURN:
;
; R0 POINTS TO THE CHUNK OBTAINED, OR 0 IF THAT CHUNK
; WAS NOT AVAILABLE. C IS SET FOR FAILURE AND
; CLEARED FOR SUCCESS.
;
GETCHK: MFPS -(SP) ;SAVE INTERRUPT STATUS
MTPS #BR7 ;DISABLE INTERRUPTS
MOV CHFST,R2 ;POINTER TO FIRST CHUNK
CMP R2,CHLST ;IS IT ALSO LAST?
BEQ 13$ ;YES, DONT USE LAST CHUNK.
BIT #1,(R0) ;IS CHUNK STILL ON FREE LIST?
BEQ 13$ ;NO.
MOV 2(R0),R2 ;YES, GET PREDECESSOR
BEQ 15$ ;THERE IS NONE.
MOV (R0),(R2) ;THERE IS, POINT PRED AROUND OUR CHUNK
11$: MOV (R0),R2 ;GET SUCCESSOR
BIC #1,R2 ;CLEAR "FREE" BIT
BEQ 14$ ;NO SUCCESSOR, FIX UP CHLST.
MOV 2(R0),2(R2) ;THERE IS, POINT SUCC AROUND OUR CHUNK
12$: CLR (R0) ;CLEAR FORWARD POINTER AND FREE BIT
MTPS (SP)+ ;ENABLE INTERRUPTS
CLR 2(R0) ;CLEAR OUT CHUNK
DEC CHFREC ;DECREMENT COUNT OF FREE CHUNKS
TRACE TRCCNK,R0 ;TRACE EXIT FROM "GET A CHUNK"
.IF NE,CHOWNR
MOV R1,-(SP) ;SAVE R1
MOV 2(SP),R1 ;CHUNK ID IS CALLER OF GETCHK
JSR PC,CHOWNG ;RECORD CHUNK'S OWNER
MOV (SP)+,R1 ;RESTORE R1
.ENDC ;.IF NE,CHOWNR
CLC ;FLAG SUCCESS
RTS PC ;RETURN TO CALLER
;
;
; HERE WHEN THE CHUNK HAS BEEN SWIPED OFF THE FREE LIST BY
; INTERRUPT LEVEL, OR IF THE FREE LIST IS DOWN TO ONE
; CHUNK.
;
13$: MTPS (SP)+ ;ENABLE INTERRUPTS
CLR R0 ;CLEAR R0 AS A FLAG
TRACE TRCCNK,CHFREC ;TRACE UNSUCCESSFUL EXIT
SEC ; AND SET C
RTS PC ;GIVE ERROR RETURN TO CALLER
;
; HERE IF THE CHUNK IS LAST ON THE FREE LIST. WE MUST FIX UP
; CHLST.
;
14$: MOV 2(R0),CHLST ;POINT CHLST AROUND THE CHUNK
BR 12$ ; AND CONTINUE.
;
; HERE IF THE CHUNK IS FIRST ON THE FREE LIST. WE MUST FIX UP
; CHFST.
;
15$: MOV (R0),CHFST ;POINT CHFST AROUND THE CHUNK
BIC #1,CHFST ;CLEAR "FREE" BIT
BR 11$ ; AND CONTINUE.
;
;
; SUBROUTINE TO RETURN A CHUNK TO THE FREE LIST.
;
; R0 POINTS TO THE CHUNK
;
FRECHK: TRACE TRCCNK,R0 ;TRACE ENTRY TO "FREE A CHUNK"
.IIF NE,CHOWNR,JSR PC,CHOWNF ;MARK CHUNK FREE IN OWNER TABLE
MOV #CHSIZE/2,R2 ;LENGTH OF A CHUNK IN WORDS
MOV R0,R1 ;COPY THE ADDRESS
.IF NE,FT.CHK
CMP R0,#FIRZER ;ABOVE END OF PROGRAM?
BHIS 11$ ;YES.
STOPCD BAF ;NO, BAD ADDRESS IN FRECHK
11$: CMP R0,PHYLIM ;ABOVE END OF CORE?
BLO 12$ ;NO, ALL OK.
STOPCD BAF ;YES, BAD ADDRESS IN FRECHK
12$:
.ENDC ;.IF NE,FT.CHK
13$: CLR (R1)+ ;CLEAR A WORD OF THE CHUNK
SOB R2,13$ ;CLEAR ALL THE WORDS
14$: MFPS -(SP) ;SAVE INTERRUPT LEVEL
MTPS #BR7 ;DISABLE INTERRUPTS
MOV CHFST,R1 ;GET FIRST CHUNK ON LIST
MOV R0,CHFST ;MAKE OUR CHUNK FIRST
MOV R1,(R0) ;POINT TO REST OF LIST
BIS #1,(R0) ;SET "FREE" FLAG
MOV R0,2(R1) ;STORE US IN BACK POINTER
INC CHFREC ;INCREMENT COUNT OF FREE CHUNKS
MTPS (SP)+ ;RESTORE INTERRUPT LEVEL
RTS PC ;RETURN TO CALLER.
;