dos16m.asm

来自「开放源码的编译器open watcom 1.6.0版的源代码」· 汇编 代码 · 共 557 行 · 第 1/2 页

ASM
557
字号
; fixme: - these should be modified in the source code
ifdef __REGISTER__
    STACK = 0
endif
ifdef __STACK__
    STACK = 1
endif
ifdef __386__
    ifdef __OS2__
            _OS220 = 1
    endif
    ifdef __NT__
            _NT = 1
    endif
    ifdef __NETWARE__
            __NET386__ = 1
    endif
    ifdef __PENPOINT__
            _PENPOINT = 1
    endif
endif
;fixme: source here to allow a fix
;include a\dos16m.asm
;%  Copyright (C) 1988-1993 by WATCOM International Corp. All   %
;
; startup code for WATCOM C and WATCOM FORTRAN 77 under Rational's DOS/16M
;
;  To reassemble this file for DOS/16M, use the following command:
;               masm /mx/s dos16m;
;
        .286p

        name    dos16m
        ;.dosseg

        assume  nothing

        extrn   __CMain         : far
        extrn   __FInitRtns     : far
        extrn   __FFiniRtns     : far
        extrn   stackavail_     : far
        extrn   _edata          : byte          ; end of DATA (start of BSS)
        extrn   _end            : byte          ; end of BSS (start of STACK)

public  __acrtused              ; trick to lend harmony to dealings with
        __acrtused = 9876h      ; DOS16LIB

 DGROUP group _NULL,_AFTERNULL,CONST,STRINGS,_DATA,DATA,BCSD,XIB,XI,XIE,YIB,YI,YIE,_BSS,STACK,verylast

_TEXT   segment word public 'CODE'

C_ETEXT segment para public 'ENDCODE'
        public  __first_data_16M                ; For DOS/16M seginfo struct in PML
__first_data_16M        label word
        dw      C_ETEXT         ; force reference so /packcode will work
        db      14 dup (?)      ; force one paragraph
C_ETEXT ends

nullseg segment para public 'CODE'
        assume  cs:nullseg
fake_start:     jmp     short bad_start
                nop
                nop
        public  d16_seginfo_struct
d16_seginfo_struct label word
seginfo_id      db      'DOS/16M',0     ; will be offset 0 in this segment
info_version    dw      3               ; in case structure is extended
info_init_ip    dw      OFFSET _cstart_ ; address of compiler
info_code_seg   dw      SEG _cstart_    ; startup code
info_overlay    dd      0               ; pointer to overlay info structure, if any
info_load_info  dw      ovi_data        ; seg of optional loader control info
info_first_code dw      SEG _cstart_    ; seg of first code seg
info_first_data dw      SEG __first_data_16M    ; seg of first data seg
info_data_seg   dw      SEG __main_data_16M     ; seg of main data seg (dgroup)
;;info_stack_seg  dw      SEG __stack_16M ; seg of stack (may be dgroup)
info_stack_seg  dw      SEG __main_data_16M ; seg of stack (may be dgroup)
info_verylast   dw      SEG __end_16M   ; end of program image
info_gdt        dw      gdtseg          ; seg of dummy GDT segment (8)
info_idt        dw      idtseg          ; seg of dummy IDT segment (0x10)
info_d16_data   dw      rtdataseg       ; compiler-specific info for MAKEPM (0x20)
info_flags      dw      0               ; bit vector consisting of these flags:
info_stack_is_resized   equ     1       ; flag: startup code will resize stack
                                        ;       so that MAKEPM should not worry
                                        ;       about tiny stack segs

; watch this space for exciting new pointers (but update the version when
;       new elements are added).

                dw      rtcodeseg       ; (0x18)
                dw      pspseg          ; (0x28)
                dw      envseg          ; (0x30)
                dw      mem0seg         ; (0x38)
                dw      dummy14         ; (0x70)


comment /*
        Programs that have not been processed with MAKEPM will start
        at fake_start, put out the badstart_msg and exit.  MAKEPM
        finds the actual start address from info_start in the
        d16_seginfo_struct and fixes the start address to __startup_.
                                                                        */

bad_start:                              ; .EXE indicates to start here
        mov     dx, OFFSET nullseg:badstart_msg
        mov     ax,cs
        mov     ds,ax
        mov     ah,9                    ; DOS output string
        int     21h
        mov     ax,4CFFh                ; DOS exit with code OFF
        int     21h

badstart_msg    db      '.EXE has not been processed by MAKEPM', 10, 13, '$'

nullseg ends

; The following segment definitions allow programs to have symbolic
; references to system structures.  These segments will no be in the
; .EXP file, but references to the segments will be resolved to the
; corresponding global system segment by MAKEPM.

gdtseg  segment para public 'FAR_DATA'  ; MAKEPM maps references to this
        public __gdt                    ; segment to selector 8h
__gdt   dw      0
gdtseg  ends

idtseg  segment para public 'FAR_DATA'  ; MAKEPM maps references to this
        public __idt                    ; segment to selector 10h
__idt   dw      0
idtseg  ends

