adstart.asm

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

ASM
617
字号
;*****************************************************************************
;*
;*                            Open Watcom Project
;*
;*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
;*
;*  ========================================================================
;*
;*    This file contains Original Code and/or Modifications of Original
;*    Code as defined in and that are subject to the Sybase Open Watcom
;*    Public License version 1.0 (the 'License'). You may not use this file
;*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
;*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
;*    provided with the Original Code and Modifications, and is also
;*    available at www.sybase.com/developer/opensource.
;*
;*    The Original Code and all software distributed under the License are
;*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
;*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
;*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
;*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
;*    NON-INFRINGEMENT. Please see the License for the specific language
;*    governing rights and limitations under the License.
;*
;*  ========================================================================
;*
;* Description:  DOS 32-bit AutoCAD ADS startup code.
;*
;*****************************************************************************


;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;%                                                                 %
;%       This module was modified for use with AutoCAD's protect   %
;%       mode ADI and ADS.  AutoCAD is a registered trademark of   %
;%       Autodesk, Inc.                                            %
;%                                                                 %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;
;       This must be assembled using one of the following commands:
;               wasm adstart -fo=adsstart.obj -dADS -3s
;               wasm adstart -fo=adifstrt.obj -dPADI -3s
;               wasm adstart -fo=adiestrt.obj -dPADI -dEADI -3s
;
        name    adsstart

.387
.386p

comment @
        Modified for AutoLISP and protect mode ADI

        Expects to be called at starting address as a subroutine, rather
        than as an executable program from the operating system.  Stack
        and segment registers must be correctly set up; and some
        additional information is expected in these registers:

        ECX     Compatibility-check value.  Must be equal to (our
                locally defined symbol) chkval.  If it isn't, we assume
                we are erroneously being executed as an independent
                separate program.  This won't work, so we exit
                immediately to the system.

        DS:ESI  Pointer to structure containing initialization information.
                A minimum structure size of 8 bytes is mandatory (12 bytes
                if PADI is set).  The first 4 bytes of the structure must
                contain the number of bytes making up the structure.  The
                second 4 bytes must contain the initial heapsize of the
                child process, obtained from the loader in AutoCAD.  If
                PADI is set, the third 4 bytes must contain the physical
                address of the packet buffer in AutoCAD to be used for
                communication with protect mode ADI drivers.  All subsequent
                bytes are the business between AutoCAD and the loaded child
                process and may vary.

        The value we return is the argument to exit() which terminates us.
        We preserve no registers, not even SS and SP.

        Some protected mode ADI, ADS, and AutoLISP modifications are
        conditioned on the tag ACAD.

        Some code for ADS only is included only if the tag ADS is
        predefined (e.g., in the assembler command line).

        Code required for AutoCAD protected mode ADI drivers only is included
        by setting PADI in the assembler command line.
        @

ACAD   equ  1   ; Protect mode ADI and AutoLISP version of module.
minmem equ  4   ; Offset within the structure containing initialization
                ; information to the inital heap size of the child process.
ifdef   PADI
physadr equ 8   ; Offset within the structure containing initialization
                ; information to the physical address of a buffer shared
                ; between AutoCAD and a protect mode ADI driver.
endif   ; PADI


        assume  nothing

        extrn   __CMain         : near
        extrn   __InitRtns      : near
        extrn   __FiniRtns      : near
        extrn   __DOSseg__      : near

if      ACAD
ifdef   ADS
getinitinfo     =    adsi_getinitinfo
map_phys_mem    =    ads_map_phys_mem
endif   ; ADS
ifndef  PADI
        extrn   getinitinfo     : near          ; initialize child process
                                                ; loaded by AutoCAD
endif   ; !PADI
;
; map_phys_mem allows a 3rd party to install a routine to map physical
; memory between the stack and heap
;
extrn   map_phys_mem            : near
endif   ; ACAD

        extrn   _edata          : byte          ; end of DATA (start of BSS)
        extrn   _end            : byte          ; end of BSS (start of STACK)

        extrn   _dynend         : dword
        extrn   _curbrk         : dword
        extrn   _psp            : word
        extrn   _osmajor        : byte
        extrn   _osminor        : byte
        extrn   _STACKLOW       : dword
        extrn   _STACKTOP       : dword
        extrn   _child          : dword
        extrn   __no87          : word
        extrn   "C",_Extender   : byte
        extrn   _ExtenderSubtype: byte
        extrn   _Envptr         : dword
        extrn   _Envseg         : word
        extrn   "C",__FPE_handler : dword
        extrn   _LpCmdLine      : dword
        extrn   _LpPgmName      : dword

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

