source: trunk/src/win32k/test/fakea.asm@ 4037

Last change on this file since 4037 was 3829, checked in by bird, 25 years ago

Early development.

File size: 10.8 KB
Line 
1; $Id: fakea.asm,v 1.1 2000-07-16 22:18:15 bird Exp $
2;
3; Fake assembly imports.
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
10 .386
11
12;
13; Defined Constants And Macros
14;
15 INCL_BASE EQU 1
16
17;
18; Include files
19;
20 include devsegdf.inc
21 include devhlp.inc
22 include os2.inc
23
24
25;
26; Exported symbols
27;
28 public fakepTCBCur
29 public fakepPTDACur
30 public fakeptda_start
31 public fakeptda_environ
32 public fakef_FuStrLenZ
33 public fakef_FuStrLen
34 public fakef_FuBuff
35 public fakeg_tkExecPgm
36 public CalltkExecPgm
37
38
39;
40; Imported Functions
41;
42 extrn tkExecPgmWorker:PROC ; fake.c
43
44
45DATA16 SEGMENT
46; Fake data in 16-bit segment.
47fakepTCBCur dd offset FLAT:fakeTCB
48fakepPTDACur dd offset FLAT:fakeptda_start
49
50; PTDA - Only use environ and ExecChild.
51fakeptda_start LABEL DWORD
52fakeptda_pPTDAParent dd 0
53fakeptda_pPTDASelf dd offset FLAT:fakeptda_start
54fakeptda_pPTDAFirstChild dd 0
55fakeptda_pPTDAExecChild dd offset FLAT:fakeptda_start
56fakeptda_dummy db 123 dup (0)
57fakeptda_environ dw 1 ; 1 is the hardcoded HOB of the win32ktst.exe's environment.
58
59
60; TCB - just needs some dummy data for reading and writing to the TCBFailErr.
61fakeTCB db 220h dup (0CCh)
62
63DATA16 ENDS
64
65
66CODE16 SEGMENT
67
68
69; Scans strings until empy-string is reached.
70; input: bx:di
71; uses: nearly all (save bp)
72; return: cx size - CF clear
73; ax error- CF set
74fakef_FuStrLenZ PROC FAR
75 push 2 ; required by all 16-bit far procedures.
76 push 2 ; dummy code.
77 push 2 ; dummy code.
78 push 2 ; dummy code.
79 push es
80
81 mov dx, di ; save di pointer.
82 cmp bx, 7 ; check if NULL ptr.
83 jle ffslz_badselector
84
85 mov es, bx ; es:di -> string
86 mov cx, di
87 not cx ; maximum length is to segment end.
88 xor ax, ax ; test against zero (scasb uses al to cmp with).
89
90ffslz_loop:
91 repnz scasb
92 jnz ffslz_no_term ; jump if cx = 0
93 dec cx ; check if next is NULL too
94 scasb
95 jnz ffslz_loop
96
97ffslz_retok:
98 mov cx, di
99 sub cx, dx ; cx <- size (end ptr - start ptr)
100 pop es
101 add sp, 8
102 clc
103 db 66h
104 retf
105
106ffslz_badselector:
107 mov ax, ERROR_INVALID_SELECTOR
108 jmp ffslz_reterr
109
110;ffslz_invalidptr:
111; mov ax, ERROR_INVALID_ACCESS
112; jmp ffslz_reterr
113
114ffslz_no_term:
115 mov ax, ERROR_TERMINATOR_NOT_FOUND
116ffslz_reterr:
117 pop es
118 add sp, 8
119 stc
120 db 66h
121 retf
122fakef_FuStrLenZ ENDP
123
124
125;
126; Stringlength - Fake
127; input: bx:di
128; uses: nearly all (save bp)
129; return: cx size - CF clear
130; ax error- CF set
131fakef_FuStrLen PROC FAR
132 push 2 ; required by all 16-bit far procedures.
133 push 2 ; dummy code.
134 push 2 ; dummy code.
135 push 2 ; dummy code.
136 push es
137
138 mov dx, di ; save di pointer.
139 cmp bx, 7 ; check if NULL ptr.
140 jle ffslz_badselector
141
142 mov es, bx ; es:di -> string
143 mov cx, di
144 not cx ; maximum length is to segment end.
145 xor ax, ax ; test against zero (scasb uses al to cmp with).
146
147 repnz scasb
148 jnz ffslz_no_term ; jump if cx = 0
149
150ffslz_retok:
151 mov cx, di
152 sub cx, dx ; cx <- size (end ptr - start ptr)
153 pop es
154 add sp, 8
155 clc
156 db 66h
157 retf
158
159ffslz_badselector:
160 mov ax, ERROR_INVALID_SELECTOR
161 jmp ffslz_reterr
162
163;ffslz_invalidptr:
164; mov ax, ERROR_INVALID_ACCESS
165; jmp ffslz_reterr
166
167ffslz_no_term:
168 mov ax, ERROR_TERMINATOR_NOT_FOUND
169ffslz_reterr:
170 pop es
171 add sp, 8
172 stc
173 db 66h
174 retf
175fakef_FuStrLen ENDP
176
177
178;memcpy
179;input: bx:si pointer to source
180; es:di pointer to target
181; cx count of bytes to copy
182;uses: nearly all (save bp), es, ds
183;return: success CF clear
184; failure CF set
185fakef_FuBuff PROC FAR
186 push 2 ; required by all 16-bit far procedures.
187 push 2 ; dummy code.
188 push 2 ; dummy code.
189 push 2 ; dummy code.
190 push es
191
192 cmp bx, 7 ; check if NULL ptr.
193 jle ffslz_badselector
194 mov ax, es
195 cmp bx, 7 ; check if NULL ptr.
196 jle ffslz_badselector
197
198 mov ds, bx ; ds:si -> string
199 mov ax, di
200 not ax
201 cmp ax, cx ; crosses segment boundrary...
202 jb ffslz_invalidptr
203 mov ax, si
204 not ax
205 cmp ax, cx ; crosses segment boundrary...
206 jb ffslz_invalidptr
207
208; movzx esi, si
209; movzx edi, di
210; movzx ecx, cx
211; db 66h ; force it use extended registers.
212 rep movsb
213
214ffslz_retok:
215 xor ax, ax
216 mov cx, di
217 sub cx, dx ; cx <- size (end ptr - start ptr)
218 pop es
219 add sp, 8
220 clc
221 db 66h
222 retf
223
224ffslz_badselector:
225 mov ax, ERROR_INVALID_SELECTOR
226 jmp ffslz_reterr
227
228ffslz_invalidptr:
229 int 3
230 mov ax, ERROR_INVALID_ACCESS
231 jmp ffslz_reterr
232
233ffslz_no_term:
234 mov ax, ERROR_TERMINATOR_NOT_FOUND
235ffslz_reterr:
236 pop es
237 add sp, 8
238 stc
239 db 66h
240 retf
241fakef_FuBuff ENDP
242
243
244
245
246CODE16 ENDS
247
248
249
250CODE32 SEGMENT
251;;
252; Fake g_tkExecPgm implementation.
253; @proto none. (void _Optlink fakeg_tkExecPgm(void);)
254; @returns same as tkExecPgm: eax, edx and carry flag
255; @param ax Exec flag
256; ds:dx Filename address. (String)
257; es:bx Environment address. (String)
258; di:si Argument address. (String)
259; @uses all - bp
260; @sketch Copy the filename and arguments into a buffer we
261; may modify later if this is a UNIX shellscript or
262; a PE-file started by pe.exe.
263; @status completely implemented.
264; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
265;
266;
267fakeg_tkExecPgm PROC NEAR
268 push ebp
269 mov ebp, esp
270
271 ;
272 ; We just have to make some common code...
273 ;
274 sub esp, 10h
275 movzx eax, ax
276 mov [esp + 00h], eax ; ExecFlag DWORD
277
278 mov ax, es
279 SelToFlat
280 mov [esp + 08h], eax ; Environment ptr.
281 mov ecx, eax
282
283 mov ax, ds
284 mov bx, dx
285 SelToFlat
286 mov [esp + 0ch], eax ; Filename ptr
287
288 mov ax, di
289 mov bx, si
290 SelToFlat
291 mov [esp + 04h], eax ; Argument ptr
292 mov edx, eax
293
294 mov eax, [esp + 00h] ; ExecFlag DWORD in eax
295
296 mov bx, seg FLAT:DATA32
297 mov ds, bx ; Make ds flat
298 mov es, bx ; Make es flat
299
300 call tkExecPgmWorker ;(ULONG flags, arg, env, prog)
301 add esp, 10 ; eax, edx, ecx,
302 ; ebp+8, ebp+c, ebp+10, ebp+14
303 ; esp+0, esp+4, esp+08, esp+0c
304
305 leave
306 ret
307fakeg_tkExecPgm ENDP
308
309
310;;
311; Calls the fakeg_tkExecPgm procedure.
312; @cproto ULONG _Optlink CalltkExecPgm(
313; ULONG execFlags,
314; PCSZ pArg,
315; PCSZ pEnv,
316; PCSZ pExecName);
317; @returns
318; @param eax (ebp +08h) execFlags
319; @param edx (ebp +0ch) pArg
320; @param ecx (ebp +10h) pEnv
321; @param ebp + 14h pExecName
322; @uses eax, ecx, edx
323; @status completely implemented.
324; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
325; @remark
326CalltkExecPgm PROC NEAR
327 push ebp
328 mov ebp, esp
329 push ebx
330 push edi
331 push esi
332 push es
333 push ds
334
335 ; Save parameters
336 mov [ebp+08h], eax
337
338 ;
339 ; create input for fakeg_tkExecPgm
340 ;
341 mov eax, edx
342 xor edi, edi
343 xor esi, esi
344 or eax, eax
345 jz ctkep1
346 FlatToSel
347 mov di, ax
348 mov esi, ebx ; di:si -> arguments
349ctkep1:
350
351 mov eax, [ebp + 14h]
352 xor edx, edx
353 mov ds, dx
354 or eax, eax
355 jz ctkep2
356 FlatToSel
357 mov ds, ax
358 mov edx, ebx ; ds:dx -> executable filename
359ctkep2:
360
361 mov eax, ecx
362 xor ebx, ebx
363 mov es, bx
364 or eax, eax
365 jz ctkep3
366 FlatToSel
367 mov es, ax
368 mov eax, ebx ; es:bx -> environment.
369ctkep3:
370
371 mov eax, [ebp+08h] ; ax = exec flags.
372
373 call far ptr FLAT:fakeg_tkExecPgm
374
375 ;
376 ; Restore and return.
377 ;
378 pop ds
379 pop es
380 pop esi
381 pop edi
382 pop ebx
383 leave
384 ret
385CalltkExecPgm ENDP
386
387
388;;
389; Gets the selector for the CODE16 segment.
390; @cproto USHORT _Optlink GetSelectorCODE16(void)
391; @returns Selector for the CODE16 segment.
392; @uses eax
393; @status completely implemented.
394; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
395GetSelectorCODE16 PROC NEAR
396 xor eax, eax
397 mov ax, seg CODE16
398 ret
399GetSelectorCODE16 ENDP
400
401
402;;
403; Gets the selector for the DATA16 segment.
404; @cproto USHORT _Optlink GetSelectorDATA16(void)
405; @returns Selector for the DATA16 segment.
406; @uses eax
407; @status completely implemented.
408; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
409GetSelectorDATA16 PROC NEAR
410 xor eax, eax
411 mov ax, seg DATA16
412 ret
413GetSelectorDATA16 ENDP
414
415
416;;
417; Gets the selector for the CODE32 segment.
418; @cproto USHORT _Optlink GetSelectorCODE32(void)
419; @returns Selector for the CODE32 segment.
420; @uses eax
421; @status completely implemented.
422; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
423GetSelectorCODE32 PROC NEAR
424 xor eax, eax
425 mov ax, seg FLAT:CODE32
426 ret
427GetSelectorCODE32 ENDP
428
429;;
430; Gets the selector for the DATA32 segment.
431; @cproto USHORT _Optlink GetSelectorDATA32(void)
432; @returns Selector for the DATA32 segment.
433; @uses eax
434; @status completely implemented.
435; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
436GetSelectorDATA32 PROC NEAR
437 xor eax, eax
438 mov ax, seg FLAT:DATA32
439 ret
440GetSelectorDATA32 ENDP
441
442
443
444CODE32 ENDS
445
446END
Note: See TracBrowser for help on using the repository browser.