windll.asm

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

ASM
552
字号
        DLL_Entry       20
        DLL_Entry       21
        DLL_Entry       22
        DLL_Entry       23
        DLL_Entry       24
        DLL_Entry       25
        DLL_Entry       26
        DLL_Entry       27
        DLL_Entry       28
        DLL_Entry       29
        DLL_Entry       30
        DLL_Entry       31
        DLL_Entry       32
        DLL_Entry       33
        DLL_Entry       34
        DLL_Entry       35
        DLL_Entry       36
        DLL_Entry       37
        DLL_Entry       38
        DLL_Entry       39
        DLL_Entry       40
        DLL_Entry       41
        DLL_Entry       42
        DLL_Entry       43
        DLL_Entry       44
        DLL_Entry       45
        DLL_Entry       46
        DLL_Entry       47
        DLL_Entry       48
        DLL_Entry       49
        DLL_Entry       50
        DLL_Entry       51
        DLL_Entry       52
        DLL_Entry       53
        DLL_Entry       54
        DLL_Entry       55
        DLL_Entry       56
        DLL_Entry       57
        DLL_Entry       58
        DLL_Entry       59
        DLL_Entry       60
        DLL_Entry       61
        DLL_Entry       62
        DLL_Entry       63
        DLL_Entry       64
        DLL_Entry       65
        DLL_Entry       66
        DLL_Entry       67
        DLL_Entry       68
        DLL_Entry       69
        DLL_Entry       70
        DLL_Entry       71
        DLL_Entry       72
        DLL_Entry       73
        DLL_Entry       74
        DLL_Entry       75
        DLL_Entry       76
        DLL_Entry       77
        DLL_Entry       78
        DLL_Entry       79
        DLL_Entry       80
        DLL_Entry       81
        DLL_Entry       82
        DLL_Entry       83
        DLL_Entry       84
        DLL_Entry       85
        DLL_Entry       86
        DLL_Entry       87
        DLL_Entry       88
        DLL_Entry       89
        DLL_Entry       90
        DLL_Entry       91
        DLL_Entry       92
        DLL_Entry       93
        DLL_Entry       94
        DLL_Entry       95
        DLL_Entry       96
        DLL_Entry       97
        DLL_Entry       98
        DLL_Entry       99
        DLL_Entry       100
        DLL_Entry       101
        DLL_Entry       102
        DLL_Entry       103
        DLL_Entry       104
        DLL_Entry       105
        DLL_Entry       106
        DLL_Entry       107
        DLL_Entry       108
        DLL_Entry       109
        DLL_Entry       110
        DLL_Entry       111
        DLL_Entry       112
        DLL_Entry       113
        DLL_Entry       114
        DLL_Entry       115
        DLL_Entry       116
        DLL_Entry       117
        DLL_Entry       118
        DLL_Entry       119
        DLL_Entry       120
        DLL_Entry       121
        DLL_Entry       122
        DLL_Entry       123
        DLL_Entry       124
        DLL_Entry       125
        DLL_Entry       126
        DLL_Entry       127
        DLL_Entry       128

__DLL_entry proc        near
        sub     EDX,EDX                 ; zero full register
        pop     DX                      ; get return address
        sub     DX,offset DLL1 - 1      ; calc. index * 4
        inc     bp                      ; indicate far return address
        push    bp                      ; save bp
        mov     bp,sp                   ; get access to parms
        lea     cx,[bp+6-2]             ; point to stack parms
        call    __CommonLibEntry        ; goto common library entry
        pop     bp                      ; restore bp
        dec     bp                      ; decrement bp
        pop     ebx                     ; return address
        add     sp,cx                   ; number of bytes for parms
        push    ebx                     ; restore return address
        retf                            ; go back
__DLL_entry endp

;****************************************************************************
;***                                                                      ***
;*** Win386LibEntry - the single 16-bit entry point for all stuff         ***
;***                  the first word on the stack is the function number, ***
;***                  all other data is determined by the function -      ***
;***                  the user must assign all library entry points       ***
;***                  during initialization                               ***
;***                                                                      ***
;****************************************************************************
public Win386LibEntry
Win386LibEntry proc far
        inc     bp                      ; indicate far call
        push    bp                      ; save bp
        mov     bp,sp                   ; get access to parms
        sub     edx,edx                 ; zero full register
        mov     dx,6[bp]                ; get DLL entry number
        shl     dx,2                    ; times 4
        lea     cx,[bp+6]               ; point to stack parms
        call    __CommonLibEntry        ; goto common library entry
        pop     bp                      ; restore bp
        dec     bp                      ; decrement bp
        pop     ebx                     ; return address
        add     sp,cx                   ; number of bytes for parms
        add     sp,2                    ; remove the extra parm
        push    ebx                     ; restore return address
        ret                             ; go back