; this guarantees that no function pointer will equal NULL
; (WLINK will keep segment 'BEGTEXT' in front)

BEGTEXT  segment use32 word public 'CODE'
        assume  cs:BEGTEXT
___begtext label byte
forever label   near
        int     3h
        jmp    short forever
        public ___begtext
        assume  cs:nothing
BEGTEXT  ends

_TEXT   segment use32 word public 'CODE'

        assume  ds:DGROUP

_NULL   segment para public 'BEGDATA'
__nullarea label word
        db      01h,01h,01h,00h
        public  __nullarea
_NULL   ends

_AFTERNULL segment word public 'BEGDATA'
_AFTERNULL ends

CONST   segment word public 'DATA'
CONST   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 dword public 'DATA'

__x386_zero_base_selector dw 0  ; base 0 selector for X-32VM
        public  __x386_zero_base_selector
if      ACAD
chkval  equ     1234            ; magic interface-compatibility code
ifndef  ADS                     ; Avoid excess globals for ADS
        public   brkflg, stkflg
        public   info_off, info_sel
endif   ; ADS
        public  __fsavcw
ifdef   PADI
        public  cbufadr
        align 4
cbufadr  dd     0               ; ptr to common pg between ACAD and PADI
phys_adr  dd    0               ; physical address of common page
endif   ; PADI
brkflg   dd     0               ; set nonzero for Control C
stkflg   dd     0               ; set nonzero for stack overflow
info_off dd     0               ; Offset of initialization info struct
info_sel dw     0               ; Selector of initialization info struct
rtnaddr   df    0               ; Caller's return address.
min_mem   dd    0               ; inital driver heap size
sav_ds    dw    0
my_ds     dw    0
__fsavcw  dw    0               ; for saving AutoLISP's floating point cntl word
interr    db    "Incompatible program interface",0Dh,0Ah,"$"
endif   ; ACAD

_DATA   ends

DATA    segment word public 'DATA'
DATA    ends

_BSS          segment word public 'BSS'
_BSS          ends

if      ACAD
STACK_SIZE      equ     4000h
else
STACK_SIZE      equ     1000h
endif   ; ACAD

STACK   segment para stack 'STACK'
stk     label   word
        db      (STACK_SIZE) dup(?)
STACK   ends


        assume  nothing
        public  _cstart_
        public   __exit

        assume  cs:_TEXT

_cstart_ proc near
        jmp     short around

;
; copyright message
;
include msgrt32.inc
include msgcpyrt.inc

;
; miscellaneous code-segment messages
;
ConsoleName     db      "con",00h

        dd      ___begtext      ; make sure dead code elimination
                                ; doesn't kill BEGTEXT

around: sti                             ; enable interrupts

        assume  ds:DGROUP

PSP_SEG equ     24h
ENV_SEG equ     2ch

if      ACAD
        ; Save AutoLISP's floating point control word, to be restored by
        ; adsi_farcl() before returning to AutoLISP
ifndef  EADI
        fnstcw  __fsavcw
endif

        cmp     ecx,chkval              ; Proper chkval argument?
        je      m00
        mov     edx,offset interr       ; "Incompatible program interface"
        mov     ah,9
        int     21h                     ; Print message.
        mov     ax,4C01h
        int     21h                     ; Exit to DOS.
m00:
        mov     info_off,esi            ; offset of initialization info struct
        mov     info_sel,dx             ; selector of info struct
        mov     es,dx
        mov     eax,es:[esi].minmem
        mov     min_mem,eax             ; initial heap size of driver
ifdef   PADI
        mov     eax,es:[esi].physadr
        mov     phys_adr,eax            ; phys addr of pg w/ PADI packet buffer
endif   ; PADI
        mov     ax,ds
        mov     es,ax
        pop     dword ptr rtnaddr       ; Save return address, offset
        pop     ax
        mov     word ptr rtnaddr+4,ax   ;    and segment.
        mov     my_ds,ds                ; Save DS for use in __GETDS()
endif   ; ACAD

        mov     ax,PSP_SEG              ; get segment address of PSP
        mov      _psp,ax                ; save segment address of PSP
        mov     es,ax                   ; point to PSP
        and     esp,0fffffffch          ; make sure stack is on a 4 byte bdry
        mov     ebx,esp                 ; get sp
        mov      _STACKTOP,ebx          ; set stack top
        mov      _curbrk,ebx            ; set first available memory location
;
;       get DOS & Extender version number
;
        ;mov    ebx,'PHAR'              ; set ebx to "PHAR"

⌨️ 快捷键说明

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