rtcodeseg       segment para public 'FAR_DATA'  ; MAKEPM maps references to this
        public __rtcode                 ; segment to selector 18h
__rtcode        dw      0
rtcodeseg       ends

rtdataseg       segment para public 'FAR_DATA'  ; MAKEPM maps references to this
        public __d16info                ; segment to selector 20h
__d16info       dw      0
rtdataseg       ends

pspseg  segment para public 'FAR_DATA'  ; MAKEPM maps references to this
        public __psp16M                 ; segment to selector 28h
__psp16M        dw      0
pspseg  ends

envseg  segment para public 'FAR_DATA'  ; MAKEPM maps references to this
        public __env16M                 ; segment to selector 30h
__env16M        dw      0
envseg  ends

mem0seg segment para public 'FAR_DATA'  ; MAKEPM maps references to this
        public __mem16M                 ; segment to selector 38h
__mem16M        dw      0
mem0seg ends

dummy14 segment para public 'FAR_DATA'  ; MAKEPM maps references to this
        public __dummy16M               ; segment to selector 70h
__dummy16M      dw      0
dummy14 ends

ovi_data segment para public 'CODE'     ; MAKEPM assigns this as the first
ovi_data ends                           ; code segment (first loaded)
; ovi_data, if present, has special load_time information about segments.
; It is used by the VM and OM memory managers.

FAR_DATA segment byte public 'FAR_DATA'
FAR_DATA ends

        assume  ds:DGROUP

        INIT_VAL        equ 0101h
        NUM_VAL         equ 16

_NULL   segment para public 'BEGDATA'
        public  __main_data_16M         ; For DOS/16M seginfo struct in PML
__main_data_16M label word
__nullarea label word
        dw      NUM_VAL dup(INIT_VAL)
        public  __nullarea
_NULL   ends

_AFTERNULL segment word public 'BEGDATA'
        dw      0                       ; nullchar for string at address 0
_AFTERNULL ends

CONST   segment word public 'DATA'
CONST   ends

STRINGS segment word public 'DATA'
STRINGS ends

XIB     segment word public 'DATA'
XIB     ends
XI      segment word public 'DATA'
XI      ends
XIE     segment word public 'DATA'
XIE     ends

YIB     segment word public 'DATA'
YIB     ends
YI      segment word public 'DATA'
YI      ends
YIE     segment word public 'DATA'
YIE     ends

_DATA   segment word public 'DATA'

        extrn   ___d16_selectors:far
__curbrk   dw 0                 ; top of usable memory
__psp      dw 0                 ; segment addr of program segment prefix
__osmajor  db 0                 ; major DOS version number
__osminor  db 0                 ; minor DOS version number
__osmode   db 1                 ; 0 => DOS real mode, 1 =>protect mode
__HShift   db 3                 ; Huge Shift amount (real-mode=12,prot-mode=3)
__STACKLOW dw 0                 ; lowest address in stack
__STACKTOP dw 0                 ; highest address in stack
__cbyte    dw 0                 ; used by getch, getche
__child    dw 0                 ; non-zero => a spawned process is running
__no87     dw 0                 ; non-zero => "NO87" enviroment var present
__get_ovl_stack dw 0,0          ; get overlay stack pointer
__restore_ovl_stack dw 0,0      ; restore overlay stack pointer
__close_ovl_file dw 0,0         ; close the overlay file handle
 __FPE_handler label dword
___FPE_handler dw 0,0           ; FPE handler
__LpCmdLine dw 0,0              ; lpCmdLine (for _argc, _argv processing)
__LpPgmName dw 0,0              ; lpPgmName (for _argc, _argv processing)

;       Variables filled in by Microsoft Overlay Manager
;       These are here for people who want to link with Microsoft Linker
;       and use CodeView for debugging overlayed programs.
__ovlflag  db 0                 ; non-zero => program is overlayed
__intno    db 0                 ; interrupt number used by MS Overlay Manager
__ovlvec   dd 0                 ; saved contents of interrupt vector used
        public  __ovlflag
        public  __intno
        public  __ovlvec

        public  __curbrk
        public  __psp
        public  __osmajor
        public  __osminor
        public  __osmode
        public  __HShift
        public  __STACKLOW
        public  __STACKTOP
        public  __cbyte
        public  __child
        public  __no87
        public  __get_ovl_stack
        public  __restore_ovl_stack
        public  __close_ovl_file
        public   __FPE_handler
        public  ___FPE_handler
        public  __LpCmdLine
        public  __LpPgmName

_DATA   ends

DATA    segment word public 'DATA'
DATA    ends

BCSD    segment word public 'DATA'
BCSD    ends

_BSS          segment word public 'BSS'
_BSS          ends

STACK_SIZE      equ    1000h

STACK   segment para stack 'STACK'
        public  __stack_16M     ; For DOS/16M seginfo struct in PML
__stack_16M     label word
        db      (STACK_SIZE) dup(?)
stkend  label   word
STACK   ends

verylast segment para 'STACK'
        public  __end_16M       ; For DOS/16M seginfo struct in PML
__end_16M       label word

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?