1 | ; $Id: mytkExecPgm.asm,v 1.2 2000-02-18 19:54:19 bird Exp $
|
---|
2 | ;
|
---|
3 | ; mytkExecPgm - tkExecPgm overload
|
---|
4 | ;
|
---|
5 | ; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
6 | ;
|
---|
7 | ; Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | ;
|
---|
9 | .386p
|
---|
10 |
|
---|
11 | ;
|
---|
12 | ; Include files
|
---|
13 | ;
|
---|
14 | include devsegdf.inc
|
---|
15 |
|
---|
16 | ;
|
---|
17 | ; Imported Functions
|
---|
18 | ;
|
---|
19 | extrn g_tkExecPgm:PROC
|
---|
20 | extrn AcquireBuffer:PROC
|
---|
21 | extrn ReleaseBuffer:PROC
|
---|
22 | extrn QueryBufferSegmentOffset:PROC
|
---|
23 |
|
---|
24 | ;
|
---|
25 | ; Exported symbols
|
---|
26 | ;
|
---|
27 | public mytkExecPgm
|
---|
28 | public pszFilename
|
---|
29 | public pszArguments
|
---|
30 |
|
---|
31 |
|
---|
32 | DATA32 SEGMENT
|
---|
33 | pszFilename dd 0 ; Pointer to the filename (in the buffer)
|
---|
34 | pszArguments dd 0 ; Pointer to the arguments (int the buffer)
|
---|
35 | DATA32 ENDS
|
---|
36 |
|
---|
37 |
|
---|
38 | CODE32 SEGMENT
|
---|
39 |
|
---|
40 | ;;
|
---|
41 | ;
|
---|
42 | ; @returns same as tkExecPgm: eax, edx and carry flag
|
---|
43 | ; @param ax Exec flag
|
---|
44 | ; ds:dx Filename address. (String)
|
---|
45 | ; es:bx Environment address. (String)
|
---|
46 | ; di:si Argument address. (String)
|
---|
47 | ; @uses all - bp
|
---|
48 | ; @status
|
---|
49 | ; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
50 | ; @remark Current implemententation assumes that there is one buffer,
|
---|
51 | ; this serializes the usage of the two pointers.
|
---|
52 | ;
|
---|
53 | ; The buffer we are using is a C struct as follows.
|
---|
54 | ; struct Buffer
|
---|
55 | ; {
|
---|
56 | ; char szFilename[261]; /* offset 0 */
|
---|
57 | ; char szArg[4096-261]; /* offset 261 */
|
---|
58 | ; };
|
---|
59 | ;
|
---|
60 | mytkExecPgm PROC FAR
|
---|
61 | pBuffer = dword ptr -04h
|
---|
62 | ;SegBuffer = word ptr (dword ptr -08h)
|
---|
63 | SegBuffer = -08h
|
---|
64 | ;OffBuffer = word ptr (dword ptr -0Ch)
|
---|
65 | OffBuffer = -0Ch
|
---|
66 | cchFilename = dword ptr -10h
|
---|
67 | cchArgs = dword ptr -14h
|
---|
68 | ASSUME CS:CODE32, DS:NOTHING, SS:NOTHING
|
---|
69 | push ebp
|
---|
70 | mov ebp, esp
|
---|
71 | lea esp, [ebp + cchArgs]
|
---|
72 |
|
---|
73 | push eax
|
---|
74 | push ecx
|
---|
75 | push ds
|
---|
76 | push es
|
---|
77 | push edi
|
---|
78 |
|
---|
79 | ; init local variables
|
---|
80 | mov [ebp+pBuffer], 0
|
---|
81 |
|
---|
82 | ; filename length
|
---|
83 | mov ax, ds
|
---|
84 | mov es, ax
|
---|
85 | xor eax, eax
|
---|
86 | movzx edi, dx ; es:di is now filename address (ds:dx).
|
---|
87 | mov ecx, 0ffffffffh
|
---|
88 | repne scasb
|
---|
89 | not ecx
|
---|
90 |
|
---|
91 | ;
|
---|
92 | ; if filename length is more that CCHMAXPATH then we don't do anything!.
|
---|
93 | ;
|
---|
94 | cmp ecx, 260
|
---|
95 | jae mytkExecPgm_CalltkExecPgm_X1; length >= 260
|
---|
96 | mov [ebp+cchFilename], ecx
|
---|
97 |
|
---|
98 | ;
|
---|
99 | ; args length
|
---|
100 | ;
|
---|
101 | pop edi
|
---|
102 | push edi
|
---|
103 | mov es, di
|
---|
104 | movzx edi, si ; es:di is now args address (di:si), eax is still 0
|
---|
105 | mov ecx, 0ffffffffh
|
---|
106 | repne scasb
|
---|
107 | not ecx
|
---|
108 |
|
---|
109 | mov [ebp+cchArgs], ecx
|
---|
110 | add ecx, [ebp+cchFilename] ; filename
|
---|
111 | add ecx, 3 + 260 ; 260 = new argument from a scrip file or something.
|
---|
112 | ; 3 = two '\0's and a space after added argument.
|
---|
113 | cmp ecx, 4096 ; 4096 = Buffersize. FIXME! Define this!!!
|
---|
114 | jae mytkExecPgm_CalltkExecPgm_X1; jmp if argument + file + new file > buffer size
|
---|
115 |
|
---|
116 | ;
|
---|
117 | ; Aquire a buffer
|
---|
118 | ;
|
---|
119 | call AcquireBuffer
|
---|
120 | or eax, eax
|
---|
121 | jz mytkExecPgm_CalltkExecPgm_X1; Failed to get buffer.
|
---|
122 | mov [ebp+pBuffer], eax
|
---|
123 |
|
---|
124 | ;
|
---|
125 | ; Get Segment and offset for the buffer
|
---|
126 | ;
|
---|
127 | call QueryBufferSegmentOffset
|
---|
128 | mov cx, es
|
---|
129 | mov [ebp+OffBuffer], ax
|
---|
130 | mov [ebp+SegBuffer], es
|
---|
131 | test eax, 000570000h
|
---|
132 | jnz mytkExecPgm_CalltkExecPgm_X2
|
---|
133 |
|
---|
134 | ;
|
---|
135 | ; Copy filename to pBuffer.
|
---|
136 | ;
|
---|
137 | push esi
|
---|
138 | mov edi, eax ; es:di pBuffer
|
---|
139 | movzx esi, dx ; ds:si Filename pointer (input ds:dx)
|
---|
140 | mov ecx, [ebp+cchFilename]
|
---|
141 | repnz movsb
|
---|
142 |
|
---|
143 | ;
|
---|
144 | ; Copy Args to pBuffer + 261
|
---|
145 | ;
|
---|
146 | ; stack: esi, edi, es, ds, ecx, eax
|
---|
147 | pop esi
|
---|
148 | pop edi
|
---|
149 | push edi
|
---|
150 | push esi
|
---|
151 | mov ds, di ; ds:si -> arguments
|
---|
152 | mov edi, eax
|
---|
153 | add edi, 261 ; es:di -> pBuffer + 261
|
---|
154 | mov ecx, [ebp+cchArgs]
|
---|
155 | repnz movsb
|
---|
156 |
|
---|
157 | ;
|
---|
158 | ; Set Pointers, pszFilename and pszArguments
|
---|
159 | ;
|
---|
160 | mov ax, seg FLAT:DATA32
|
---|
161 | mov ds, ax
|
---|
162 | ASSUME ds:FLAT
|
---|
163 | mov eax, ss:[ebp+pBuffer]
|
---|
164 | mov pszFilename, eax
|
---|
165 | add eax, 261
|
---|
166 | mov pszArguments, eax
|
---|
167 |
|
---|
168 | ;
|
---|
169 | ; Restore variables pushed on the stack
|
---|
170 | ;
|
---|
171 | ; stack: esi, edi, es, ds, ecx, eax
|
---|
172 | pop esi
|
---|
173 | pop edi
|
---|
174 | pop es
|
---|
175 | pop ds
|
---|
176 | pop ecx
|
---|
177 | pop eax
|
---|
178 |
|
---|
179 | ;
|
---|
180 | ; Set new input parameters (call g_tkExecPgm)
|
---|
181 | ;
|
---|
182 | ; ds:dx is to become SegBuffer:OffBuffer
|
---|
183 | ; di:si is to become SegBuffer:OffBuffer+261
|
---|
184 | ;
|
---|
185 | ; The some of the old values are stored on the stack (for the time being)
|
---|
186 | push ds
|
---|
187 | push edi
|
---|
188 | push esi
|
---|
189 |
|
---|
190 | mov di, [ebp+SegBuffer]
|
---|
191 | mov ds, di
|
---|
192 | mov si, [ebp+OffBuffer]
|
---|
193 | mov dx, si ; ds:dx SegBuffer:OffBuffer
|
---|
194 | add si, 261 ; di:si SegBuffer:OffBuffer+261
|
---|
195 |
|
---|
196 | ;
|
---|
197 | ; Call g_tkExecPgm
|
---|
198 | ;
|
---|
199 | call far ptr FLAT:g_tkExecPgm;WARNING far call!!!
|
---|
200 | pushfd
|
---|
201 |
|
---|
202 | ;
|
---|
203 | ; Release buffer
|
---|
204 | ;
|
---|
205 | push eax
|
---|
206 | mov eax, [ebp + pBuffer]
|
---|
207 | call ReleaseBuffer
|
---|
208 | mov [ebp + pBuffer], 0
|
---|
209 | pop eax
|
---|
210 |
|
---|
211 | ;
|
---|
212 | ; Return
|
---|
213 | ;
|
---|
214 | popfd
|
---|
215 | pop esi
|
---|
216 | pop edi
|
---|
217 | pop ds
|
---|
218 | leave
|
---|
219 | retf
|
---|
220 |
|
---|
221 | mytkExecPgm_CalltkExecPgm_X2:
|
---|
222 | ;
|
---|
223 | ; Release buffer
|
---|
224 | ;
|
---|
225 | mov eax, [ebp + pBuffer]
|
---|
226 | call ReleaseBuffer
|
---|
227 | mov [ebp + pBuffer], 0
|
---|
228 |
|
---|
229 | mytkExecPgm_CalltkExecPgm_X1:
|
---|
230 | pop edi
|
---|
231 | pop es
|
---|
232 | pop ds
|
---|
233 | pop ecx
|
---|
234 | pop eax
|
---|
235 |
|
---|
236 | mytkExecPgm_CalltkExecPgm:
|
---|
237 | call far ptr FLAT:g_tkExecPgm
|
---|
238 | leave
|
---|
239 | retf
|
---|
240 | mytkExecPgm ENDP
|
---|
241 |
|
---|
242 | CODE32 ENDS
|
---|
243 | END
|
---|
244 |
|
---|