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

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

Unix styled scripts is working!

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