source: trunk/src/win32k/ldr/mytkExecPgm.asm@ 2849

Last change on this file since 2849 was 2849, checked in by bird, 26 years ago

Finally it's working! (Or at least it seems like working...)

File size: 12.5 KB
Line 
1; $Id: mytkExecPgm.asm,v 1.8 2000-02-21 15:59:21 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 ; Scans strings until empy-string is reached.
25 ; input: bx:di
26 ; uses: nearly all (save bp)
27 ; return: cx size - CF clear
28 ; ax error- CF set
29 extrn _f_FuStrLenZ:PROC
30
31 ; Stringlength
32 ; input: bx:di
33 ; uses: nearly all (save bp)
34 ; return: cx size - CF clear
35 ; ax error- CF set
36 extrn _f_FuStrLen:PROC
37
38 ;memcpy
39 ;input: bx:si pointer to source
40 ; es:di pointer to target
41 ; cx count of bytes to copy
42 ;uses: nearly all (save bp), es, ds
43 ;return: success CF clear
44 ; failure CF set
45 extrn _f_FuBuff:PROC
46
47;
48; Exported symbols
49;
50 public mytkExecPgm
51
52
53
54CODE32 SEGMENT
55
56;;
57;
58; @returns same as tkExecPgm: eax, edx and carry flag
59; @param ax Exec flag
60; ds:dx Filename address. (String)
61; es:bx Environment address. (String)
62; di:si Argument address. (String)
63; @uses all - bp
64; @status
65; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
66; @remark Current implemententation assumes that there is one buffer,
67; this serializes the usage of the two pointers.
68;
69; The buffer we are using is a C struct as follows.
70; struct Buffer
71; {
72; char szFilename[261]; /* offset 0 */
73; char achArg[1536-261]; /* offset 261 */
74; };
75;
76mytkExecPgm PROC FAR
77pBuffer = dword ptr -04h
78SegBuffer = -08h
79OffBuffer = -0Ch
80cchFilename = dword ptr -10h
81cchArgs = dword ptr -14h
82;usExecFlag = -18h
83;SegFilename = -1ch
84;OffFilename = -1eh
85;SegEnv = -20h
86;OffEnv = -22h
87;SegArg = -24h
88;OffArg = -26h
89
90 ASSUME CS:CODE32, DS:NOTHING, SS:NOTHING
91 push ebp
92 mov ebp, esp
93 lea esp, [ebp + cchArgs]
94
95 push eax
96 push ecx
97 push ds
98 push es
99 push edi
100
101 ; parameter validations
102 mov ax, ds ; pointer to filename
103 cmp ax, 4
104 jb mytkExecPgm_CalltkExecPgm_X1
105
106 ;
107 ; filename length
108 ;
109 mov ax, ds
110 mov es, ax
111 pushad
112 push es
113 push ds
114 mov bx, ds
115 mov di, dx ; es:di is now filename address (ds:dx).
116 push cs ; Problem calling far into the calltab segement.
117 call near ptr FLAT:_f_FuStrLen
118 movzx ecx, cx
119 mov [ebp+cchFilename], ecx
120 pop ds
121 pop es
122 popad
123 jc mytkExecPgm_CalltkExecPgm_X1; If the FuStrLen call failed we bail out!
124
125 ;
126 ; if filename length is more that CCHMAXPATH then we don't do anything!.
127 ;
128 cmp [ebp+cchFilename], 260
129 jae mytkExecPgm_CalltkExecPgm_X1; length >= 260
130
131 ;
132 ; args length
133 ; Note: the arguments are a series of ASCIIZs ended by an empty string (ie. '\0').
134 ;
135 pop edi
136 push edi
137 xor ecx, ecx
138 cmp di, 4 ; The argument might me a invalid pointer...
139 jb mytkExecPgm_CalltkExecPgm_1
140
141 pushad
142 push es
143 push ds
144 mov bx, di ;
145 mov di, si ; bx:di -> arguments
146 push cs ; Problem calling far into the calltab segement.
147 call near ptr FLAT:_f_FuStrLenZ
148 movzx ecx, cx
149 mov [ebp+cchArgs], ecx
150 pop ds
151 pop es
152 popad
153 jc mytkExecPgm_CalltkExecPgm_X1
154
155mytkExecPgm_CalltkExecPgm_1:
156 mov ecx, [ebp+cchArgs]
157 add ecx, [ebp+cchFilename] ; filename
158 add ecx, 3 + 260 ; 260 = new argument from a scrip file or something.
159 ; 3 = two '\0's and a space after added argument.
160 cmp ecx, 1536 ; 1536 = Buffersize. FIXME! Define this!!!
161 jae mytkExecPgm_CalltkExecPgm_X1; jmp if argument + file + new file > buffer size
162
163 ;
164 ; Aquire a buffer
165 ;
166 call AcquireBuffer
167 or eax, eax
168 jz mytkExecPgm_CalltkExecPgm_X1; Failed to get buffer.
169 mov [ebp+pBuffer], eax
170
171 ;
172 ; Get Segment and offset for the buffer
173 ;
174 call QueryBufferSegmentOffset
175 mov cx, es
176 mov [ebp+OffBuffer], ax
177 mov [ebp+SegBuffer], es
178 test eax, 000570000h
179 jnz mytkExecPgm_CalltkExecPgm_X2
180
181 ;
182 ; Copy filename to pBuffer.
183 ;
184 pushad
185 push es
186 push ds
187 mov di, ax ; es:di pBuffer
188 mov si, dx
189 mov bx, ds ; bx:si Filename pointer (input ds:dx)
190 mov ecx, [ebp+cchFilename]
191 push cs ; Problem calling far into the calltab segement.
192 call near ptr FLAT:_f_FuBuff
193 pop ds
194 pop es
195 popad
196 jc mytkExecPgm_CalltkExecPgm_X2
197
198 ;
199 ; Copy Args to pBuffer + 261
200 ;
201 ; stack: edi, es, ds, ecx, eax
202 pop edi
203 push edi
204 add eax, 261 ; we'll use eax in the branch
205 cmp di, 4
206 jb mytkExecPgm_CalltkExecPgm_2
207 pushad
208 push es
209 push ds
210 mov ecx, [ebp+cchArgs]
211 mov bx, di ; ds:si -> arguments
212 mov di, ax ; es:di -> buffer + 261
213 push cs ; Problem calling far into the calltab segement.
214 call near ptr FLAT:_f_FuBuff
215 pop ds
216 pop es
217 popad
218 jc mytkExecPgm_CalltkExecPgm_X2
219 jmp mytkExecPgm_CalltkExecPgm_3
220
221mytkExecPgm_CalltkExecPgm_2:
222 mov word ptr es:[eax], 0 ; Terminate the empty string!
223
224 ;
225 ; Restore variables pushed on the stack
226 ;
227 ; stack: edi, es, ds, ecx, eax
228mytkExecPgm_CalltkExecPgm_3:
229 pop edi
230 pop es
231 pop ds
232 pop ecx
233 pop eax
234
235 ;
236 ; Set new input parameters (call _g_tkExecPgm)
237 ;
238 ; ds:dx is to become SegBuffer:OffBuffer
239 ; di:si is to become SegBuffer:OffBuffer+261
240 ;
241 ; The some of the old values are stored on the stack (for the time being)
242 push ds
243 push edi
244 push esi
245
246 mov di, [ebp+SegBuffer]
247 mov ds, di
248 mov si, [ebp+OffBuffer]
249 mov dx, si ; ds:dx SegBuffer:OffBuffer
250 add si, 261 ; di:si SegBuffer:OffBuffer+261
251
252 ;
253 ; Call _g_tkExecPgm
254 ;
255 push cs ; Problem calling far into the calltab segement.
256 call near ptr FLAT:_g_tkExecPgm
257 pushfd
258
259 ;
260 ; Release buffer
261 ;
262 push eax
263 mov eax, [ebp + pBuffer]
264 call ReleaseBuffer
265 mov [ebp + pBuffer], 0
266 pop eax
267
268 ;
269 ; Return
270 ;
271 popfd
272 pop esi
273 pop edi
274 pop ds
275 leave
276 retf
277
278mytkExecPgm_CalltkExecPgm_X2:
279 ;
280 ; Release buffer
281 ;
282 mov eax, [ebp + pBuffer]
283 call ReleaseBuffer
284 mov [ebp + pBuffer], 0
285
286mytkExecPgm_CalltkExecPgm_X1:
287 pop edi
288 pop es
289 pop ds
290 pop ecx
291 pop eax
292
293mytkExecPgm_CalltkExecPgm:
294 push cs
295 call near ptr FLAT:_g_tkExecPgm
296 leave
297 retf
298mytkExecPgm ENDP
299
300
301
302CODE32 ENDS
303
304if 0 ; alternate implementation.
305mytkExecPgm PROC FAR
306pBuffer = dword ptr -04h
307SegBuffer = -08h
308OffBuffer = -0Ch
309cchFilename = -10h
310cchArgs = -14h
311usExecFlag = -18h
312SegFilename = -1ch
313OffFilename = -1eh
314SegEnv = -20h
315OffEnv = -22h
316SegArg = -24h
317OffArg = -26h
318
319 ASSUME CS:CODE32, DS:NOTHING, SS:NOTHING
320 push ebp
321 mov ebp, esp
322 lea esp, [ebp + OffArg]
323
324 ; save input parameters
325 mov [ebp + usExecFlag], ax
326 mov ax, es
327 mov [ebp + SegEnv], ax
328 mov [ebp + OffEnv], bx
329 mov [ebp + SegArg], di
330 mov [ebp + OffArg], si
331 mov ax, ds
332 mov [ebp + SegFilename], ax
333 mov [ebp + OffFilename], dx
334
335 ; parameter validations
336 cmp ax, 4 ; pointer to filename
337 jb mytkExecPgm_CalltkExecPgm_X1
338
339 ;
340 ; filename length
341 ;
342 mov bx, ax
343 mov di, dx ; bx:di is now filename address
344 push cs ; Problem calling far into the calltab segement.
345 call near ptr FLAT:_f_FuStrLen
346 jc mytkExecPgm_CalltkExecPgm_X1; If the FuStrLen call failed we bail out!
347
348 ;
349 ; if filename length is more that CCHMAXPATH then we don't do anything!.
350 ;
351 cmp cx, 260
352 jae mytkExecPgm_CalltkExecPgm_X1; length >= 260
353 mov [ebp+cchFilename], cx
354
355 ;
356 ; args length
357 ; Note: the arguments are a series of ASCIIZs ended by an empty string (ie. '\0').
358 ;
359 mov bx, [ebp+SegArg]
360 cmp bx, 4 ; The argument might me an NULL pointer
361 xor cx, cx
362 jb mytkExecPgm_CalltkExecPgm_1
363
364 mov di, [ebp+OffArg] ; bx:di -> arguments
365 push cs ; Problem calling far into the calltab segement.
366 call near ptr FLAT:_f_FuStrLenZ
367 mov [ebp+cchArgs], cx
368 jc mytkExecPgm_CalltkExecPgm_X1
369
370mytkExecPgm_CalltkExecPgm_1:
371 add cx, [ebp+cchFilename] ; filename length
372 add cx, 3 + 260 ; 260 = new argument from a scrip file or something.
373 ; 3 = two '\0's and a space after added argument.
374 cmp ecx, 1536 ; 1536 = Buffersize. FIXME! Define this!!!
375 jae mytkExecPgm_CalltkExecPgm_X1; jmp if argument + file + new file > buffer size
376
377 ;
378 ; Aquire a buffer
379 ;
380 call AcquireBuffer
381 mov [ebp+pBuffer], eax
382 or eax, eax
383 jz mytkExecPgm_CalltkExecPgm_X1; Failed to get buffer.
384
385 ;
386 ; Get Segment and offset for the buffer
387 ;
388 call QueryBufferSegmentOffset
389 mov cx, es
390 mov [ebp+OffBuffer], ax
391 mov [ebp+SegBuffer], es
392 test eax, 000570000h
393 jnz mytkExecPgm_CalltkExecPgm_X2
394
395 ;
396 ; Copy filename to pBuffer.
397 ;
398 mov di, ax ; es:di pBuffer
399 mov si, dx
400 mov bx, ds ; bx:si Filename pointer (input ds:dx)
401 mov cx, [ebp+cchFilename] ; cx = length of area to copy
402 push cs ; Problem calling far into the calltab segement.
403 call near ptr FLAT:_f_FuBuff
404 jc mytkExecPgm_CalltkExecPgm_X2
405
406 ;
407 ; Copy Args to pBuffer + 261
408 ;
409 mov si, [ebp+SegArg]
410 cmp si, 4
411 jb mytkExecPgm_CalltkExecPgm_2
412 mov ds, si
413 mov si, [ebp+OffArg] ; ds:si -> arguments
414 mov di, [ebp+SegBuffer]
415 mov es, di
416 mov di, [ebp+OffBuffer]
417 add di, 261 ; es:di -> buffer + 261
418 mov cx, [ebp+cchArgs] ; cx = length of area to copy
419 push cs ; Problem calling far into the calltab segement.
420 call near ptr FLAT:_f_FuBuff
421 jc mytkExecPgm_CalltkExecPgm_X2
422 jmp mytkExecPgm_CalltkExecPgm_3
423
424mytkExecPgm_CalltkExecPgm_2:
425 mov word ptr es:[eax], 0 ; Terminate the empty string!
426
427 ;
428 ; Set new input parameters (call _g_tkExecPgm)
429 ;
430 ; ds:dx is to become SegBuffer:OffBuffer
431 ; di:si is to become SegBuffer:OffBuffer+261
432 ;
433mytkExecPgm_CalltkExecPgm_3:
434 mov di, [ebp+SegBuffer]
435 mov ds, di
436 mov si, [ebp+OffBuffer]
437 mov dx, si ; ds:dx SegBuffer:OffBuffer
438 add si, 261 ; di:si SegBuffer:OffBuffer+261
439 mov bx, [ebp+SegEnv]
440 mov es, bx
441 mov bx, [ebp+SegEnv]
442
443 ;
444 ; Call _g_tkExecPgm
445 ;
446 push cs ; Problem calling far into the calltab segement.
447 call near ptr FLAT:_g_tkExecPgm
448 pushfd
449
450 ;
451 ; Release buffer
452 ;
453 push eax
454 mov eax, [ebp + pBuffer]
455 call ReleaseBuffer
456 mov [ebp + pBuffer], 0
457 pop eax
458
459 ;
460 ; Return
461 ;
462 push [ebp + SegFilename]
463 pop ds
464 push [ebp + SegEnv]
465 pop es
466 popfd
467 leave
468 retf
469
470mytkExecPgm_CalltkExecPgm_X2:
471 ;
472 ; Release buffer
473 ;
474 mov eax, [ebp + pBuffer]
475 call ReleaseBuffer
476 mov [ebp + pBuffer], 0
477
478mytkExecPgm_CalltkExecPgm_X1:
479 pop ds
480
481mytkExecPgm_CalltkExecPgm:
482 push cs
483 call near ptr FLAT:_g_tkExecPgm
484 leave
485 retf
486mytkExecPgm ENDP
487
488CODE32 ENDS
489endif
490
491
492END
493
Note: See TracBrowser for help on using the repository browser.