;       SCCSID = @(#)dosseg.inc 6.3 91/05/02

;       Segment declarations and ordering for OS/2 kernel.
;       All kernel .DEF file segment attributes are also specified
;       in this file.  Each segment declaration is followed by
;       a special comment "DEF:" (immediatley preceded by two semicolons)
;       if segment attributes are to be propagated to the .DEF file.
;       To maintain group order, when a segment attribute is propagated
;       to the .DEF file, the first segment in each prior group must also
;       be propagated.
;
;       The following comment is propagated as well:
;
;;DEF:  Segment attributes are mechanically extracted from a kernel
;;DEF:  include file containing segment declarations (dosseg.inc).
;;DEF:
;;DEF:  PRELOAD tells the boot loader to tile the segment
;;DEF:  FIXED tells the boot loader the segment must reside in low memory
;;DEF:  IOPL tells the boot loader to disallow FLAT references
;;DEF:  NONSHARED tells the boot loader the object is MVDM instance data
;;DEF:  RESIDENT tells the boot loader the object is non-swappable

FALSE           equ     0
TRUE            equ     -1
RETFOFFSET      equ     1       ; offset for faronly thunk returns
RETFDOFFSET     equ     2       ; offset for far16 thunk returns

.386p                           ; Enable 386 protected instructions
                                ; and pure code checking

?cseg = 0                       ; count of segments within a group
?cgroup = 0                     ; running group number
?fretfdlabel = 0                ; true after retfd label generated

% ifdif <@FileName>,<ibmdos>
    ?fibmdos = 0                ; if NOT included from ibmdos.asm
elseifdef MISCSTRICT
    ?fibmdos = 2                ; else if MISCSTRICT ibmdos.asm
elseifdef ALLSTRICT
    ?fibmdos = 2                ; else if ALLSTRICT ibmdos.asm
                                ; (osmaca.inc may be included after dosseg.inc)
else
    ?fibmdos = 1                ; else non-strict ibmdos.asm
endif


;***    ?AssignGroup - generate a kernel segment definition
;
;       ENTRY   groupname = group name (DOSCODE, etc.)
;               snname = name of variable to hold group number (SN_DosCode)
;               badarg = blank arg test parameter
;       EXIT    ?cseg set to 0
;               ?cgroup incremented
;               <snname> arg set to new ?cgroup value
;               macro defined to add segment to group definition

?AssignGroup    macro   groupname, snname, fsegtable, badarg
    if2
        .errb <groupname>
        .errb <snname>
        .errnb <badarg>
        ifnb <fsegtable>
            ifdif <fsegtable>,<segtable>
                .err
            endif
        endif
    endif
    ?cseg = 0
    ?cgroup = ?cgroup + 1
    snname = ?cgroup
    ifb <fsegtable>
        ?fsegtable = 0
    else
        ?fsegtable = ?fibmdos
    endif
    ?GroupDef macro segname
        groupname group segname
    endm
endm


;***    ?SegDef - generate a kernel segment definition
;
;       ENTRY   segname = segment name
;               align = align type
;               combine = combine type
;               use1632 = use16 or use32
;               classname = class name
;               badarg = blank arg test parameter
;       EXIT    segment definition generated
;               segment added to group definition
;               if included from ibmdos.asm:
;                   end label generated for previous seg in group (if any)
;                   start label generated for current segment
;                   RETF,RETFD generated for 1st seg in group (if use16 code)

?SegDef macro   segname, align, combine, use1632, classname, badarg
local a
    if2
        .errb <segname>
        .errb <align>
        .errb <combine>
        .errb <use1632>
        .errb <classname>
        .errnb <badarg>
    endif
    segname segment align combine use1632 classname
    if ?fibmdos                         ;; if included from ibmdos.asm
        public _Start&segname           ;; generate this segment's start label
        _Start&segname label byte
        if ?cseg                        ;; if not first segment in group
            ?EndLabel                   ;; generate previous segment end label
                                        ;; else is first segment in group
        elseifidn <use1632>,<use16>     ;; if a use16 code group
            a instr <classname>,<CODE'>
            if a                        ;; generate RETF,RETFD for thunks
                int 3                   ;; to trap returns to offset 0
                if (?fretfdlabel eq 0)
                    public RETFDLabel
                    RETFDLabel label byte
                    ?fretfdlabel = 1
                endif
                .errnz (RETFOFFSET - (offset segname:$ - offset segname:0))
                retf                    ;; 16 bit far ret
                .errnz (RETFDOFFSET - (offset segname:$ - offset segname:0))
                RETFD                   ;; 32 bit far ret
            endif
        endif
        ?cseg = ?cseg + 1
        ?EndLabel macro                 ;; macro for this segment's end label
            public _End&segname
            _End&segname label byte
        endm
    endif
    segname ends
    ?GroupDef  segname
    if ?fsegtable
        THUNKINIT_DATA segment
            dd  offset _Start&segname
            db  '&segname&', 0
        THUNKINIT_DATA ends
    endif
endm




;****************** DOSGROUP group ******************
;       First because it must be tiled, because it contains
;       the INFOSEG segment which must be separately tiled,
;       and to allow maximum physical memory recovery when
;       compacting the per process data based on the threads=
;       value given in config.sys.  Never moved.

?AssignGroup  DOSGROUP, SN_DosGroup

;*      The start of the DOS data segment.  Must be first segment.
?SegDef START           word  public use16 'LOWDATA'    ;;DEF: PRELOAD FIXED

;*      Contains initialized variables and variables used at startup.
?SegDef CONSTANTS       word  public use16 'LOWDATA'

;*      Contains uninitialized variables.
?SegDef IDTDATA         para  public use16 'LOWDATA'

;*      Contains uninitialized variables.
?SegDef DATA            word  public use16 'LOWDATA'

;*      Contains dword aligned data variables.
?SegDef DWORDDATA       dword public use16 'LOWDATA'

;*      Read-only data.
?SegDef TABLE           word  public use16 'LOWDATA'

;*      InternalError Messages.
?SegDef INTERRMSG       byte  public use16 'LOWDATA'

;*      Data used only by Abios code on Abios machines. Will be freed on
;*      non-Abios machines
?SegDef ABIOSDATA       byte  public use16 'LOWDATA'

;*      Last allocated data.  This segment may be re-sized at initialization.
;       LASTDATA needs to be byte aligned.
?SegDef LASTDATA        byte  public use16 'LOWDATA'

;*      End of data
;       ENDDATA needs to be byte aligned.
?SegDef EENDDATA        byte  public use16 'LOWDATA'




;****************** DOSCODE group ******************
;       Here because it must be tiled.  Never moved.

?AssignGroup  DOSCODE, SN_DosCode

;*      The first code segment of the DOS.
?SegDef FIRSTCODE       dword public use16 'LOWCODE'    ;;DEF: PRELOAD FIXED

;*      The code comprising the system.  Should be read-only.
?SegDef CODE            dword public use16 'LOWCODE'

;*      ABIOS Code.  Will be freed on Non-abios machines
?SegDef ABIOSCODE       dword public use16 'LOWCODE'

;*      This code will be discarded when sysinit is done with it.
?SegDef INITCODE        dword public use16 'LOWCODE'


;****************** DBGCODE group ******************
;       Here because it's just past all tiled DOS segments
;       Debugger segments never move.

ifdef PMDEBUG
?AssignGroup  DBGCODE, SN_DbgCode

?SegDef DCODE           dword public use16 'DCODE'      ;;DEF: FIXED
endif ; PMDEBUG




;****************** DBGDATA group ******************
;       Debugger segments never move.

ifdef PMDEBUG
?AssignGroup  DBGDATA, SN_DbgData

?SegDef DFIRST          word  public use16 'DDATA'      ;;DEF: FIXED
?SegDef DDATA           word  public use16 'DDATA'
?SegDef DCONST          word  public use16 'DDATA'
?SegDef DBSS            word  public use16 'DDATA'
endif ; PMDEBUG




;****************** TASKAREA group ******************
;       Could be moved high after loading.

?AssignGroup  TASKAREA, SN_TaskGroup

;*      Per-process data.  The copy which resides in the kernel is
;       used by SysInit and, eventually, the ager.
?SegDef TASKDUMMY       word  public use16 'PTDADATA' ;;DEF: FIXED IOPL INVALID
?SegDef TASKDATA        word  public use16 'PTDADATA' ;;DEF: FIXED IOPL




;****************** DOSGDTDATA group **********************
;       Contains the GDT.
;       Is moved high and is fixed after loading.

?AssignGroup  DOSGDTDATA, SN_DosGDTData

;*      Static and dynamic GDT descriptor pools.
?SegDef GDTSTART        word  public use16 'GDTDATA'    ;;DEF: FIXED IOPL

;*      Segment to contain movable DOSCALLS call gates.
?SegDef GDTCGSEG        word  public use16 'GDTDATA'    ;;DEF: FIXED IOPL

;*      Segment to contain public (non-movable) DOSCALLS call gates
;       and additional statically allocated (named public) GDT entries.
?SegDef GDTPUBSEG       word  public use16 'GDTDATA'    ;;DEF: FIXED IOPL

;*      Segment to mark GDT end.
?SegDef GDTEND          word  public use16 'GDTDATA'    ;;DEF: FIXED IOPL




;****************** DOSINITDATA group ******************
;       Is moved high after loading. Discarded after SysInit.

?AssignGroup  DOSINITDATA, SN_DosInitData

;*      High Memory Initialization data only.
?SegDef INITDATA        word  public use16 'INITDATA'   ;;DEF: FIXED
?SegDef INITTABLE       word  public use16 'INITDATA'
?SegDef INITSTRING      word  public use16 'INITDATA'
?SegDef INITBSS         word  public use16 'INITDATA'




;****************** DOSINITR3CODE group ******************
;       Is discarded after SysInit.

?AssignGroup  DOSINITR3CODE, SN_DosInitR3Code

?SegDef INITR3CODE      dword public use16 'INITR3CODE' ;;DEF: FIXED




;****************** DOSMVDMINSTDATA group *********************
;       This is the fixed kernel instance data for the MVDM component

?AssignGroup  DOSMVDMINSTDATA, SN_DosMvdmInstData

?SegDef MVDMINSTDATA    dword public use32 'MIDATA' ;;DEF: NONSHARED RESIDENT




;****************** DOSSMVDMINSTDATA group *********************
;       This is the swappable kernel instance data for the MVDM component

?AssignGroup  DOSSWAPINSTDATA, SN_DosSwapInstData

?SegDef SWAPINSTDATA    dword public use32 'SIDATA' ;;DEF: NONSHARED




;****************** DGROUP group *****************
;       Order is carefully chosen to allow:
;       1) throwing away a single range that includes all initialization data
;       2) specifying a single range that includes all swappable data
;          (also includes the two previous MVDM instance data groups!!)
;       3) minimal .obj segment and class name editing
;       4) minimal number of segment definitions
;       Warning: automatic label generation is used to determine the
;       range of init data; segment reordering may cause init data to
;       not be freed, or non-init data to be erroneously freed.

