MACFLM	MACRO M1110  22-AUG-78 01:43  PAGE 3





      1						.IF NDF	W$$KST

      2

      3						.TITLE	GTCOR

      4

      5						.IFF

      6

      7						.TITLE	GTCOS

      8

      9						.ENDC

     10

     11						.IDENT	/02/

     12

     13					;

     14					; COPYRIGHT (C) 1976

     15					; DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.

     16					;

     17					; THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY ON A

     18					; SINGLE COMPUTER SYSTEM AND MAY  BE  COPIED   ONLY  WITH  THE

     19					; INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE,  OR

     20					; ANY OTHER COPIES THEREOF, MAY NOT BE PROVIDED  OR  OTHERWISE

     21					; MADE AVAILABLE TO ANY OTHER PERSON   EXCEPT FOR  USE ON SUCH

     22					; SYSTEM AND TO ONE WHO AGREES TO THESE LICENSE  TERMS.  TITLE

     23					; TO AND OWNERSHIP OF THE SOFTWARE SHALL AT ALL  TIMES  REMAIN

     24					; IN DEC.

     25					;

     26					; THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE WITHOUT

     27					; NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL

     28					; EQUIPMENT CORPORATION.

     29					;

     30					; DEC ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF

     31					; ITS SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DEC.

     32					;

     33					; VERSION 02

     34					;                                                                               ;**-1

     35					; C. MONIA 22-FEB-74

     36					;

     37					; MODIFICATIONS:

     38					;

     39					; NO.		DATE		PROGRAMMER

     40					; ---		----		----------

     41					;

     42					; 065		30-JUL-76	C. MONIA

     43					;

     44					; ALLOCATE DYNAMIC STORAGE

     45					;

     46					;+

     47					; **-GTCOR-ALLOCATE DYNAMIC STORAGE, DISPLACE VIRTUAL PAGE BUFFERS

     48					;

     49					; INPUTS:

     50					;

     51					;	R1=ALLOCATION REQUESTED(BYTES)

     52					;	$TPADR=NEXT VIRTUAL ADDRESS ABOVE TASK IMAGE

     53					;

     54					; OUTPUTS:

     55					;

     56					;	C-CLEAR: ALLOCATION REQUEST SUCCEEDED

     57					;

GTCOS	MACRO M1110  22-AUG-78 01:43  PAGE 3-1





     58					;	R0=ADDRESS OF STORAGE ALLOCATED

     59					;

     60					;	C-SET: ALLOCATION FAILED

     61					;

     62					; THIS ROUTINE IS CALLED TO OBTAIN DYNAMIC STORAGE. AN ATTEMPT IS MADE

     63					; TO ALLOCATE THIS MEMORY FROM THE EXISTING POOL. IF THIS FAILS, A REQ-

     64					; UEST TO EXTEND THE TASK IS ISSUED. IF THE REQUIRED MEMORY CANNOT BE OB-

     65					; TAINED THEN UNLOCKED PAGE BUFFERS ARE DISPLACED UNTIL THE REQUESTED SPACE

     66					; IS AVAILABLE. PAGE DISPLACEMENT IS ON THE BASIS OF 'LEAST RECENTLY USED'.

     67					;-

     68

     69	000000				$GTCOR::			;

     70	000000					SAVRG			; SAVE NON-VOLATILE REGISTERS

     71	000004				10$:				;

     72	000004	010146 				MOV	R1,-(SP)	; SAVE BYTE COUNT

     73	000006	012700 	000000G			MOV	#$FRHD,R0	; GET ADDRESS OF FREE CORE POOL

     74	000012					CALL	$RQCB		; REQUEST CORE BLOCK

     75	000016	103105 				BCC	60$		; IF C/C HAVE REQUESTED SPACE

     76

     77						.IF DF	W$$KST

     78

     79	000020	012703 	000000G			MOV	#$TPADR,R3	; GET POINTER TO NEXT FREE ADDRESS

     80	000024	011302 				MOV	(R3),R2		; GET NEXT FREE ADDRESS

     81	000026	020227 	000000G			CMP	R2,#T$KMAX	; TASK AT MAX. ALLOWABLE SIZE?

     82	000032	103011 				BHIS	17$		; IF HIS YES

     83	000034	012701 	000000G			MOV	#T$KINC,R1	; GET TASK INCREMENT (IN BYTES)

     84	000040					CALL	$EXTSK		; EXTEND THE TASK

     85	000044	103404 				BCS	17$		; IF C/S EXTEND FAILED

     86	000046	060167 	000000G			ADD	R1,$FRSIZ	; ADD INCREMENT TO POOL

     87	000052	060113 				ADD	R1,(R3)		; UPDATE TOP OF MEMORY

     88	000054	000457 				BR	47$		; RELEASE BLOCK TO POOL

     89	000056				17$:				;

     90	000056	012713 	177777 			MOV	#-1,(R3)	; BLOCK FURTHER ATTEMPTS TO EXTEND TASK

     91

     92						.ENDC

     93

     94					;

     95					; INSUFFICIENT STORAGE IS AVAILABLE. FREE UP MEMORY

     96					; BY DISPLACING PAGE BUFFERS

     97					;

     98

     99	000062	012704 	000000C			MOV	#<$PAGHD-P$GNXT>,R4 ; GET LISTHEAD ADDRESS MINUS OFFSET

    100	000066	005002 				CLR	R2		; CLEAR ADDRESS OF LRU PAGE

    101	000070	012703 	177777 			MOV	#-1,R3		; SET MAXIMUM TIME

    102	000074	005046 				CLR	-(SP)		; CLEAR LRU PREDECESSOR

    103	000076				20$:				;

    104	000076	010405 				MOV	R4,R5		; SAVE PREDECESSOR

    105	000100	016504 	000000G			MOV	P$GNXT(R5),R4	; GET NEXT PAGE

    106	000104	001413 				BEQ	30$		; IF EQ DONE

    107	000106	026403 	000000G			CMP	P$GTIM(R4),R3	; TEST TIME OF LAST USE VS. LEAST

    108	000112	101371 				BHI	20$		; IF HI, THIS BUFFER NOT LEAST

    109	000114	105764 	000000G			TSTB	P$GLOK(R4)	; THIS PAGE LOCKED IN MEMORY?

    110	000120	001366 				BNE	20$		; IF NE YES

    111	000122	010402 				MOV	R4,R2		; MARK BUFFER AS LRU

    112	000124	016403 	000000G			MOV	P$GTIM(R4),R3	; SAVE TIME

    113	000130	010516 				MOV	R5,(SP)		; SAVE PREDECESSOR FOR RELINK

    114	000132	000761 				BR	20$		; GO AGAIN

