.title gsa3 - pashunfingaz toy for RMS v2.0 memory allocation ; we use "C" malloc() to give memory, then use $RQCB/$RLCB to massage it ; this version does NOT give memory back to "C", even if it could afford to ; this is different from gsa2 because it tells RMS it exists .ident /26OC84/ .psect GSA,I,RO,I,LCL,REL,CON ;+ ;*-GSA-general storage allocator used by RMSv2.0 uses malloc() of DECUS C ; See: "RSX-11M/M-PLUS RMS-11 Macro Programmer's Guide AA-L668A-TC" ; April 1983 (for RMS 2.0) section 7.5 page 7-18 ; for an example GSA -- CORE SPACE ALLOCATOR ;- .mcall gsa$ gsa$ gsa gsa:: ; (r0) = [head] ; (r1) = size ; (r2) = 0 or [chunk] jsr r5,$savrg ; preserve r3,r4,r5 tst r1 ; beq retn ; return if caller is silly (often RMS case) ; C reset: RMS seems to like this (kinky) ; ; here with finite size chunk to talk about tst r2 ; beq grab ; ; ; here to free memory jmp $rlcb ; it will return to our caller grab: ; here to grab memory mov r0,-(sp) ; [head] mov r1,-(sp) ; chunk size call $rqcb ; beg for memory bcc 69$ ; if win, 2 words to unstack, C is clear ; ; need to grab more memory from "C" mov @sp,r0 ; (r0) = size add #4,r0 ; just in case ; (r0) = siiiiize mov r0,-(sp) ; 3 temp words call malloc ; grovel for memory tst r0 ; beq 42$ ; if fail: C must be set, 3 words to clean up ; ; "C" gave us our memory ; (r0) = [chunk] mov r0,r2 ; (r2) = [chunk] mov (sp)+,r1 ; (r1) = siiiiize mov 2(sp),r0 ; (r0) = [head] call $rlcb ; feed it the new memory ; burp! ; now we expect to succeed mov (sp)+,r1 ; size caller requested mov (sp)+,r0 ; [head] clr r2 ; br grab ; try again 42$: ; pop 3 words and fail sec ; inc (sp)+ ; 69$: ; pop 2 words bit (sp)+,(sp)+ ; retn: ; return return ; .end ; END OF GSA3.MAC