summaryrefslogtreecommitdiffstats
path: root/private/ntos/nbt/vxd/vxdstub.asm
blob: 0404c3dda671b4c57a6609864d26eec2cb882d7a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
        name    vxdstub
;************************************************************************
;
;   (C) Copyright MICROSOFT Corp., 1990-1991
;
;   Title:      VXDSTUB.ASM
;
;   Date:       1-Jun-1991 
;
;   Author:     Neil Sandlin
;
;************************************************************************
	INCLUDE INT2FAPI.INC
;----------------------------- M A C R O S ------------------------------
Writel	MACRO	addr
        push	ax
        push	bx
        push	cx
        push	dx

        mov     dx,offset &addr         ;Print
        mov     cx,&addr&l   
        mov     bx,1                    ;stdout
        mov     ah,40h                  ;write
        int     21h

        pop     dx
        pop     cx
        pop     bx
        pop     ax	
        ENDM

;----------------------------- E Q U A T E S -----------------------------

cr      equ     0dh
lf      equ     0ah


_TEXT   segment word public 'CODE'
        assume cs:_TEXT,ds:_DATA

;*-----------------------  TSR Data Area ---------------------*
InstData Win386_Startup_Info_Struc <>
oldint  dd      0

;*-----------------------  TSR Code --------------------------*
        

handle2f proc
	cmp	ax,1605h
	jnz	@f
	push	di
	lea	di,InstData
	mov	word ptr cs:[di].SIS_Next_Ptr,bx
	mov	word ptr cs:[di][2].SIS_Next_Ptr,es
	pop	di
	push	cs
	pop	es
	lea	bx,InstData
@@:
        jmp     DWORD PTR [oldint]
handle2f endp

        ALIGN   16
init_fence:

_TEXT ends

;*----------------------  Initialization Data ------------------------*

_DATA   segment word public 'DATA'

TSR_rsv dw      ?

intmsg  db      cr,lf,'Hooking interrupt '
intmsgx dd      ?
        db      cr,lf
intmsgl equ     $-intmsg

hndmsg  db      cr,lf,'ISR entry point:  '
hndmsga dd      ?
        db      ':'
hndmsgb dd      ?
        db      ', length='
hndmsgc dd      ?
        db      'h bytes'
        db      cr,lf
hndmsgl equ     $-hndmsg

tsrmsg  db      'TSR; reserving '
tsrmsgx dd      ?
        db      ' paragraphs'
        db      cr,lf
tsrmsgl equ     $-tsrmsg

_DATA   ends


_TEXT   segment word public 'CODE'
;*-------------------------- Initialization Code ----------------------*

vxdstub     proc    far
        mov     ax, _DATA
        mov     ds, ax

; get a pointer to the name of the load file in the environment seg.

	mov	ah,62h
	int	21h			;bx -> psp
	mov	es,bx
	mov	bx,2ch			;environment segment
	mov	es,es:[bx]		
	xor	di,di
	mov	cx,-1			;big number
	xor	al,al			;search for a null
	cld				
@@:
	repne	scasb			;get past one null and stop
	cmp	byte ptr es:[di],0	;another null
	jnz	@b			;no.
	add	di,3			;skip the word before the name.

; prepare part of the instance data list. Stuff in pointer to the file name
; and refernce data 

	lea	si,InstData
	mov	word ptr CS:[si].SIS_Version,3
	mov	word ptr CS:[si].SIS_Virt_Dev_File_Ptr,di
	mov	word ptr CS:[si][2].SIS_Virt_Dev_File_Ptr,es

	mov	word ptr cs:[si].SIS_Instance_Data_Ptr,0
	mov	word ptr cs:[si][2].SIS_Instance_Data_Ptr,0

; Write message and hook interrupt 2f
        mov     ax, 2fh
        mov     bx, offset intmsgx
        call    hexasc

        Writel  intmsg                          

        mov     ah, 35h
        mov     al, 2fh
        int     21h                     ; get old vector
        mov     WORD PTR cs:oldint,bx   ; save old vector here
        mov     WORD PTR cs:oldint+2,es

        push    ds
        mov     dx, offset handle2f
        push    cs                      ; get current code segment
        pop     ds
        mov     ah, 25h
        mov     al, 2fh                 ; vector to hook
        int     21h                     ; hook that vector
        pop     ds


; Print out some information about the handler

        push    cs                      ; code segment
        pop     ax
        mov     bx, offset hndmsga
        call    hexasc

        mov     ax, offset handle2f     ; offset of ISR
        mov     bx, offset hndmsgb
        call    hexasc

        mov     ax, offset init_fence   ; length in bytes of handler
        mov     bx, offset hndmsgc
        call    hexasc

        Writel  hndmsg

; Compute size of TSR area

        mov     dx, offset init_fence   ; start of initialization code
        add     dx, 15                  ; round it off to paragraph
        shr     dx, 1                   ; divide by 16
        shr     dx, 1
        shr     dx, 1
        shr     dx, 1
        add     dx, 32                  ; add in PSP
        mov     TSR_rsv, dx             ; save it

        mov     ax, dx
        mov     bx, offset tsrmsgx
        call    hexasc

        Writel  tsrmsg

; Terminate and stay resident
        
        mov     ax, 3100h               ; TSR
        mov     dx, TSR_rsv             ; # of paragraphs to reserve
        int     21h                     ; TSR
vxdstub     endp



;************************************************************************
;
;       HEXASC
;
;       This subroutine formats hex values into ASCII
;       (utility routine from Advanced MS-DOS Programming)
;
;
;************************************************************************

hexasc  proc    near            ; converts word to hex ASCII
                                ; call with AX = value,
                                ; DS:BX = address for string
                                ; returns AX, BX destroyed

        push    cx              ; save registers
        push    dx

        mov     dx,4            ; initialize character counter
hexasc1:
        mov     cx,4            ; isolate next four bits
        rol     ax,cl
        mov     cx,ax
        and     cx,0fh
        add     cx,'0'          ; convert to ASCII
        cmp     cx,'9'          ; is it 0-9?
        jbe     hexasc2         ; yes, jump
        add     cx,'A'-'9'-1    ; add fudge factor for A-F

hexasc2:                        ; store this character
        mov     [bx],cl
        inc     bx              ; bump string pointer

        dec     dx              ; count characters converted
        jnz     hexasc1         ; loop, not four yet

        pop     dx              ; restore registers
        pop     cx
        ret                     ; back to caller

hexasc  endp

        

_TEXT   ends



        end     vxdstub