$TITLE('ENTX V061A M01 === 080587)

NAME ENTX

;MODULE_DATA     SEGMENT WORD PUBLIC 'DATA'
;VERSION_MODULE  DB      '061A01'
;MODULE_DATA     ENDS

;******************************* MODULE HEADER *******************************;
;*									     *;
;*									     *;
;* MACHINE: B38		LANGUAGE: MASM V5.1   OS: CTOS II		     *;
;*									     *;
;* DESCRIPTION:								     *;
;*									     *;
;*		THIS MODULE CONTAINS THE 8086 MSPASCAL			     *;
;*		AND FORTRAN ENTRY AND EXIT POINTS.  			     *;
;*									     *;
;*									     *;
;*									     *;
;*									     *;
;*									     *;
;* HISTORY:								     *;
;*									     *;
;* MMDDYY VVVVMM PROGRAMMER     DESCRIPTION				     *;
;*									     *;
;* 080587 061A01 M. Chen        Modified 'Begxqq' to fix the stack	     *;
;*				    segment problem with PMOSS.  This 	     *;
;*				    initialization must also be done for V4  *;
;*				    run files.  We now take the RPL of the   *;
;*				    code segment and put it in SS.  	     *;
;*									     *;
;*									     *;
;* TITLE:  BTOS SYSTEM SOFTWARE						     *;
;*									     *;
;*			PROPRIETARY PROGRAM MATERIAL			     *;
;*									     *;
;* THIS MATERIAL IS PROPRIETARY TO UNISYS CORPORATION AND IS NOT TO BE       *;
;* REPRODUCED, USED OR DISCLOSED EXCEPT IN ACCORDANCE WITH PROGRAM LICENSE   *;
;* OR UPON WRITTEN AUTHORIZATION OF THE PATENT DIVISION OF UNISYS	     *;
;* CORPORATION, DETROIT, MICHIGAN 48232, USA.				     *;
;*									     *;
;* COPYRIGHT (C) 1980 CONVERGENT TECHNOLOGIES, INC. ALL RIGHTS RESERVED      *;
;* COPYRIGHT (C) 1987 UNISYS CORPORATION		                     *;
;* ************************************************************************* *;
;*									     *;
;* UNISYS BELIEVES THAT THE SOFTWARE FURNISHED HEREWITH IS ACCURATE AND      *;
;* RELIABLE, AND MUCH CARE HAS BEEN TAKEN IN ITS PREPARATION.  HOWEVER,      *;
;* NO RESPONSIBILITY, FINANCIAL OR OTHERWISE, CAN BE ACCEPTED FOR ANY        *;
;* CONSEQUENCES ARISING OUT OF THE USE OF THIS MATERIAL, INCLUDING LOSS OF   *;
;* PROFIT, INDIRECT, SPECIAL, OR CONSEQUENTIAL DAMAGES, THERE ARE NO         *;
;* WARRANTIES WHICH EXTEND BEYOND THE PROGRAM SPECIFICATION.		     *;
;*									     *;
;* THE CUSTOMER SHOULD EXERCISE CARE TO ASSURE THAT USE OF THE SOFTWARE      *;
;* WILL BE IN FULL COMPLIANCE WITH LAWS, RULES AND REGULATIONS OF THE        *;
;* JURISDICTIONS WITH RESPECT TO WHICH IT IS USED.			     *;
;*									     *;
;*									     *;
;*************************** END OF MODULE HEADER ****************************;

;  8086 MSPascalFORTRAN entry and exit points BEGXQQ and ENDXQQ
;  Convergent Technologies version;  requires CTOS operating system
;  Bob Wallace, Microsoft; original 780 (revised 1280 and 581)

PUBLIC INIFQQ               ;Dummy to avoid bringing runtime.
EXTRN   ENTGQQ:FAR             ;Main program entry point
EXTRN   EXIT:FAR               ;operating system exit point
EXTRN   ERROREXIT:FAR
EXTRN   WRITELOG: FAR
EXTRN fProtectedMode:FAR		; a CTOS routine

; ordering of segments must be enforced for V6 run files.  MDB

DGROUP  GROUP HEAP,STACK,DATA,MEMORY,CONST,EINQQQ,COMADS,COMADS_DATA,COMMON_DATA


;CT move MEMORY not to be overwritten by heap and stack  M.S.
;Memory segment definition (PLM)
;
MEMORY  SEGMENT PUBLIC 'MEMORY'
MEMORY  ENDS
;Heap segment definition (lowest segment)
;
HEAP    SEGMENT PUBLIC 'MEMORY'
HEAPGO  DW      1              ;allocated length zero block
HEAP    ENDS

; *** CT enhancement  PKD
;Memory segment definition (PLM)
;
;MEMORY  SEGMENT PUBLIC 'MEMORY'
;MEMORY  ENDS

;Stack segment definition (fixed length)
;
STACK   SEGMENT STACK 'STACK'
        DB      8192 DUP (?)
SKTOP   EQU     THIS BYTE
STACK   ENDS

;FIRST resident public data
;
DATA    SEGMENT PUBLIC 'DATA'
;   WriteLog message called by emseqq
PbMSG  DW      0FFF7h
CbMsg  DW      ?
Msg    DB      124 DUP(?)

PUBLIC  CSXEQQ                 ;pointer to sourcef context list
CSXEQQ  DW      0
PUBLIC  CLNEQQ                 ;last line number encountered
CLNEQQ  DW      0
PUBLIC  PNUXQQ                 ;pointer to unit initialization list
PNUXQQ  DW      0
PUBLIC  RESEQQ                 ;machine error context, stack ptr
RESEQQ  DW      0
PUBLIC  REFEQQ                 ;machine error context, frame ptr
REFEQQ  DW      0
PUBLIC  REPEQQ                 ;machine error context, program offset
REPEQQ  DW      0
PUBLIC  RECEQQ                 ;machine error context, program segment
RECEQQ  DW      0
PUBLIC  UPCX87                 ;offset address of 8087 error context
UPCX87  DW      0
PUBLIC  BEGHQQ                 ;first header word in heap
BEGHQQ  DW      0
PUBLIC  CURHQQ                 ;current heap item
CURHQQ  DW      0
PUBLIC  ENDHQQ                 ;just past end of the heap
ENDHQQ  DW      0
PUBLIC  STKBQQ                 ;stack start, to fix long GOTO
STKBQQ  DW      0
PUBLIC  STKHQQ                 ;stack limit, to check overflow
STKHQQ  DW      0

PUBLIC  ISPROTECTEDMODE	
ISPROTECTEDMODE	DB 0
DATA    ENDS

; *** CT enhancement  PKD
;COMADS segment definition for FORTRAN Commons

COMADS_DATA  SEGMENT PUBLIC 'COMADS'
COMADS_DATA  ENDS

COMADS SEGMENT PUBLIC 'COMADS'
COMADS ENDS


;Constant segment definition
;
CONST   SEGMENT PUBLIC 'CONST'
CONST   ENDS

;COMMON segment definition for FORTRAN Named Commons
;
COMMON_DATA  SEGMENT PUBLIC 'COMMON'
COMMON_DATA  ENDS
; end CT

COMMQQ SEGMENT COMMON 'COMMON'
COMMQQ ENDS
;
EINQQQ  SEGMENT WORD COMMON 'DATA'
InitializeCodeAddress   DD  1 DUP(?)
ExitCodeAddress         DD  1 DUP(?)
EINQQQ  ENDS


; dummy segments are used in Microsoft assembler files to break
; records so that the CT linker will be able to do overlays.  MDB

;COMMONDUMMY SEGMENT BYTE COMMON
;COMMONDUMMY ENDS

;DUMMY SEGMENT BYTE COMMON
;DUMMY ENDS

;Code for this module
;
ENTXQQ  SEGMENT 'CODE'
        ASSUME  CS:ENTXQQ,DS:DGROUP,ES:DGROUP,SS:DGROUP
;*** CT enhancement  PKD
ENTXQQ  ENDS
PUBLIC EMSEQQ  
;   EMSEQQ: this replaces the real emseqq in erre.pas.  
;           The routine will pass real time errors to
;           WRITELOG and ERROREXIT.
;   LTV21489
ENTXQQ  SEGMENT 'CODE'
EMSEQQ  PROC FAR
;assume ds:data,es:data
        push	bp
        mov 	bp,sp
        mov 	ax,[bp+12]
        mov     cx,ax
        inc 	ax
        mov     bx,offset CbMsg
        mov  	[bx],ax
        mov     di,offset Msg
        mov     si,[bp+10]
        inc     si
        inc     si
        rep movsb 
	    push 	ds
        mov     bx,offset PbMsg
        push  	bx
        add     ax,4
        push    ax
        call WRITELOG
        push    [bp+8]
        call ERROREXIT
EMSEQQ  ENDP
ENTXQQ  ENDS
PUBLIC  BEGXQQ,ENDXQQ          ;main entry and exit points
;PUBLIC  GETXQQ,TICBQQ          ;other CTOS dependent code
;*** CT enhancement  PKD
;ENDXQQ:  Termination code
;  call  EXIT   (operating system)

ENTXQQ  SEGMENT 'CODE'

ENDXQQ  PROC   FAR            ;termination entry point
	PUSH	BP
	MOV	BP,SP
;end CT
   
      CALL    EXIT           ;operating system termination
      HLT                    ;just in case exit doesn't
;*** CT 
		RET
ENDXQQ  ENDP
ENTXQQ  ENDS
;end CT
;

;BEGXQQ:  Initialization code
;  set initial stackpointer, framepointer, STKBQQ
;  call  INIX87 (real initialization)
;
;  For pasMID version:
;
;  set initial stackpointer STKBQQ
;  clear RESEQQ (machine error context)
;  clear CSXEQQ (sourcef error context)
;  clear PNUXQQ (unit init list header)
;  set BEGHQQ, CURHQQ, ENDHQQ, STKHQQ (heap init)
;
;  call  INIX87 (real initialization)
;
;
;
ENTXQQ  SEGMENT 'CODE'
BEGXQQ  PROC    FAR
        cli                    ;required by linkerswapper *** CT

; Initialize registers for V4 link.
        MOV     AX,DGROUP      ;get data segment value
        MOV     DS,AX          ;initialize data segment reg

; Set flag to indicate whether or not we're in protected mode.  Currently,
; the 87 emulator makes use of this flag.  MDB.
; We need to know this to set up the RPL field of the stack segment.   MEC

		CALL 	fProtectedMode
		MOV	BYTE PTR ISPROTECTEDMODE, AL

        MOV     AX,DGROUP      ;get data segment value
	MOV     DL,ISPROTECTEDMODE
        CMP     DL,0           ;is this protected mode?
        JE      SET            ;no, do nothing special to SS
        MOV     DX,CS          ;get the code segment value
        AND     DX,3           ;want the RPL field
        OR      AX,DX          ;set the RPL field in SS

SET:    MOV     SS,AX          ;initialize stack segment reg
        MOV     SP,OFFSET DGROUP:SKTOP  ;set stackpointer

        sti                    ;required by linkerswapper *** CT
        mov     bp, sp         ; SWAPPER requires initial BP = initial SP

        PUSH    DS             ; Make sure that DS and ES are the same.
        POP     ES             ; Some of our initialization code assumes
                               ; that they are.

;       <<<<<< Following lines of code from pasmax. >>>>>>

        MOV     STKBQQ,SP      ;to reinit BP after long GOTO
        SUB     STKBQQ,6       ;contains address of main frame
        SUB     AX,AX          ;initial frame pointer zero
        MOV     RESEQQ,AX      ;machine error context zero
        MOV     CSXEQQ,AX      ;sourcef error context NIL
        MOV     PNUXQQ,AX      ;unit init list header NIL
;
; Initialize short heap control addresses
;
        MOV     AX,OFFSET DGROUP:HEAPGO ;get initial heap
        MOV     BEGHQQ,AX      ;heap start address
        MOV     CURHQQ,AX      ;current heap pointer
        ADD     AX,2           ;point past heap
        MOV     ENDHQQ,AX      ;heap end address

;CT Give stack as much room as the linker will. M.S.

        ADD     AX,384         ;extra room for safety
        MOV     STKHQQ,AX      ;stack overflow check value

;
; Call real number initialization
;
        CMP     WORD PTR InitializeCodeAddress,0    ; Was init code linked in?
        JZ      DoneInitialize                      ; If not, skip call
        CALL    DWORD PTR InitializeCodeAddress     ; Init. floating pt.


DoneInitialize:

;       <<<<<< END OF CODE from pasmax. >>>>>>

;hand coded instruction for the 8087

; FINIT eliminated.  It seems to mischeivous and not important to the 
; operation of PasMin programs.  MDB.

;        db		0dbh,0e3h	            ;initialize 8087 (FNINIT)

        CALL    ENTGQQ         ;call main program
	CALL	ENDXQQ         ;*** CT
	ret                    ;*** CT
BEGXQQ  ENDP
ENTXQQ  ENDS                   ;*** CT

ENTXQQ  SEGMENT 'CODE'
INIFQQ  PROC FAR
        PUSH BP
        POP  BP
        RET
INIFQQ  ENDP
ENTXQQ  ENDS

;TICBQQ  returns an arbitrary current tenths of seconds value
;  called by BEGOQQ and ENDOQQ to give program runtime.
;  Only valid for Convergent Technologies operating system 
;
;TICBQQ  PROC    FAR
;        MOV     CX,0           ;constanttenths register
;        MOV     DX,10          ;multiplier for seconds
;        MOV     ES,CX          ;address OS data segment
;        MOV     BX,240H        ;time indirect address
;        MOV     AX,ES:[BX]     ;get offset of time struct
;        MOV     ES,ES:[BX+2]   ;get segment of time struct
;        MOV     BX,AX          ;now have address [LES?]
;        MOV     AX,ES:[BX+2]   ;get seconds
;        MOV     CL,ES:[BX+1]   ;get hundreths
;        MUL     DX             ;seconds times ten
;        ADD     AX,CX          ;plus hundreths
;        RET
;TICBQQ  ENDP

;GETXQQ transfers control to ALLOCMEMORYSL.  Since it has a 6 char
;name, its caller in MISHC.PAS can be compiled on the DEC10.
;
;GETXQQ  LABEL   FAR
;        JMP     ALLOCMEMORYSL

;ENTXQQ  ENDS

        END     BEGXQQ