?AssignGroup  DGROUP, SN_DGROUP


;*      C data segment
?SegDef CINIT_DATA      dword public use32 'CINITDATA'  ;;DEF:
?SegDef THUNKINIT_DATA  dword public use32 'CINITDATA'
?SegDef CSWAP_DATA      dword public use32 'CSWAPDATA'  ;;DEF:
?SegDef _DATA           dword public use32 'DATA'       ;;DEF:

;       WARNING The DOSMTE, FSHMTE and VDDMTE segments are used to construct
;               resident name tables and entry tables in pieces at assemble
;               and link time.  They must be byte aligned, or we'll get
;               intolerable padding in the middle of the data structures.

;*      DOSCALLS MTE
?SegDef DOSMTE          byte  public use32 'DATA'
?SegDef DOSMTENAME      byte  public use32 'DATA'
?SegDef DOSMTEMID       byte  public use32 'DATA'
?SegDef DOSMTEENTRY     byte  common use32 'DATA'
?SegDef DOSMTEAUX       byte  common use32 'DATA'

;*      FSH MTE
?SegDef FSHMTE          byte  public use32 'DATA'
?SegDef FSHMTENAME      byte  public use32 'DATA'
?SegDef FSHMTEMID       byte  public use32 'DATA'
?SegDef FSHMTEENTRY     byte  common use32 'DATA'

