cstrtx32.asm

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

ASM
525
字号
;*****************************************************************************
;*
;*                            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:  FlashTek 32-bit DOS extender startup code.
;*
;*****************************************************************************


; Copyright FlashTek Inc 1992 - 1993
; Modified by
; Doug Huffman
; Route 1 Box 54A
; Lenore, ID 83541
; email: doug@proto.com

comment&
        X-32 startup code for producing executables using the Watcom compiler
        and linker with clib3r.  This module must be linked first since it
        determines the segment order for all segments in the final executable.

        Portions of this Code were provided by Watcom Systems Inc and modified
        by FlashTek for the purpose of providing X-32 support for Watcom
        products.

        Portions of this Code have subsequently been modified by Watcom
        for use with the 10.0 release.
        Additional changes have been made to support WASM and both the
        -3r and -3s calling conventions.


        This must be assembled using one of the following commands:
                wasm cstrtx32 -bt=DOS -ms -3r
                wasm cstrtx32 -bt=DOS -ms -3s
&

.386p

public  __x386_zero_base_ptr
public  __x386_zero_base_selector
public  __data_bottom
public  __x386_init
public  _cstart_
public  __do_exit_with_msg__
public  "C",sbrk
public  "C",__exit
public  "C",__brk
public  __x32_zero_base_ptr
public  __x32_zero_base_selector

;define 16 bit segments first so they will be located at the beginning
;of the executable.

__X386_DATASEG_16      segment para use16 public 'DATA16'
;16 bit data segment for real mode and priv level 0 activities
        dw      _TEXT
        extrn __x386_dbg_hook:word
        dw      offset __x386_dbg_hook  ;debugger hook
        dd      offset _TEXT:_edata            ;B format information
        dd      offset _TEXT:_end              ;B format information
__X386_DATASEG_16      ends

__X386_STACK            segment para use16 stack 'STACK' ;phony stack segment
;this is a fake stack segment, the Watcom linker sets the size according to the
;stacksize parameter.  This is only used for locating the 16 bit data object
__X386_STACK            ends
__X386_GROUP_16         group   __X386_DATASEG_16,__X386_STACK

__X386_CODESEG_16       segment para use16 public 'CODE'
assume cs:__X386_CODESEG_16,ds:nothing,es:nothing,fs:nothing,gs:nothing,ss:nothing
extrn __x386_start:near
_cstart_:
        jmp     __x386_start    ;jump to 16 bit initialization
__X386_CODESEG_16       ends


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

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


DGROUP group BEGTEXT,_TEXT,CODE32,_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)
; This segment must be at least 4 bytes in size to avoid confusing the
; signal function.

BEGTEXT  segment use32 para public 'CODE'
        assume  cs:_TEXT
        jmp     null_error
        nop     ;2
        nop     ;3
        nop     ;4
        nop     ;5
        nop     ;6
        nop     ;7
        nop     ;8
        nop     ;9
        nop     ;A
        nop     ;B
        nop     ;C
        nop     ;D
        nop     ;E
        nop     ;F
        assume  cs:nothing
BEGTEXT  ends

_TEXT   segment use32 word public 'CODE'

CODE32  segment use32 dword public 'CODE'
CODE32  ends

        assume  ds:DGROUP

_NULL   segment para public 'BEGDATA'
__data_bottom   label byte      ;lowest address in data segment
__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'
extrn __x32_stack_size:dword
;debugger requires two variables below to be positioned together
__x32_zero_base_selector        label   word
__x386_zero_base_selector       dw      ?       ;writable segment, base = 0
__x32_zero_base_ptr             label dword
__x386_zero_base_ptr            dd      0f0000000h

__D16Infoseg   dw       0020h   ; DOS/4G kernel segment

        public  __D16Infoseg

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

__x386_break    dd      ?
__saved_DS      dw      0 ; save area for DS for interrupt routines

insuf_msg       db      10,13,'Insufficient memory for stack setup',24h
null_msg        db      10,13,'Null code pointer was called',0
ConsoleName     db      "con",0

_DATA    ends


DATA    segment word public 'DATA'
DATA    ends

_BSS    segment word public 'BSS'
_BSS    ends

STACK   segment para stack 'STACK'
STACK   ends

        assume  cs:_TEXT
        assume  ds:DGROUP

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

;
; miscellaneous code-segment messages
;
fpe_handler:    ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;This is the location where 16 bit code transfers control to when
;first entering 32 bit code.  DS will = ES = __x386_data_32, GS =
;__x386_seg_env, FS = __x386_seg_psp.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__x386_init proc near
;The Watcom compliler uses ds and ss to point to things in the data segment
;so we cannot use the normal limits, we will use the default ds for both ds
;and ss but alter the limits.
        mov     bx,ds
        mov     ecx,offset DGROUP:brk_c
        mov     ax,3505h
        int     21h                     ;set limit to include most code
        push    ds
        pop     ss                      ;Switch SS to default DS selector
        mov     _psp,fs                 ; save segment address of PSP
        mov     ah,30h                  ;get DOS version number
        int     21h
        mov     _osmajor,al
        mov     _osminor,ah

        mov     __saved_DS,ds           ; save DS value
        mov     _Envseg,gs              ; save segment of environment area
        mov     _Extender,3             ; pretend to be PharLap V3
        mov     __X32VM,1               ; mark that this is X32VM
        push    fs
        pop     es                      ;pointer to psp
        mov     edi,81h                 ;DOS command buffer es:edi
;
;       copy command line into top of stack
;
        movzx   ecx,byte ptr es:[edi-1] ; get length of command

⌨️ 快捷键说明

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