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

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

Correction

File size: 7.7 KB
Line 
1; $Id: mytkExecPgm.asm,v 1.6 2000-02-21 09:35:45 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;
19DATA32 SEGMENT
20 extrn g_tkExecPgm:PROC
21DATA32 ENDS
22 extrn AcquireBuffer:PROC
23 extrn ReleaseBuffer:PROC
24 extrn QueryBufferSegmentOffset:PROC
25
26 ; Scans strings until empy-string is reached.
27 ; input: bx:di
28 ; uses: nearly all (save bp)
29 ; return: cx size - CF clear
30 ; ax error- CF set
31 extrn f_FuStrLenZ:PROC
32
33 ; Stringlength
34 ; input: bx:di
35 ; uses: nearly all (save bp)
36 ; return: cx size - CF clear
37 ; ax error- CF set
38 extrn f_FuStrLen:PROC
39
40 ;memcpy
41 ;input: bx:si pointer to source
42 ; es:di pointer to target
43 ; cx count of bytes to copy
44 ;uses: nearly all (save bp)
45 ;return: success CF clear
46 ; failure CF set
47 extrn f_FuBuff:PROC
48
49;
50; Exported symbols
51;
52 public mytkExecPgm
53 public pszFilename
54 public pszArguments
55
56
57DATA32 SEGMENT
58pszFilename dd 0 ; Pointer to the filename (in the buffer)
59pszArguments dd 0 ; Pointer to the arguments (int the buffer)
60DATA32 ENDS
61
62
63CODE32 SEGMENT
64
65;;
66;
67; @returns same as tkExecPgm: eax, edx and carry flag
68; @param ax Exec flag
69; ds:dx Filename address. (String)
70; es:bx Environment address. (String)
71; di:si Argument address. (String)
72; @uses all - bp
73; @status
74; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
75; @remark Current implemententation assumes that there is one buffer,
76; this serializes the usage of the two pointers.
77;
78; The buffer we are using is a C struct as follows.
79; struct Buffer
80; {
81; char szFilename[261]; /* offset 0 */
82; char achArg[1536-261]; /* offset 261 */
83; };
84;
85mytkExecPgm PROC FAR
86pBuffer = dword ptr -04h
87;SegBuffer = word ptr (dword ptr -08h)
88SegBuffer = -08h
89;OffBuffer = word ptr (dword ptr -0Ch)
90OffBuffer = -0Ch
91cchFilename = dword ptr -10h
92cchArgs = dword ptr -14h
93 ASSUME CS:CODE32, DS:NOTHING, SS:NOTHING
94 push ebp
95 mov ebp, esp
96 lea esp, [ebp + cchArgs]
97
98 push eax
99 push ecx
100 push ds
101 push es
102 push edi
103
104 ; parameter validations
105 mov ax, ds ; pointer to filename
106 cmp ax, 4
107 jb mytkExecPgm_CalltkExecPgm_X1
108
109 ;
110 ; filename length
111 ;
112 mov ax, ds
113 mov es, ax
114 pushad
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 popad
122 jc mytkExecPgm_CalltkExecPgm_X1; If the FuStrLen call failed we bail out!
123
124 ;
125 ; if filename length is more that CCHMAXPATH then we don't do anything!.
126 ;
127 mov ecx, [ebp+cchFilename]
128 cmp ecx, 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 mov bx, di ;
143 mov di, si ; bx:di -> arguments
144 push cs ; Problem calling far into the calltab segement.
145 call near ptr FLAT:f_FuStrLenZ
146 movzx ecx, cx
147 mov [ebp+cchArgs], ecx
148 popad
149 jc mytkExecPgm_CalltkExecPgm_X1
150
151mytkExecPgm_CalltkExecPgm_1:
152 mov ecx, [ebp+cchArgs]
153 add ecx, [ebp+cchFilename] ; filename
154 add ecx, 3 + 260 ; 260 = new argument from a scrip file or something.
155 ; 3 = two '\0's and a space after added argument.
156 cmp ecx, 1536 ; 1536 = Buffersize. FIXME! Define this!!!
157 jae mytkExecPgm_CalltkExecPgm_X1; jmp if argument + file + new file > buffer size
158
159 ;
160 ; Aquire a buffer
161 ;
162 call AcquireBuffer
163 or eax, eax
164 jz mytkExecPgm_CalltkExecPgm_X1; Failed to get buffer.
165 mov [ebp+pBuffer], eax
166
167 ;
168 ; Get Segment and offset for the buffer
169 ;
170 call QueryBufferSegmentOffset
171 mov cx, es
172 mov [ebp+OffBuffer], ax
173 mov [ebp+SegBuffer], es
174 test eax, 000570000h
175 jnz mytkExecPgm_CalltkExecPgm_X2
176
177 ;
178 ; Copy filename to pBuffer.
179 ;
180 pushad
181 mov di, ax ; es:di pBuffer
182 mov si, dx
183 mov bx, ds ; bx:si Filename pointer (input ds:dx)
184 mov ecx, [ebp+cchFilename]
185 push cs ; Problem calling far into the calltab segement.
186 call near ptr FLAT:f_FuBuff
187 popad
188 jc mytkExecPgm_CalltkExecPgm_X2
189
190 ;
191 ; Copy Args to pBuffer + 261
192 ;
193 ; stack: edi, es, ds, ecx, eax
194 pop edi
195 push edi
196 add eax, 261 ; we'll use eax in the branch
197 cmp di, 4
198 jb mytkExecPgm_CalltkExecPgm_2
199 pushad
200 mov ecx, [ebp+cchArgs]
201 mov bx,[ebp+SegBuffer]
202 mov ex, bx
203 mov bx, di ; ds:si -> arguments
204 push cs ; Problem calling far into the calltab segement.
205 call near ptr FLAT:f_FuBuff
206 popad
207 jc mytkExecPgm_CalltkExecPgm_X2
208 jmp mytkExecPgm_CalltkExecPgm_3
209
210mytkExecPgm_CalltkExecPgm_2:
211 mov word ptr es:[eax], 0 ; Terminate the empty string!
212
213 ;
214 ; Set Pointers, pszFilename and pszArguments
215 ;
216mytkExecPgm_CalltkExecPgm_3:
217 mov ax, seg FLAT:DATA32
218 mov ds, ax
219 ASSUME ds:FLAT
220 mov eax, ss:[ebp+pBuffer]
221 mov pszFilename, eax
222 add eax, 261
223 mov pszArguments, eax
224
225 ;
226 ; Restore variables pushed on the stack
227 ;
228 ; stack: edi, es, ds, ecx, eax
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 call far ptr FLAT:g_tkExecPgmStub
295 leave
296 retf
297mytkExecPgm ENDP
298
299
300;;
301; Stub which jumps to g_tkExecPgmStub.
302; (This way I will hopefully get the right selector.)
303g_tkExecPgmStub PROC FAR
304 jmp near ptr FLAT:g_tkExecPgm
305g_tkExecPgmStub ENDP
306
307
308CODE32 ENDS
309END
310
Note: See TracBrowser for help on using the repository browser.