;*      VDD MTE
?SegDef VDDMTE          byte  public use32 'DATA'
?SegDef VDDMTENAME      byte  public use32 'DATA'
?SegDef VDDMTEMID       byte  public use32 'DATA'
?SegDef VDDMTEENTRY     byte  common use32 'DATA'

;*      Panic message CONST segment
?SegDef PANICMSG        byte public use32 'CONST'       ;;DEF:

;*      C CONST segment
?SegDef CONST           dword public use32 'CONST'

;*      C BSS segment ('BSS' class name forces c_common to be next)
?SegDef _BSS            dword public use32 'BSS'        ;;DEF:

;*      C common segment
?SegDef c_common        dword public use32 'BSS'




;****************** DOSHIGH2CODE group *****************
;       Is moved high and is fixed after loading.

?AssignGroup  DOSHIGH2CODE, SN_DosHigh2Code

?SegDef HIGH2CODE       dword public use16 'HIGH2CODE'  ;;DEF:




;****************** DOSHIGH3CODE group *****************
;       Is moved high and is fixed after loading.

?AssignGroup  DOSHIGH3CODE, SN_DosHigh3Code

?SegDef HIGH3CODE       dword public use16 'HIGH3CODE'  ;;DEF:




;****************** DOSHIGH4CODE group *****************
;       Is moved high and partially fixed, partially swappable after loading.
;
;       Note that the RETF and RETFD instructions at the beginning of the
;       group cannot be made swappable.
;
;       The below ordering is used, assuming the generic file system code
;       is most likely to be used, followed by the FAT EA code, then monitors.
;       The lockable monitors code is next to the FAT EA code and swappable
;       monitors code to make page fragments of FAT EA and monitors swappable
;       code resident when locking down monitors code.  NMPIPE code is less
;       used than monitors, and LOG and RAS code aren't used at all in a
;       typical retail installation.  Error logging is only slightly more
;       likely to be used than RAS.  There are no plans to do short term
;       locks on LOG and RAS code.