Win386LibEntry endp

__CommonLibEntry proc near
        push    si                      ; save si
        push    di                      ; save di
        push    ds                      ; save ds
        push    es                      ; save es
;*
;** save stack info, set up new stack
;*
        mov     ax,ss                   ; get old ss
        mov     es,ax                   ;   to unload parms
        mov     ds,cs:dsvalue           ; get our DS value
        assume  ds:DGROUP
        mov     ax,ds                   ; set GS=DS
        mov     gs,ax                   ; ...

        push    _SaveSP                 ; save current 32-bit sp

        mov     word ptr ds:[_EntryStackSave],sp   ; save current sp
        mov     word ptr ds:[_EntryStackSave+2],ss ; save stack segment

        mov     ss,_StackSelector       ; new sp
        mov     esp,_SaveSP             ; current 32 bit stack

;*
;*** load the magic registers
;*
        mov     ax,_DataSelector        ; load data selector
        mov     ds,ax                   ; get 32 bit data selector
        push    gs                      ; save this ds

;*
;*** build entry point
;*** entry as follows:
;***
;***    LONG  - routine         (offset 0)
;***    SHORT - number of parms (offset 4)
;***    SHORT - total bytes     (offset 6)
;***    SHORT - size 1          (offset 8)
;***    ...
;***    SHORT - size N          (offset 6+N*2)
;*
        mov     si,cx                   ; point to stack parms
        add     edx,gs:__DLLEntryAddr   ; dll table addr
        mov     ebx,ds:[edx]            ; get specific dll entry
        mov     eax,ds:[ebx]            ; get address of routine
        mov     gs:DLLEIP,eax           ; save it
        mov     cx,word ptr ds:[ebx+4]  ; # of parms
        mov     dx,word ptr ds:[ebx+6]  ; # of bytes
        lea     edi,ds:[ebx+8]          ; first parm size entry
        add     si,dx                   ; go to first parm
        push    dx                      ; save # of bytes
        cmp     word ptr ds:[edi],4     ; is parm 4 bytes in size?
        jne     loopme                  ; no
        sub     si,2                    ; get to start of parm
loopme:
        cmp     cx,0                    ; done?
        je      doneparms               ; yep
        mov     ax,word ptr ds:[edi]    ; get size
        cmp     ax,2                    ; two bytes?
        jne     get4
        movzx   eax,word ptr es:[si]    ; got it
        jmp     short nextone
get4:   mov     eax,dword ptr es:[si]
nextone:push    eax
        dec     cx                      ; decrement count
        add     edi,2                   ; next size
        mov     ax,word ptr ds:[edi]
        sub     si,ax                   ; point at next guy
        jmp     loopme                  ; try again

;*
;*** invoke the 32-bit call back routine
;*
doneparms:
        mov     ax,ds
        mov     es,ax                   ; point es into flat area
        call    gs:[DLLRoutine]         ; invoke the 32 bit appl

;*
;*** restore state
;*
        pop     cx                      ; number of bytes extra on stack
        pop     ds                      ; dll's ds

        mov     ss,word ptr ds:[_EntryStackSave+2]
        movzx   esp,word ptr ds:[_EntryStackSave]

        pop     ds:_SaveSP

        pop     di                      ; restore es
        lsl     dx,di                   ; see if still valid?
        jz      short es_ok             ; jump if selector is valid
        sub     di,di                   ; set selector to 0
es_ok:  mov     es,di                   ; restore es

        pop     di                      ; restore ds
        lsl     dx,di                   ; see if still valid?
        jz      short ds_ok             ; jump if selector is valid
        sub     di,di                   ; set selector to 0
ds_ok:  mov     ds,di                   ; restore ds

        pop     di                      ; restore di
        pop     si                      ; restore si
        mov     edx,eax                 ; put the return code
        shr     edx,16                  ;   from eax to dx:ax
        ret                             ; return
__CommonLibEntry endp


;****************************************************************************
;***                                                                      ***
;*** StartDLL32 - invoke a 32-bit dll's entry code                        ***
;***                                                                      ***
;***       The 32 bit application must save gs, since that is our pointer ***
;***       to our data segment (given to us by windows)                   ***
;***                                                                      ***
;***       Our program image is as follows:                               ***
;***                                                                      ***
;***            0 -> send          Stack                                  ***
;***            send+1 -> cend     Code                                   ***
;***            cend+1 -> 

⌨️ 快捷键说明

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