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

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

Nearly there!

File size: 7.7 KB
Line 
1; $Id: mytkExecPgm.asm,v 1.5 2000-02-21 09:24:01 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, di ; ds:si -> arguments
202 push cs ; Problem calling far into the calltab segement.
203 call near ptr FLAT:f_FuBuff
204 popad
205 jc mytkExecPgm_CalltkExecPgm_X2
206 jmp mytkExecPgm_CalltkExecPgm_3
207
208mytkExecPgm_CalltkExecPgm_2:
209 mov word ptr es:[eax], 0 ; Terminate the empty string!
210
211 ;
212 ; Set Pointers, pszFilename and pszArguments
213 ;
214mytkExecPgm_CalltkExecPgm_3:
215 mov ax, seg FLAT:DATA32
216 mov ds, ax
217 ASSUME ds:FLAT
218 mov eax, ss:[ebp+pBuffer]
219 mov pszFilename, eax
220 add eax, 261
221 mov pszArguments, eax
222
223 ;
224 ; Restore variables pushed on the stack
225 ;
226 ; stack: edi, es, ds, ecx, eax
227 pop edi
228 pop es
229 pop ds
230 pop ecx
231 pop eax
232
233 ;
234 ; Set new input parameters (call g_tkExecPgm)
235 ;
236 ; ds:dx is to become SegBuffer:OffBuffer
237 ; di:si is to become SegBuffer:OffBuffer+261
238 ;
239 ; The some of the old values are stored on the stack (for the time being)
240 push ds
241 push edi
242 push esi
243
244 mov di, [ebp+SegBuffer]
245 mov ds, di
246 mov si, [ebp+OffBuffer]
247 mov dx, si ; ds:dx SegBuffer:OffBuffer
248 add si, 261 ; di:si SegBuffer:OffBuffer+261
249
250 ;
251 ; Call g_tkExecPgm
252 ;
253 push cs ; Problem calling far into the calltab segement.
254 call near ptr FLAT:g_tkExecPgm
255 pushfd
256
257 ;
258 ; Release buffer
259 ;
260 push eax
261 mov eax, [ebp + pBuffer]
262 call ReleaseBuffer
263 mov [ebp + pBuffer], 0
264 pop eax
265
266 ;
267 ; Return
268 ;
269 popfd
270 pop esi
271 pop edi
272 pop ds
273 leave
274 retf
275
276mytkExecPgm_CalltkExecPgm_X2:
277 ;
278 ; Release buffer
279 ;
280 mov eax, [ebp + pBuffer]
281 call ReleaseBuffer
282 mov [ebp + pBuffer], 0
283
284mytkExecPgm_CalltkExecPgm_X1:
285 pop edi
286 pop es
287 pop ds
288 pop ecx
289 pop eax
290
291mytkExecPgm_CalltkExecPgm:
292 call far ptr FLAT:g_tkExecPgmStub
293 leave
294 retf
295mytkExecPgm ENDP
296
297
298;;
299; Stub which jumps to g_tkExecPgmStub.
300; (This way I will hopefully get the right selector.)
301g_tkExecPgmStub PROC FAR
302 jmp near ptr FLAT:g_tkExecPgm
303g_tkExecPgmStub ENDP
304
305
306CODE32 ENDS
307END
308
Note: See TracBrowser for help on using the repository browser.