?AssignGroup  DOSHIGH4CODE, SN_DosHigh4Code

?SegDef HIGH4CODE       dword public use16 'HIGH4CODE'  ;;DEF:

?SegDef HIGH4SWAPCODE   dword public use16 'HIGH4CODE'
?SegDef FSSWAPCODE      dword public use16 'HIGH4CODE'
?SegDef FATEASWAPCODE   dword public use16 'HIGH4CODE'
?SegDef MONLOCKCODE     dword public use16 'HIGH4CODE'
?SegDef MONSWAPCODE     dword public use16 'HIGH4CODE'
?SegDef NMPIPESWAPCODE  dword public use16 'HIGH4CODE'

?SegDef RASSWAPCODE     dword public use16 'HIGH4CODE'
?SegDef LOGSWAPCODE     dword public use16 'HIGH4CODE'
?SegDef LOGLOCKCODE     dword public use16 'HIGH4CODE'
?SegDef RASLOCKCODE     dword public use16 'HIGH4CODE'
?SegDef ENDHIGH4CODE    dword public use16 'HIGH4CODE'




;****************** DOSHIGH32CODE group *****************
;       Is moved high after loading.

?AssignGroup  DOSHIGH32CODE, SN_DosHigh32Code, segtable

;*      32 bit code used for thunks; separate only for size information.
?SegDef THUNK_TEXT      dword public use32 'CODE'       ;;DEF:

;*      32 bit code that may reside in high memory.
?SegDef HIGH32CODE      dword public use32 'CODE'
?SegDef _TEXT           dword public use32 'CODE'

;*      32 bit code that may be freed.
;* used for page swapping (i.e. resident if page swapping going on).
?SegDef SMLOCK_TEXT     dword public use32 'CODE'

;*      32 bit code that may be swapped out
;
;* WARNING!!! HIGH32SWAP_TEXT must be first swappable 32-bit segment
;* because that segment is hardcoded in LDRINITA.ASM

?SegDef HIGH32SWAP_TEXT dword public use32 'CODE'
?SegDef THUNKSWAP_TEXT  dword public use32 'CODE'

; THE TUNE? are frequently called routines
?SegDef SWAP32_1   dword public use32 'CODE'
?SegDef SWAP32_2   dword public use32 'CODE'
?SegDef SWAP32_3   dword public use32 'CODE'
?SegDef SWAP32_4   dword public use32 'CODE'
?SegDef SWAP32_5   dword public use32 'CODE'
?SegDef SWAP32_6   dword public use32 'CODE'
?SegDef SWAP32_7   dword public use32 'CODE'
?SegDef SWAP32_8   dword public use32 'CODE'
?SegDef SWAP32_9   dword public use32 'CODE'
?SegDef SWAP32_10  dword public use32 'CODE'
?SegDef SWAP32_11  dword public use32 'CODE'
?SegDef SWAP32_12  dword public use32 'CODE'
?SegDef SWAP32_13  dword public use32 'CODE'
?SegDef SWAP32_14  dword public use32 'CODE'
?SegDef SWAP32_15  dword public use32 'CODE'
?SegDef SWAP32_16  dword public use32 'CODE'
?SegDef SWAP32_17  dword public use32 'CODE'
?SegDef SWAP32_18  dword public use32 'CODE'
?SegDef SWAP32_19  dword public use32 'CODE'
?SegDef SWAP32_20  dword public use32 'CODE'
?SegDef SWAP32_21  dword public use32 'CODE'
?SegDef SWAP32_22  dword public use32 'CODE'
?SegDef SWAP32_23  dword public use32 'CODE'
?SegDef SWAP32_24  dword public use32 'CODE'
?SegDef SWAP32_25  dword public use32 'CODE'
?SegDef SWAP32_26  dword public use32 'CODE'
?SegDef SWAP32_27  dword public use32 'CODE'
?SegDef SWAP32_28  dword public use32 'CODE'
?SegDef LOAD_TUNE1_SWP  dword public use32 'CODE'
?SegDef LOAD_TUNE4_SWP  dword public use32 'CODE'
?SegDef LOAD_TUNE8_SWP  dword public use32 'CODE'
?SegDef LOAD_TUNE9_SWP  dword public use32 'CODE'
;  FTUNE2 has routines called by a variate of processes
?SegDef LOAD_FTUNE2_SWP  dword public use32 'CODE'
;  ftune1 has spreadsheet and editor called routines
?SegDef LOAD_FTUNE1_SWP  dword public use32 'CODE'
; TUNEDIT1 calls are used to load the enhanced editor
?SegDef LOAD_TUNEDIT1_SWP  dword public use32 'CODE'
; Ftunedit1 has dos and editor called routines
;  TUNEDOS5 and TUNEDOS12 are calls primarily called by dos
?SegDef LOAD_TUNEDOS5_SWP  dword public use32 'CODE'
?SegDef LOAD_TUNEDOS12_SWP dword public use32 'CODE'
;  TUNEDOS11 and TUNEDOS4 are calls used for dos and exiting dos
?SegDef LOAD_TUNEDOS11_SWP dword public use32 'CODE'
?SegDef LOAD_TUNEDOS4_SWP  dword public use32 'CODE'
;  EXITDOS1 contains calls used to exit a dos session
?SegDef LOAD_EXITDOS1_SWP  dword public use32 'CODE'
; routines seldom called from HIGH32SWAP
?SegDef LOAD_BEEP_SWP  dword public use32 'CODE'
?SegDef EXMGSWAP_TEXT   dword public use32 'CODE'
?SegDef TKSWAP_TEXT     dword public use32 'CODE'
; ?SegDef SEMSWAP_TEXT    dword public use32 'CODE'
?SegDef LDRSWAP_TEXT    dword public use32 'CODE'
;;;;?SegDef LDR16SWAP_TEXT  dword public use32 'CODE'
?SegDef SELSWAP_TEXT    dword public use32 'CODE'
?SegDef VMSWAP_TEXT     dword public use32 'CODE'
?SegDef PGSWAP_TEXT     dword public use32 'CODE'
;;;;?SegDef SGSWAP_TEXT     dword public use32 'CODE'
;;;;?SegDef IFSSWAP_TEXT    dword public use32 'CODE'
?SegDef MVDMSWAP_TEXT       dword public use32 'CODE'
;;;;;?SegDef STATSWAP_TEXT  dword public use32 'CODE'
?SegDef QUERYSWAP_TEXT  dword public use32 'CODE'
?SegDef PERFSWAP_TEXT   dword public use32 'CODE'