GTCOS	MACRO M1110  22-AUG-78 01:43  PAGE 3-2





    115	000134				30$:				;

    116	000134	005702 				TST	R2		; FIND LRU?

    117	000136	000261 				SEC			; ASSUME NO

    118	000140	001433 				BEQ	50$		; IF EQ NO

    119	000142	132762 	000000G	000000G		BITB	#PG$WRT,P$GSTS(R2) ; PAGE WRITTEN INTO ?

    120	000150	001402 				BEQ	40$		; IF EQ NO

    121	000152					CALL	$WRPAG		; WRITE OUT PAGE INTO VM

    122	000156				40$:				;

    123	000156	016703 	000000G			MOV	$PAGLS,R3	; GET ADDRESS OF PAGE LIST                      ;**NEW**

    124	000162	001406 				BEQ	45$		; IF EQ NONE                                    ;**NEW**

    125	000164	005000 				CLR	R0		; SET FOR MOVB WITH NO SIGN EXTEND              ;**NEW**

    126	000166	156200 	000000G			BISB	P$GBLK(R2),R0	; GET BLOCK NUMBER                              ;**NEW**

    127	000172	006300 				ASL	R0		; CONVERT TO WORD OFFSET                        ;**NEW**

    128	000174	060003 				ADD	R0,R3		; COMPUTE LOCATION IN LIST                      ;**NEW**

    129	000176	005013 				CLR	(R3)		; CLEAR ENTRY                                   ;**NEW**

    130	000200				45$:				;                                               ;**NEW**

    131	000200	012603 				MOV	(SP)+,R3	; RETRIEVE LRU PREDECESSOR

    132	000202	016263 	000000G	000000G		MOV	P$GNXT(R2),P$GNXT(R3) ; RELINK REMAINING PAGES

    133	000210	012701 	000000G			MOV	#P$GSIZ,R1	; SET SIZE TO RELEASE

    134	000214				47$:				;

    135	000214	012700 	000000G			MOV	#$FRHD,R0	; GET ADDRESS OF FREE POOL LISTHEAD

    136	000220					CALL	$RLCB		; RELEASE MEMORY

    137	000224	012601 				MOV	(SP)+,R1	; RESTORE COUNT

    138	000226	000666 				BR	10$		; GO AGAIN

    139	000230				50$:				;

    140	000230	005226 				INC	(SP)+		; CLEAN STACK, LEAVE C INTACT

    141	000232				60$:				;

    142	000232	005226 				INC	(SP)+		; CLEAN STACK

    143	000234					RETURN			;

    144

    145		000001 				.END

GTCOS	MACRO M1110  22-AUG-78 01:43  PAGE 3-3

SYMBOL TABLE



CR    = 000015   	P$GLOK= ****** GX	SPA   = 000040   	$FRHD = ****** GX	$RQCB = ****** GX

FF    = 000014   	P$GNXT= ****** GX	T$KINC= ****** GX	$FRSIZ= ****** GX	$SAVRG= ****** GX

HT    = 000011   	P$GSIZ= ****** GX	T$KMAX= ****** GX	$GTCOR  000000RG 	$TPADR= ****** GX

LF    = 000012   	P$GSTS= ****** GX	VT    = 000013   	$PAGHD= ****** GX	$WRPAG= ****** GX

PG$WRT= ****** GX	P$GTIM= ****** GX	W$$KST= 000000   	$PAGLS= ****** GX	$$    = 000001

P$GBLK= ****** GX	R$$11M= 000000   	$EXTSK= ****** GX	$RLCB = ****** GX



. ABS.	000000	   000

      	000236	   001

ERRORS DETECTED:  0



VIRTUAL MEMORY USED:  720 WORDS  ( 3 PAGES)

DYNAMIC MEMORY:  2772 WORDS  ( 10 PAGES)

ELAPSED TIME:  00:00:07

OBJ$:GTCOS,LIS$:GTCOS/-SP=SRC$:MACFLM,WRKST,GTCOR

