home *** CD-ROM | disk | FTP | other *** search
- ****************************************************************************
- *
- * $RCSfile: DISPOSE.asm $
- * Description: Runtime support for the Oberon-A compiler
- *
- * Created by: fjc (Frank Copeland)
- * $Revision: 1.3 $
- * $Author: fjc $
- * $Date: 1994/07/24 18:24:34 $
- *
- * Copyright © 1994, Frank Copeland.
- * This file is part of the Oberon-A Library.
- * See Oberon-A.doc for conditions of use and distribution.
- *
- * Log entries are at the end of the file.
- *
- ****************************************************************************
- *
- * This file contains the MC68000 source code for part of the runtime
- * support library of the Oberon-A compiler. It contains the code to
- * implement the Oberon standard procedure SYSTEM.DISPOSE().
- *
- * Other parts of the runtime system may be found in the other files in
- * this directory. The object files resulting from assembling these
- * files are concatenated to create OberonSys.lib.
- *
- * This code is by definition *not* re-entrant and is not suitable for
- * creating shared-code libraries.
- *
- ****************************************************************************
-
- ;---------------------------------------------------------------------
- ; Program unit hunk name
- ; !! DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING !!
-
- TTL OberonSys
-
- ;---------------------------------------------------------------------
- ; Imports
-
- INCLUDE "OberonSys.i"
-
- ABSEXECBASE EQU 4
-
- FreeMem EQU -210
-
- ;---------------------------------------------------------------------
- ; Macros
-
- CALLSYS MACRO
- JSR \1(A6)
- ENDM
-
- ;---------------------------------------------------------------------
- ; PROCEDURE OberonSys_DISPOSE (
- ; var {D0} : ADDRESS)
- ;
- ; A call to this procedure is generated by the compiler when it
- ; translates a call to SYSTEM.DISPOSE (). The contents of the
- ; variable to be freed is passed in D0. The procedure first checks to
- ; see that the variable points to a block that has actually been
- ; allocated. If not it halts the program. If the variable is NIL then
- ; it returns without taking any action. Once it has confirmed the
- ; block is valid, it removes it from the list of allocated blocks and
- ; frees it.
- ;
- ; TYPE
- ; RecordBlkPtr = POINTER TO RecordBlk;
- ; RecordBlk = RECORD
- ; link, tag : ADDRESS;
- ; data : ...
- ; END;
- ; ArrayBlkPtr = POINTER TO ArrayBlk;
- ; ArrayBlk = RECORD
- ; arrpos, size : LONGINT;
- ; link, tag : ADDRESS;
- ; data : ...
- ; END;
- ; SysBlkPtr = POINTER TO SysBlk;
- ; SysBlk = RECORD
- ; link : ADDRESS;
- ; size : LONGINT;
- ; data : ...
- ; END;
- ;
- ; CONST NIL {D1} = 0;
- ;
- ; VAR mem {A1}, prev {A2}, next {A3} : ADDRESS;
- ; tag {A2} : ADDRESS;
- ; size {D0} : LONGINT;
- ;
- ;---------------------------------------------------------------------
-
- SECTION OberonSys,CODE
-
- XDEF OberonSys_DISPOSE
- XREF OberonSys_CLEANUP
-
- OberonSys_DISPOSE:
-
- MOVEQ.L #0,D1 ; D1 = NIL
- CMP.L D0,D1 ; IF var # NIL THEN
- BEQ 9$
- MOVE.L D0,A1 ; mem := var - 8
- SUBQ.L #8,A1
- MOVE.L A5,-(A7)
- LEA OberonSys_VAR,A5 ; Get base pointer for variables
- LEA OS_untraced(A5),A2 ; prev := ADR (untraced)
- MOVE.L OS_untraced(A5),A3 ; next := untraced;
- 1$
- CMPA.L D1,A3 ; WHILE (next # NIL)
- BEQ.S 2$
- CMPA.L A1,A3 ; & (next # mem) DO
- BEQ.S 2$
- MOVE.L A3,A2 ; prev := next
- MOVE.L (A3),A3 ; next := next.link
- BRA.S 1$ ; END
- 2$
- CMPA.L D1,A3 ; IF next = NIL THEN
- BNE.S 5$
- LEA OS_memList(A5),A2 ; prev := ADR (memList)
- MOVE.L OS_memList(A5),A3 ; next := memList;
- 3$
- CMPA.L D1,A3 ; WHILE (next # NIL)
- BEQ.S 4$
- CMPA.L A1,A3 ; & (next # mem) DO
- BEQ.S 4$
- MOVE.L A3,A2 ; prev := next
- MOVE.L (A3),A3 ; next := next.link
- BRA.S 3$ ; END
- 4$
- CMPA.L D1,A3 ; IF next = NIL THEN
- BNE.S 5$
- ; HALT (OS_DisposeFail)
- MOVE.L #OS_DisposeFail,OS_returnCode(A5)
- BRA OberonSys_CLEANUP
- ; END (* IF *)
- 5$ ; END (* IF *)
- MOVE.L (A7)+,A5 ; Restore registers
- MOVE.L (A3),(A2) ; prev.link := next.link
- MOVE.L 4(A1),D1
- BTST #0,D1 ; IF 0 IN mem.tag THEN
- BEQ.S 6$
- MOVE.L D1,D0 ; size := mem.tag + 7
- ADDQ #7,D0
- BRA.S 8$
- 6$
- BTST #1,D1 ; ELSIF 1 IN mem.tag THEN
- BEQ.S 7$
- SUBQ.L #8,A1 ; DEC (mem, 12);
- SUBQ.L #4,A1
- MOVE.L 8(A1),D0 ; size := mem.size + 20
- ADD.L #20,D0
- BRA.S 8$
- 7$ ; ELSE
- MOVEA.L 4(A1),A0 ; size := mem.tag.size + 8
- MOVE.L (A0),D0
- ADDQ.L #8,D0
- 8$ ; END;
- MOVE.L ABSEXECBASE,A6
- CALLSYS FreeMem ; FreeMem(mem,size)
- 9$ ; END (* IF *)
- RTS
-
- ;---------------------------------------------------------------------
-
- END ; OberonSys
-
- ****************************************************************************
- *
- * $Log: DISPOSE.asm $
- * Revision 1.3 1994/07/24 18:24:34 fjc
- * - Changed code far calling HALT().
- *
- * Revision 1.2 1994/05/12 20:31:15 fjc
- * - Prepared for release
- *
- * Revision 1.1 1994/01/15 18:31:52 fjc
- * Start of revision control
- *
- * (12 Jan 1994) Modified to handle change in ArrayBlk (elemSize added)
- * Modified to assemble with PhxAss instead of A68K
- * ( 4 Jan 1994) Complete rewrite as part of implementation of the
- * garbage collector.
- * ( 9 Jul 1993) Changed return code to OS_DisposeFail.
- * (28 Jun 1993) Changed the way it handles the sizeTag field.
- * General overhaul.
- * (29 May 1993) Split OberonSys.asm into several files to create
- * OberonSys.lib.
- *
- ****************************************************************************
-
-