home *** CD-ROM | disk | FTP | other *** search
- ****************************************************************************
- *
- * $RCSfile: OberonSys.asm $
- * Description: Runtime support for the Oberon-A compiler
- *
- * Created by: fjc (Frank Copeland)
- * $Revision: 1.3 $
- * $Author: fjc $
- * $Date: 1994/07/24 18:26:38 $
- *
- * 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 program
- * startup and exit code and the variables used by the runtime system.
- *
- * 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.
- *
- * Acknowledgements
- * ----------------
- *
- * The startup and exit code is based on the standard Commodore startup
- * code provided with the Native Developers kit for Kickstart 2.04.
- *
- **********************************************************************
-
- ;---------------------------------------------------------------------
- ; Program unit hunk name
-
- TTL OberonSys
-
- ;---------------------------------------------------------------------
- ; Imports
-
- ABSEXECBASE EQU 4
-
- FindTask EQU -294
- Forbid EQU -132
- FreeMem EQU -210
- GetMsg EQU -372
- ReplyMsg EQU -378
- WaitPort EQU -384
- OpenLibrary EQU -552
- CloseLibrary EQU -414
-
- tcTrapData EQU 46
- tcTrapCode EQU 50
- prMsgPort EQU 92
- prCLI EQU 172
-
- OS_MathFail EQU 21
-
- ;---------------------------------------------------------------------
- ; Macros
-
- CALLSYS MACRO
- JSR \1(A6)
- ENDM
-
- ;---------------------------------------------------------------------
-
- ;---------------------------------------------------------------------
- ; PROCEDURE OberonSys_INIT (
- ; dosCmdLen {D0} : LONGINT;
- ; dosCmdBuf {A0} : LONGINT;
- ; initialSP {A6} : LONGINT)
- ;
- ; This procedure is called by the code prologue of the main
- ; program module. A6 contains the initial stack pointer, put
- ; there by the code prologue of the main program module. A0 and
- ; D0 contain the parameters passed by AmigaDOS.
- ;---------------------------------------------------------------------
-
- SECTION OberonSys,CODE
-
- XDEF OberonSys_INIT
-
- OberonSys_INIT:
-
- LEA OberonSys_VAR,A5 ; Get base pointer for variables
- MOVE.L A6,(A5) ; Save initialSP
- MOVE.L D0,OS_argLen(A5) ; Save dosCmdLen
- MOVE.L A0,OS_args(A5) ; Save dosCmdBuf
-
- MOVE.L ABSEXECBASE,A6 ; Get Exec library base pointer
-
- ; Get pointer to our task
-
- SUBA.L A1,A1 ; Clear A1
- CALLSYS FindTask
- MOVE.L D0,A4 ; Store it in A4
-
- ; Check if program started from CLI or Workbench
-
- MOVE.L prCLI(A4),D0
- BNE.S continueINIT ; CLI, branch around Workbench code
-
- ;---------------------------------------------------------------------
- ; Workbench startup code
- ;
- ; Inputs
- ;
- ; A4 : Task
- ; A5 : OberonSys_VAR
- ; A6 : ABSEXECBASE
-
- ; Indicate this is a Workbench program
- MOVEQ #-1,D0
- MOVE.L D0,OS_argLen(A5)
-
- ; Get the startup message
-
- LEA prMsgPort(A4),A0 ; Process message port
- CALLSYS WaitPort
- LEA prMsgPort(A4),A0 ; Process message port
- CALLSYS GetMsg
-
- ; Save it
-
- MOVE.L D0,OS_args(A5)
-
- continueINIT:
-
- CLR.L OS_returnCode(A5) ; Lets be optimistic about this
- CLR.L OS_cleanupProc(A5) ; Set cleanupProc to NIL
-
- ; Install trap handler. Task base is still in A4 (I hope)
-
- MOVE.L tcTrapData(A4),OS_oldTrapData(A5)
- MOVE.L tcTrapCode(A4),OS_oldTrapCode(A5)
- CLR.L tcTrapData(A4)
- LEA OberonSys_TrapHandler,A0
- MOVE.L A0,tcTrapCode(A4)
-
- ; Open mathffp.library
-
- LEA mathName(PC),A1
- MOVEQ #33,D0
- CALLSYS OpenLibrary ; Exec.OpenLibrary (mathName,33)
- MOVE.L D0,OS_mathBase(A5) ; Save math base pointer
-
- TST.L D0 ; If open OK, exit
- BNE.S exitINIT
-
- ; If open failed, abort program
-
- MOVE.L #OS_MathFail,OS_returnCode(A5)
- BRA OberonSys_CLEANUP
-
- exitINIT:
- RTS ; Back to the module
-
- ;---------------------------------------------------------------------
- ; PC relative data
-
- mathName DC.B "mathffp.library",0
-
- ;---------------------------------------------------------------------
- ; PROCEDURE OberonSys_CLEANUP ()
- ;
- ; This procedure is called by the code prologue of the main
- ; program module. It is the last code to be executed and it
- ; returns to the program's calling process. D0 contains
- ; the program's return code.
- ;---------------------------------------------------------------------
-
- SECTION OberonSys,CODE
-
- XDEF OberonSys_CLEANUP
-
- OberonSys_CLEANUP:
-
- LEA OberonSys_VAR,A5 ; Get base pointer for variables
- MOVE.L (A5),A7 ; Restore initial stack pointer
-
- ; Execute cleanup procedures
-
- TST.L OS_cleanupProc(A5) ; Is there a cleanup procedure?
- BEQ.S 1$ ; If not, branch around
- MOVEA.L OS_cleanupProc(A5),A3 ; Get the first node
- CLR.L OS_cleanupProc(A5) ; NIL the list, to avoid loops
- 3$
- MOVE.L A3,-(A7) ; save the node pointer
- MOVE.L 4(A3),A3 ; call the procedure
- JSR (A3)
- MOVE.L (A7)+,A3 ; restore the node pointer
- TST.L (A3) ; is there another procedure?
- BEQ.S 1$ ; no
- MOVE.L (A3),A3 ; get the next node
- BRA.S 3$ ; loop
-
- 1$
- MOVE.L ABSEXECBASE,A6 ; Get Exec library base pointer
-
- ; Free allocated memory blocks
-
- MOVE.L OS_untraced(A5),A2
- JSR OberonSys_FreeMem
- MOVE.L OS_memList(A5),A2
- JSR OberonSys_FreeMem
-
- ; Close math library
-
- MOVE.L OS_mathBase(A5),A1
- CALLSYS CloseLibrary
-
- ; Get pointer to our task
-
- SUBA.L A1,A1 ; Clear A1
- CALLSYS FindTask
- MOVE.L D0,A4 ; Store it in A4
-
- ; Restore default trap handler
- MOVE.L OS_oldTrapCode(A5),tcTrapCode(A4)
- MOVE.L OS_oldTrapData(A5),tcTrapData(A4)
-
- ; Check if program started from CLI or Workbench
- CMPI.L #-1,OS_argLen(A5)
- BNE.S 2$ ; CLI, branch around Workbench code
-
- ; Workbench cleanup code
-
- CALLSYS Forbid ; Stop Workbench unloading us
- MOVE.L OS_args(A5),A1 ; Get startup message
- CALLSYS ReplyMsg
-
- 2$
- MOVE.L OS_returnCode(A5),D0; Set return code
-
- RTS ; Back to the calling process
-
-
- ;---------------------------------------------------------------------
- ; PROCEDURE OberonSys_FreeMem
- ;
- ; This procedure traverses a list of allocated memory blocks and
- ; frees them using the Exec function FreeMem ().
- ;
- ; Inputs
- ;
- ; A2 : memory list
- ; A6 : ABSEXECBASE
- ;
- ; Variables
- ;
- ; A0 : tag
- ; A1 : mem
- ; A2 : next
- ; D0 : size
- ; D1 : tag
- ; D2 : NIL
- ;---------------------------------------------------------------------
-
- SECTION OberonSys,CODE
-
- OberonSys_FreeMem:
-
- MOVEQ.L #0,D2 ; D2 = NIL
- 1$
- CMPA.L D2,A2 ; WHILE next # NIL DO
- BEQ.S 5$
- MOVE.L A2,A1 ; mem := next
- MOVE.L (A2),A2 ; next := next.link
- MOVE.L 4(A1),D1
- BTST #0,D1 ; IF 0 IN mem.tag THEN
- BEQ.S 2$
- MOVE.L D1,D0 ; size := mem.tag + 7
- ADDQ #7,D0
- BRA.S 4$
- 2$
- BTST #1,D1 ; ELSIF 1 IN mem.tag THEN
- BEQ.S 3$
- SUBQ.L #8,A1 ; DEC (mem, 12);
- SUBQ.L #4,A1
- MOVE.L 8(A1),D0 ; size := mem.size + 20
- ADDI.L #20,D0
- BRA.S 4$
- 3$ ; ELSE
- MOVEA.L 4(A1),A0 ; size := mem.tag.size + 8
- MOVE.L (A0),D0
- ADDQ.L #8,D0
- 4$ ; END;
- CALLSYS FreeMem ; FreeMem(mem,size)
- BRA.S 1$ ; END
- 5$
- RTS
-
- ;---------------------------------------------------------------------
- ; PROCEDURE OberonSys_TrapHandler ()
- ;
- ; This procedure is installed as the task's trap handler routine
- ; by OberonSys_INIT. It's job is to get the trap number, then
- ; exit Supervisor mode as soon as possible. If the trap number
- ; is one it understands, it passes control to OberonSys_Traps,
- ; otherwise it passes it on to the default trap handler.
- ;
- ; This is loosely based on the example in the RKM:Libraries,
- ; Ch 21.
- ;---------------------------------------------------------------------
-
- SECTION OberonSys,CODE
-
- XDEF OberonSys_TrapHandler
-
- OberonSys_TrapHandler:
-
- MOVE.L (SP)+,D0 ; Recover the trap number and
- ; adjust the stack.
-
- LEA OberonSys_Traps,A0 ; Con the CPU into thinking it came
- MOVE.L A0,2(SP) ; from OberonSys_Traps
-
- RTE ; Return to OberonSys_Traps
-
- ;---------------------------------------------------------------------
- ; PROCEDURE OberonSys_Traps
- ; ( trapNo {D0} : LONGINT )
- ;
- ; This carries out the actual processing of traps in User mode.
- ; The default action is to jump to OberonSys_CLEANUP with a
- ; return code of trapNo + 100. If a trap handler routine has
- ; been defined, it will be called instead.
- ;
- ; The trap number is passed by OberonSys_TrapHandler in D0.
- ;---------------------------------------------------------------------
-
- SECTION OberonSys,CODE
-
- XDEF OberonSys_Traps
-
- OberonSys_Traps:
-
- ADDI.L #100,D0
- LEA OberonSys_VAR,A5
- MOVE.L D0,OS_returnCode(A5)
- JMP OberonSys_CLEANUP ; HALT (trapNo + 100)
- ; RTS ; never reached
-
-
- ;---------------------------------------------------------------------
- ; The following section defines a generic type descriptor which
- ; describes a record with a single pointer field. This is passed to
- ; OberonSys_NEW when allocating a POINTER TO ARRAY OF POINTER TO ...
- ; variable.
- ;---------------------------------------------------------------------
-
- SECTION OberonSys,DATA
-
- XDEF OberonSys_TYPE_0
-
- OberonSys_TYPE_0:
-
- DC.L 4 ; size of type
- DC.L 0,0,0,0,0,0,0,0 ; type tag table, set to NILs
- DC.L 0 ; offset of pointer field
- DC.L -40 ; offset to start of descriptor
- DC.B 0 ; empty string for type name
-
- ;---------------------------------------------------------------------
-
- SECTION OberonSys,BSS
-
- XDEF OberonSys_VAR
- XDEF OS_initialSP
- XDEF OS_argLen
- XDEF OS_args
- XDEF OS_returnCode
- XDEF OS_cleanupProc
- XDEF OS_memList
- XDEF OS_mathBase
- ;XDEF OS_lmathBase
- XDEF OS_untraced
- XDEF OS_GCVars
-
- OberonSys_VAR: ; Start of OberonSys variables
-
- OS_initialSP EQU 0
- DS.L 1 ; Initial stack pointer on entry to program.
- ; Initialised by OberonSys_INIT.
-
- OS_argLen EQU 4
- DS.L 1 ; Length of the Command line passed to the program
- ; by DOS in D0. Initialised by OberonSys_INIT. A
- ; value of -1 indicates that the program was
- ; started by Workbench. Returned by
- ; SYSTEM.ARGLEN ().
-
- OS_args EQU 8
- DS.L 1 ; If argLen >= 0, the command line passed to the
- ; program by DOS in A5. Otherwise, the address of
- ; the message sent to the program by Workbench.
- ; Initialised by OberonSys_INIT. Returned by.
- ; SYSTEM.ARGS ().
-
- OS_returnCode EQU 12
- DS.L 1 ; Value returned by the program in D0 on exit.
- ; Initialised to 0 by OberonSys_INIT. Set by the
- ; HALT standard procedure.
-
- OS_cleanupProc EQU 16
- DS.L 1 ; Contains the address of a procedure to be
- ; executed as part of the cleanup when the program
- ; exits. Initialised to NIL by OberonSys_INIT.
- ; Set by SYSTEM.SETCLEANUP (). Returned by
- ; SYSTEM.GETCLEANUP ().
-
- OS_memList EQU 20
- DS.L 1 ; Contains a pointer to the head of a linked list
- ; of memory blocks used by the garbage collector in
- ; its sweep phase. Initialised to NIL by
- ; OberonSys_INIT. The list is traversed by
- ; OberonSys_CLEANUP and all the memory blocks are
- ; freed.
-
- OS_mathBase EQU 24
- DS.L 1 ; Contains the base pointer of mathffp.library.
- ; This library is used for all floating point
- ; arithmetic and is automatically opened and
- ; closed by OberonSys_INIT and OberonSys_CLEANUP.
-
- OS_lmathBase EQU 28
- DS.L 1 ; Not used yet. It will eventually be used to
- ; hold the base pointer for
- ; mathieeedoubbas.library to be used for long
- ; floating point math.
-
- OS_oldTrapCode EQU 32
- DS.L 1 ; Stores the default trap handler on entry to the
- ; program. Restored on exit.
-
- OS_oldTrapData EQU 36
- DS.L 1 ; Stores the default trap data on entry to the
- ; program. Restored on exit.
-
- OS_untraced EQU 40
- DS.L 1 ; Contains a pointer to the head of a linked list
- ; of memory blocks ignored by the garbage collector
- ; in its sweep phase. Initialised to NIL by
- ; OberonSys_INIT. The list is traversed by
- ; OberonSys_CLEANUP and all the memory blocks are
- ; freed.
-
- OS_GCVars EQU 44
- DS.L 1 ; Contains a pointer to the head of a linked list
- ; of hunks containing the offsets of global
- ; pointer variables.
-
- ;---------------------------------------------------------------------
-
- END ; OberonSys
-
- ****************************************************************************
- *
- * $Log: OberonSys.asm $
- * Revision 1.3 1994/07/24 18:26:38 fjc
- * - Changed initialisation code.
- * - Changed code for calling HALT().
- * - Changed code for calling cleanup procedures.
- *
- * 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
- * ( 5 Jan 1994) Defined generic pointer type descriptor.
- * ( 4 Jan 1994) Made modifications required by changes to the memory
- * management system.
- * (28 Aug 1993) Added trap handling code.
- * ( 9 Jul 1993) Added code to open and close mathffp.library.
- * (28 Jun 1993) Changed memory deallocation on exit in line with
- * changes made in OberonSys_NEW and OberonSys_DISPOSE.
- * (29 May 1993) Split OberonSys.asm into several files to create
- * OberonSys.lib.
- * ( 2 May 1993) First stab at it.
- *
- ****************************************************************************
-
-