cortns.asm

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

ASM
437
字号
;*****************************************************************************
;*
;*                            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:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
;*               DESCRIBE IT HERE!
;*
;*****************************************************************************


;;
;; CORTNS       : i/o co-routines (common to READ and WRITE)
;;

.8087

include ptypes.inc
include struct.inc
include mdef.inc

        modstart cortns, byte

        dataseg
        assume  ES:DGROUP

        xred    "C",IORslt,      word
        xred    "C",_STACKLOW,   word

; for all 16-bit systems we now use a 4K coroutine stack
COSTACK_SIZE = 4096

; we also need our normal stack to be minimum 4K
F77_STACK_SIZE = 4096

STACK   SEGMENT STACK BYTE 'STACK'
ifdef __OS2__
other_stack_low label   word
endif
        db      F77_STACK_SIZE dup(?)
        db      COSTACK_SIZE dup(?)
STACK   ENDS

CoStack dw      COSTACK_SIZE
SaveSP  dw      ?
SaveSS  dw      ?
RetAddr dw      2 dup(?)
SaveReg dw      6 dup(?)
SaveSeg dw      2 dup(?)
IORtn   dw      2 dup(?)
ifdef __OS2__
InitStackLow dw 0
endif
ifdef __WINDOWS__
SaveAX  dw      ?
BPLink  dw      ?
endif

        enddata


        defp    Switch                  ; switch back to generated code
ifdef __WINDOWS__
        inc     BP                      ; set up Windows BP-chain
        push    BP                      ; ...
        mov     BP,SP                   ; ...
else
        xdefp   IOSwitch
IOSwitch:
        push    BP                      ; save current registers
endif
        push    BX                      ; ...
        push    CX                      ; ...
        push    DX                      ; ...
        push    DI                      ; ...
        push    SI                      ; ...
        push    DS                      ; ...
        push    ES                      ; ...
        mov     BX,DGROUP               ; get segment address of DGROUP
        mov     ES,BX                   ; ...
        mov     ES:SaveSS,SS            ; switch stacks
        mov     SS,BX                   ; ...
        xchg    ES:SaveSP,SP            ; ...
        pop     ES                      ; restore previous registers
        pop     DS                      ; ...
        pop     SI                      ; ...
        pop     DI                      ; ...
        pop     DX                      ; ...
        pop     CX                      ; ...
        pop     BX                      ; ...
ifdef __WINDOWS__
        mov     SaveAX,AX               ; save return value
        inc     BP                      ; fix up Windows BP-chain
        mov     AX,BP                   ; ...
        pop     BP                      ; ...
        dec     BP                      ; ...
        push    BX                      ; ...
        mov     BX,BPLink               ; ...
        xchg    [BX],AX                 ; ...
        mov     BX,_STACKLOW            ; ...
        add     BX,CoStack              ; ...
        add     BX,1                    ; ...
        and     BX,0FFFEh               ; ...
        lea     BX,-6[BX]               ; ...
        mov     SS:[BX],AX              ; ...
        pop     BX                      ; ...
        mov     AX,SaveAX               ; restore return value
else
        pop     BP                      ; ...
endif
        ret                             ; return to generated code
        endproc Switch


ifdef __WINDOWS__
        xdefp   IOSwitch                ; switch back to i/o system
        defp    IOSwitch
        inc     BP                      ; set up Windows BP-chain
        push    BP                      ; ...
        mov     BP,SP                   ; ...
        push    BX                      ; save registers
        push    CX                      ; ...
        push    DX                      ; ...
        push    DI                      ; ...
        push    SI                      ; ...
        push    DS                      ; ...
        push    ES                      ; ...
        mov     BX,DGROUP               ; get segment address of DGROUP
        mov     ES,BX                   ; ...
        mov     BX,ES:SaveSS            ; switch stacks
        mov     ES:SaveSS,SS            ; ...
        mov     SS,BX                   ; ...
        xchg    ES:SaveSP,SP            ; ...
        pop     ES                      ; restore previous registers
        pop     DS                      ; ...
        pop     SI                      ; ...
        pop     DI                      ; ...
        pop     DX                      ; ...
        pop     CX                      ; ... (except BX)
        mov     SaveAX,AX               ; save return value
        mov     AX,BP                   ; fix up Windows BP-chain
        inc     AX                      ; ...
        mov     BX,_STACKLOW            ; ...
        add     BX,CoStack              ; ...
        add     BX,1                    ; ...
        and     BX,0FFFEh               ; ...
        lea     BX,-6[BX]               ; ...
        xchg    SS:[BX],AX              ; ...
        pop     BX                      ; now restore BX
        mov     BP,[BP]                 ; ...
        dec     BP                      ; ...
        cmp     BP,BPLink               ; get BP link to generated code
        _if     ne                      ; if array i/o, its next link
          mov   BP,[BP]                 ; ...
          dec   BP                      ; ...
        _endif                          ; ...
        mov     [BP],AX                 ; ...
        pop     BP                      ; ...
        dec     BP                      ; ...
        mov     AX,SaveAX               ; restore return value
        ret                             ; return to run-time system
        endproc IOSwitch
endif

FRAME_SIZE      = (8*2+4)       ; define stack frame to discard when restoring
                                ; state (8 registers and return address)

        xdefp   RdWrCommon
        defp    RdWrCommon
        ; on entry address of i/o routine is on stack
        push    BP                      ; get stack addressability
        mov     BP,SP                   ; ...
        push    ES                      ; save ES
        mov     AX,DGROUP               ; get segment address of DGROUP
        mov     ES,AX                   ; ...
ifdef __OS2__
        cmp     es:InitStackLow,0       ; check to see if we need to adjust _STACKLOW
        _if     e                       ; if already done then no needto do so again
          mov   ax,offset DGROUP:other_stack_low        ; compare our low stack offset to _STACKLOW
          cmp   ax,es:_STACKLOW         ; and pick the lesser of the two
          _if   b                       ; ...
            mov es:_STACKLOW, ax        ; ...
          _endif                        ; ...
          mov   es:InitStackLow, 1      ; So we don't need to check it again.
        _endif
endif
        mov     AX,2[BP]                ; save address of i/o routine
        mov     ES:IORtn,AX             ; ...
        mov     AX,4[BP]                ; ...
        mov     ES:IORtn+2,AX           ; ...
        mov     ES:SaveReg,BX           ; save state
        mov     ES:SaveReg+2,CX         ; ... (in case ERR= or END=)
        mov     ES:SaveReg+4,DX         ; ...
        mov     ES:SaveReg+6,DI         ; ...
        mov     ES:SaveReg+8,SI         ; ...
        mov     AX,0[BP]                ; ... (original BP if on the stack)
        mov     ES:SaveReg+10,AX        ; ...
        mov     ES:SaveSeg,DS           ; ...

⌨️ 快捷键说明

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