
(*   MODIFIED to get rid of absolute addresses *)

DEFINITION MODULE UnixMCI;
FROM SYSTEM IMPORT ADDRESS, WORD, PROCESS;
FROM SystemTypes IMPORT String;

EXPORT QUALIFIED 
    ArgPtr, GFTablePtr, 
    LoadedModule, LMTablePtr, ModuleData,
    ModuleDataPtr, 
    errnoPtr, argvPtr, envPtr, 
    GFTableSize, gFTablePtr, lMTablePtr, gFTableUpbPtr,
    endText, environPtr, mainProcessPtr;
    

TYPE 
     ArgPtr = POINTER TO ARRAY [0 .. 511] OF String;

CONST GFTableSize = 256;
(*  The maximum number of entries in the Global Frame table.
    The variable GFTableUpbPtr gives the index of the highest entry in use.
*)

TYPE 
    GFTablePtr = POINTER TO ARRAY [0 .. GFTableSize-1] OF ADDRESS;
    ModuleDataPtr = POINTER TO ModuleData;
    ModuleData =
    (*  this data is output by the compiler at the beginning of the
        code area of a module.  It is intended to be used by a
        Modula-2 debugger.
    *)
        RECORD
            codeLength: CARDINAL;
            procedureCount: CARDINAL;    (* number of procedures in module *)
            dataLength: CARDINAL;
        END;

    LoadedModule =
    (*  this data is output by the linker and is also intended for
        use by a debugging aid.
    *)
        RECORD
            name: String;  (* name of module associated with this slot *)
	    iName: String; (* null unless a different implementation was
                               loaded by the linker, in which case it is
                               the last part of the file-name.
                               Allows debugger to load correct symbol file.
                            *)
	    moduleData: ModuleDataPtr;
        END;

    LMTablePtr = 
        POINTER TO ARRAY [0 .. GFTableSize-1] OF LoadedModule;

(*  The absolute addresses assigned below correspond to the
    initialisation code output by the linker.
*)

VAR gFTablePtr  : GFTablePtr;
(*  A pointer to an array of pointers to the data frames of the 
    loaded modules. Unfilled slots not initialised.
*)

VAR lMTablePtr : LMTablePtr;
(*  A Pointer to An array of records containing pointers to the name,
    implementation name and compilation data, of the modules
    loaded in the corresponding slots of the Global Frame table.
    Unfilled slots are uninitialised.
*)

VAR gFTableUpbPtr  : POINTER TO CARDINAL;
(*  Pointer to a word containing the index of the highest 
    entry in the Global frame table which is in use.
*)
VAR errnoPtr  : POINTER TO INTEGER;
(*  A pointer to the word in which error return
    codes from system calls are placed.
*)
VAR endText : ADDRESS;
(*  the value of the symbol '_etext' as defined by 'ld', 
    i.e. the end of the program text area.
*)
VAR argvPtr : ArgPtr;
(*  Pointer to an array of pointers to the arguments passed to the
    program, terminated by a zero.  Actually `ArgvPtr^[0]' is the
    number of arguments, thus the zeroth argument (the program name)
    is pointed to by `ArgvPtr^[1]'. 
*)
VAR environPtr : POINTER TO ADDRESS;
(*  a pointer to the cell identified as '_environ', which
    must be set-up to point at the environment variables
    in order to use 'exec'.  This cell actually contains
    the value of 'EnvPtr' (see below)
*)    
VAR mainProcessPtr : POINTER TO PROCESS;
(*  a pointer to a hidden PROCESS variable which holds
    the identity of the main process.
*)

(*  The following variable is initialised by the implementation
    of this module
*)

VAR envPtr: ArgPtr;
(*  Pointer to an array of pointers to the environment strings,
    terminated by a zero.  The number of strings is not explicitly encoded.
*)
END UnixMCI .
