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

Last change on this file since 4178 was 4164, checked in by bird, 25 years ago

Merged in the Grace branch. New Win32k!

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