/* This C language subroutine provides heap memory management for the runtime library. The Run Time Library for the C Language. Gordon A. Sterling (617) 461 - 3076 DSP Development Tools Engineering Created on 12/9/90 Updated on 1/95 by AS - separated polymorphic functions #include
void free(void *p); */ #include "lib_glob.h" #include "sdl_glob.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL ___freeP; ___freeP: put(R3); put(R5); put(R6); put(R7); put(R13); put(R14); put(R15); CALL ___lib_get_heap_data (DB); /*Read heap information*/ R2=PASS R4, pm_ptr=R4; R3=PM(pm_M1, pm_ptr); /*Read heap number*/ R0=PASS R2; /*Test for zero input*/ IF EQ JUMP (PC, restore_state); /*Return NULL ptr*/ R2=R2-1, dm_lnt=dm_0; /*Pt to heap #, clr len regs*/ R2=R2-1, pm_lnt=pm_0; /*Pt to heap len,clr len regs*/ pm_deallocation:R14=R14-R14, pm_ptr=R2; /*Set to 0 for unsigned comp*/ PM(1,pm_ptr)=R14; /*Write out a NULL*/ R0=PASS R4, pm_ptr=R4; /*Test for NULL ptr*/ IF EQ JUMP (PC, restore_state); /*ERROR if NULL*/ R3=PASS R0, R0=PM(1,pm_ptr); /*Fetch next ptr*/ DO scan_free_pm UNTIL EQ; R13=R0-R2; /*Do an unsigned compare*/ NOP; /*CHIP ANOMALY: Late carry*/ R13=R14-R14+CI-1; /*Extend to double*/ IF GE JUMP (PC, check_postblk_pm) (LA);/*In middle*/ R0=PASS R0, pm_ptr=R0; IF EQ JUMP (PC, check_preblk_pm) (LA);/*At the end of list*/ R15=PASS R3, R3=R0; scan_free_pm: R0=PM(1,pm_ptr); /* Test if the de-allocated block is contigious with the end block*/ check_postblk_pm:pm_ptr=R2; /*Point to length*/ R4=PM(pm_ptr,0); /*Fetch length*/ R5=R2+R4; /*Figure end address*/ R5=R5+1; /*Compute contig. blk add*/ R5=R5+1; COMP(R0,R5); /*Test for equal*/ IF NE PM(1,pm_ptr)=R0; /*Not contigious*/ IF NE JUMP (PC, check_preblk_pm); pm_ptr=R0; /*Point to next block*/ R6=PM(pm_ptr,0); /*Fetch length*/ R6=R6+1, R7=PM(1,pm_ptr); /*Include extra block*/ R6=R6+1; R6=R6+R4, pm_ptr=R2; /*Add initial block*/ PM(pm_ptr,0)=R6; /*Write new length*/ pm_ptr=R2; PM(1,pm_ptr)=R7; /*Copy pointer*/ check_preblk_pm:pm_ptr=R3; /*Point to previous block*/ R4=PM(pm_ptr,0); /*Fetch length*/ R5=R3+R4; /*Compute end address*/ R5=R5+1; /*Include extra blk*/ R5=R5+1; COMP(R2,R5); /*Test for equal*/ IF NE PM(1,pm_ptr)=R2; /*Set previous ptr*/ IF NE JUMP (PC, restore_state); pm_ptr=R2; /*Point to block*/ R6=PM(pm_ptr,0); /*Fetch length*/ R6=R6+1, R7=PM(1,pm_ptr); /*Include extra block*/ R6=R6+1; R6=R6+R4, pm_ptr=R3; /*Compute total length*/ PM(pm_ptr,0)=R6; /*Write out new length*/ PM(1,pm_ptr)=R7; restore_state: FETCH_RETURN get(R15,1); get(R14,2); get(R13,3); get(R7,4); get(R6,5); get(R5,6); get(R3,7); RETURN (DB); RESTORE_STACK RESTORE_FRAME .ENDSEG;