?SegDef DYNSWAP_TEXT    dword public use32 'CODE'
?SegDef DYNLOCK_TEXT    dword public use32 'CODE'
?SegDef DEBUGLOCK_TEXT  dword public use32 'CODE'
?SegDef DEBUGSWAP_TEXT  dword public use32 'CODE'
?SegDef MON32SWAP_TEXT  dword public use32 'CODE'
?SegDef MON32LOCK_TEXT  dword public use32 'CODE'
?SegDef PROFLOCK_TEXT   dword public use32 'CODE'
?SegDef PROFSWAP_TEXT   dword public use32 'CODE'

;*      32 bit code that may be freed after initialization.
?SegDef CINIT_TEXT      dword public use32 'CODE'
?SegDef THUNKINIT_TEXT  dword public use32 'CODE'

;*      Marks end of segment (used to free init code)
?SegDef ENDHIGH32CODE   byte  public use32 'CODE'


if (?fibmdos eq 2)                      ; if MISCTRICT ibmdos.asm
    THUNKINIT_DATA segment
        dd      -1                      ; mark end of seg table
        public _ThunkTable
        _ThunkTable label byte          ; mark start of thunk table
    THUNKINIT_DATA ends
endif


SN_MAX = ?cgroup                ; Number of Groups

purge ?AssignGroup, ?GroupDef, ?SegDef

;***    For BASEDEF.INC/BASEMACA.INC macros

ifdef INCL_DEF

@INIT_CODE      equ     <CINIT_TEXT>
?INIT_CODE      equ     <USE32>
@INIT_DATA      equ     <CINIT_DATA>
?INIT_DATA      equ     <USE32>
@GLOBAL_CODE    equ     <HIGH32CODE>
?GLOBAL_CODE    equ     <USE32>
@GLOBAL_DATA    equ     <_DATA>
?GLOBAL_DATA    equ     <USE32>
@SWAP_CODE      equ     <MVDMSWAP_TEXT>
?SWAP_CODE      equ     <USE32>
@SWAP_DATA      equ     <CSWAP_DATA>
?SWAP_DATA      equ     <USE32>
@INSTANCE_DATA  equ     <MVDMINSTDATA>
?INSTANCE_DATA  equ     <USE32>
@SWAPINST_DATA  equ     <SWAPINSTDATA>
?SWAPINST_DATA  equ     <USE32>

endif

.286p
