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

Last change on this file since 5655 was 5247, checked in by bird, 25 years ago

Calltable fixes. Handle event. New 14062e kernels.

File size: 15.1 KB
Line 
1; $Id: fakea.asm,v 1.5 2001-02-23 02:57:55 bird Exp $
2;
3; Fake assembly imports.
4;
5; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.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 include options.inc
24
25
26;
27; Exported symbols
28;
29 public fakepTCBCur
30 public fakepPTDACur
31 public fakeptda_start
32 public fakeptda_environ
33 public fakeptda_handle
34 public fakeptda_module
35 public fakeptda_ptdasem
36 public fakeptda_pBeginLIBPATH
37 public fakef_FuStrLenZ
38 public fakef_FuStrLen
39 public fakef_FuBuff
40 public fakeg_tkExecPgm
41 public faketkStartProcess
42 public CalltkExecPgm
43 public _fakeldrOpenPath@20
44 public fakeKMEnterKmodeSEF
45 public fakeKMExitKmodeSEF8
46 public fakeRASRST
47 public fakedh_SendEvent
48
49
50;
51; Imported Functions and Variables.
52;
53 extrn tkExecPgmWorker:PROC ; fake.c
54 extrn _fakeLDRClearSem@0:PROC ; fake.c
55 extrn _fakeKSEMRequestMutex@8:PROC ; fake.c
56 extrn _fakeldrOpenPath_old@16:PROC ; fake.c
57 extrn _fakeldrOpenPath_new@20:PROC ; fake.c
58 extrn _options:options ; d16globl.c
59
60
61DATA16 SEGMENT
62; Fake data in 16-bit segment.
63fakepTCBCur dd offset FLAT:fakeTCB
64fakepPTDACur dd offset FLAT:fakeptda_start
65
66; PTDA - Only use environ and ExecChild.
67fakeptda_start LABEL DWORD
68fakeptda_pPTDAParent dd 0
69fakeptda_pPTDASelf dd offset FLAT:fakeptda_start
70fakeptda_pPTDAFirstChild dd 0
71fakeptda_pPTDAExecChild dd offset FLAT:fakeptda_start
72fakeptda_dummy db 123 dup (0)
73fakeptda_environ dw 1 ; 1 is the hardcoded HOB of the win32ktst.exe's environment.
74fakeptda_ptdasem db 20 dup (0) ; PTDA semaphore - Intra-Process serialisation mutex KSEM (sg244640).
75fakeptda_handle dw 2 ; 2 is the hardcoded HPTDA of the current process.
76fakeptda_module dw 1 ; 1 is the hardcoded HMTE of the current executable module.
77fakeptda_pBeginLIBPATH dd 0 ; BEGINLIBPATH not implemented.
78 dd 0 ; ENDLIBPATH not implemented.
79
80
81; TCB - just needs some dummy data for reading and writing to the TCBFailErr.
82fakeTCB db 220h dup (0CCh)
83
84DATA16 ENDS
85
86
87CODE16 SEGMENT
88
89
90; Scans strings until empy-string is reached.
91; input: bx:di
92; uses: nearly all (save bp)
93; return: cx size - CF clear
94; ax error- CF set
95fakef_FuStrLenZ PROC FAR
96 push 2 ; required by all 16-bit far procedures.
97 push 2 ; dummy code.
98 push 2 ; dummy code.
99 push 2 ; dummy code.
100 push es
101
102 mov dx, di ; save di pointer.
103 cmp bx, 7 ; check if NULL ptr.
104 jle ffslz_badselector
105
106 mov es, bx ; es:di -> string
107 mov cx, di
108 not cx ; maximum length is to segment end.
109 xor ax, ax ; test against zero (scasb uses al to cmp with).
110
111ffslz_loop:
112 repnz scasb
113 jnz ffslz_no_term ; jump if cx = 0
114 dec cx ; check if next is NULL too
115 scasb
116 jnz ffslz_loop
117
118ffslz_retok:
119 mov cx, di
120 sub cx, dx ; cx <- size (end ptr - start ptr)
121 pop es
122 add sp, 8
123 clc
124 db 66h
125 retf
126
127ffslz_badselector:
128 mov ax, ERROR_INVALID_SELECTOR
129 jmp ffslz_reterr
130
131;ffslz_invalidptr:
132; mov ax, ERROR_INVALID_ACCESS
133; jmp ffslz_reterr
134
135ffslz_no_term:
136 mov ax, ERROR_TERMINATOR_NOT_FOUND
137ffslz_reterr:
138 pop es
139 add sp, 8
140 stc
141 db 66h
142 retf
143fakef_FuStrLenZ ENDP
144
145
146;
147; Stringlength - Fake
148; input: bx:di
149; uses: nearly all (save bp)
150; return: cx size - CF clear
151; ax error- CF set
152fakef_FuStrLen PROC FAR
153 push 2 ; required by all 16-bit far procedures.
154 push 2 ; dummy code.
155 push 2 ; dummy code.
156 push 2 ; dummy code.
157 push es
158
159 mov dx, di ; save di pointer.
160 cmp bx, 7 ; check if NULL ptr.
161 jle ffslz_badselector
162
163 mov es, bx ; es:di -> string
164 mov cx, di
165 not cx ; maximum length is to segment end.
166 xor ax, ax ; test against zero (scasb uses al to cmp with).
167
168 repnz scasb
169 jnz ffslz_no_term ; jump if cx = 0
170
171ffslz_retok:
172 mov cx, di
173 sub cx, dx ; cx <- size (end ptr - start ptr)
174 pop es
175 add sp, 8
176 clc
177 db 66h
178 retf
179
180ffslz_badselector:
181 mov ax, ERROR_INVALID_SELECTOR
182 jmp ffslz_reterr
183
184;ffslz_invalidptr:
185; mov ax, ERROR_INVALID_ACCESS
186; jmp ffslz_reterr
187
188ffslz_no_term:
189 mov ax, ERROR_TERMINATOR_NOT_FOUND
190ffslz_reterr:
191 pop es
192 add sp, 8
193 stc
194 db 66h
195 retf
196fakef_FuStrLen ENDP
197
198
199;memcpy
200;input: bx:si pointer to source
201; es:di pointer to target
202; cx count of bytes to copy
203;uses: nearly all (save bp), es, ds
204;return: success CF clear
205; failure CF set
206fakef_FuBuff PROC FAR
207 push 2 ; required by all 16-bit far procedures.
208 push 2 ; dummy code.
209 push 2 ; dummy code.
210 push 2 ; dummy code.
211 push es
212
213 cmp bx, 7 ; check if NULL ptr.
214 jle ffslz_badselector
215 mov ax, es
216 cmp bx, 7 ; check if NULL ptr.
217 jle ffslz_badselector
218
219 mov ds, bx ; ds:si -> string
220 mov ax, di
221 not ax
222 cmp ax, cx ; crosses segment boundrary...
223 jb ffslz_invalidptr
224 mov ax, si
225 not ax
226 cmp ax, cx ; crosses segment boundrary...
227 jb ffslz_invalidptr
228
229; movzx esi, si
230; movzx edi, di
231; movzx ecx, cx
232; db 66h ; force it use extended registers.
233 rep movsb
234
235ffslz_retok:
236 xor ax, ax
237 mov cx, di
238 sub cx, dx ; cx <- size (end ptr - start ptr)
239 pop es
240 add sp, 8
241 clc
242 db 66h
243 retf
244
245ffslz_badselector:
246 mov ax, ERROR_INVALID_SELECTOR
247 jmp ffslz_reterr
248
249ffslz_invalidptr:
250 int 3
251 mov ax, ERROR_INVALID_ACCESS
252 jmp ffslz_reterr
253
254ffslz_no_term:
255 mov ax, ERROR_TERMINATOR_NOT_FOUND
256ffslz_reterr:
257 pop es
258 add sp, 8
259 stc
260 db 66h
261 retf
262fakef_FuBuff ENDP
263
264
265;;
266; RASRST faker.
267; @status stupid stub.
268fakeRASRST proc near
269 mov ax, ds
270 mov ax, ds
271 mov ax, ds
272 mov ax, ds
273 int 3
274fakeRASRST endp
275
276
277;;
278; dh_SendEvent faker.
279; @status stupid stub.
280fakedh_SendEvent proc near
281 mov ax, ds
282 mov ax, ds
283 mov ax, ds
284 mov ax, ds
285 int 3
286fakedh_SendEvent endp
287
288
289CODE16 ENDS
290
291
292
293CODE32 SEGMENT
294;;
295; Faker of which simply clears the loader semaphore.
296; @cproto none! (void _Optlink faketkStartProcess(void))
297; @returns
298; @param
299; @uses
300; @equiv
301; @time
302; @sketch
303; @status
304; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
305; @remark
306faketkStartProcess PROC NEAR
307 push ebp
308 mov ebp, esp
309
310 push ebx
311 push ecx
312
313 call _fakeLDRClearSem@0
314
315 pop ecx
316 pop ebx
317
318 xor eax, eax
319 leave
320 ret
321faketkStartProcess ENDP
322
323
324;;
325; Fake g_tkExecPgm implementation.
326; @proto none. (void _Optlink fakeg_tkExecPgm(void);)
327; @returns same as tkExecPgm: eax, edx and carry flag
328; @param ax Exec flag
329; ds:dx Filename address. (String)
330; es:bx Environment address. (String)
331; di:si Argument address. (String)
332; @uses all - bp
333; @sketch Copy the filename and arguments into a buffer we
334; may modify later if this is a UNIX shellscript or
335; a PE-file started by pe.exe.
336; @status completely implemented.
337; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
338;
339;
340fakeg_tkExecPgm PROC NEAR
341 push ebp
342 mov ebp, esp
343
344 ;
345 ; Call C worker
346 ;
347 sub esp, 10h
348 movzx eax, ax
349 mov [esp + 00h], eax ; ExecFlag DWORD
350
351 mov ax, es
352 SelToFlat
353 mov [esp + 08h], eax ; Environment ptr.
354 mov ecx, eax
355
356 mov ax, ds
357 mov bx, dx
358 SelToFlat
359 mov [esp + 0ch], eax ; Filename ptr
360
361 mov ax, di
362 mov bx, si
363 SelToFlat
364 mov [esp + 04h], eax ; Argument ptr
365 mov edx, eax
366
367 mov eax, [esp + 00h] ; ExecFlag DWORD in eax
368
369 mov bx, seg FLAT:DATA32
370 mov ds, bx ; Make ds flat
371 mov es, bx ; Make es flat
372
373 call tkExecPgmWorker ;(ULONG flags, arg, env, prog)
374 add esp, 10 ; eax, edx, ecx,
375 ; ebp+8, ebp+c, ebp+10, ebp+14
376 ; esp+0, esp+4, esp+08, esp+0c
377 or eax, eax
378 jnz ftkep_ret
379 call faketkStartProcess ; If succesfully so far. call start process.
380 jmp ftkep_ret2 ; <Currently no parameters are implemented.>
381
382ftkep_ret:
383 push eax
384 call _fakeLDRClearSem@0 ; clear the semaphore.
385 pop eax
386
387ftkep_ret2:
388 leave
389 ret
390fakeg_tkExecPgm ENDP
391
392
393;;
394; Calls the fakeg_tkExecPgm procedure.
395; @cproto ULONG _Optlink CalltkExecPgm(
396; ULONG execFlags,
397; PCSZ pArg,
398; PCSZ pEnv,
399; PCSZ pExecName);
400; @returns
401; @param eax (ebp +08h) execFlags
402; @param edx (ebp +0ch) pArg
403; @param ecx (ebp +10h) pEnv
404; @param ebp + 14h pExecName
405; @uses eax, ecx, edx
406; @status completely implemented.
407; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
408; @remark
409CalltkExecPgm PROC NEAR
410 push ebp
411 mov ebp, esp
412 push ebx
413 push edi
414 push esi
415 push es
416 push ds
417
418 ; Save parameters
419 mov [ebp+08h], eax
420
421 ;
422 ; create input for fakeg_tkExecPgm
423 ;
424 mov eax, edx
425 xor edi, edi
426 xor esi, esi
427 or eax, eax
428 jz ctkep1
429 FlatToSel
430 mov di, ax
431 mov esi, ebx ; di:si -> arguments
432ctkep1:
433
434 mov eax, [ebp + 14h]
435 xor edx, edx
436 mov ds, dx
437 or eax, eax
438 jz ctkep2
439 FlatToSel
440 mov ds, ax
441 mov edx, ebx ; ds:dx -> executable filename
442ctkep2:
443
444 mov eax, ecx
445 xor ebx, ebx
446 mov es, bx
447 or eax, eax
448 jz ctkep3
449 FlatToSel
450 mov es, ax
451 mov eax, ebx ; es:bx -> environment.
452ctkep3:
453
454 mov eax, [ebp+08h] ; ax = exec flags.
455
456 call far ptr FLAT:fakeg_tkExecPgm
457
458 ;
459 ; Restore and return.
460 ;
461 pop ds
462 pop es
463 pop esi
464 pop edi
465 pop ebx
466 leave
467 ret
468CalltkExecPgm ENDP
469
470
471;;
472; Gets the selector for the CODE16 segment.
473; @cproto USHORT _Optlink GetSelectorCODE16(void)
474; @returns Selector for the CODE16 segment.
475; @uses eax
476; @status completely implemented.
477; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
478GetSelectorCODE16 PROC NEAR
479 xor eax, eax
480 mov ax, seg CODE16
481 ret
482GetSelectorCODE16 ENDP
483
484
485;;
486; Gets the selector for the DATA16 segment.
487; @cproto USHORT _Optlink GetSelectorDATA16(void)
488; @returns Selector for the DATA16 segment.
489; @uses eax
490; @status completely implemented.
491; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
492GetSelectorDATA16 PROC NEAR
493 xor eax, eax
494 mov ax, seg DATA16
495 ret
496GetSelectorDATA16 ENDP
497
498
499;;
500; Gets the selector for the CODE32 segment.
501; @cproto USHORT _Optlink GetSelectorCODE32(void)
502; @returns Selector for the CODE32 segment.
503; @uses eax
504; @status completely implemented.
505; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
506GetSelectorCODE32 PROC NEAR
507 xor eax, eax
508 mov ax, seg FLAT:CODE32
509 ret
510GetSelectorCODE32 ENDP
511
512;;
513; Gets the selector for the DATA32 segment.
514; @cproto USHORT _Optlink GetSelectorDATA32(void)
515; @returns Selector for the DATA32 segment.
516; @uses eax
517; @status completely implemented.
518; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
519GetSelectorDATA32 PROC NEAR
520 xor eax, eax
521 mov ax, seg FLAT:DATA32
522 ret
523GetSelectorDATA32 ENDP
524
525
526;;
527; Wrapper for fakeldrOpenPath.
528; @cproto ULONG LDRCALL fakeldrOpenPath(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful, ULONG lLibPath);
529; @returns Return of the current fakeldrOpenPath
530; @param pachFilename Pointer to modulename. Not zero terminated!
531; @param cchFilename Modulename length.
532; @param plv Loader local variables? (Struct from KERNEL.SDF)
533; @param pful Pointer to flags which are passed on to ldrOpen.
534; @param lLibPath New parameter in build 14053.
535; ldrGetMte calls with 1
536; ldrOpenNewExe calls with 3
537; This is compared to the initial libpath index.
538; The libpath index is:
539; BEGINLIBPATH 1
540; LIBPATH 2
541; ENDLIBPATH 3
542; The initial libpath index is either 1 or 2.
543; - ignored -
544; @uses ecx, eax, edx
545; @sketch
546; @status
547; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
548; @remark
549_fakeldrOpenPath@20 PROC NEAR
550 ASSUME ds:FLAT
551 ; dummy prolog.
552 push ebp
553 mov ebp, esp
554 sub esp, 10h
555 add esp, 10h
556 pop ebp
557 ; real code
558 cmp FLAT:DATA16:_options.ulBuild, 14053
559 jge new
560 jmp near ptr FLAT:CODE32:_fakeldrOpenPath_old@16
561new:
562 jmp near ptr FLAT:CODE32:_fakeldrOpenPath_new@20
563_fakeldrOpenPath@20 ENDP
564
565
566
567;;
568; This is called at kernel entry.
569; @cproto none
570; @returns nothing
571; @param none
572; @uses nothing
573; @status stub.
574; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
575fakeKMEnterKmodeSEF proc near
576 ; dummy prolog.
577 push ebp
578 mov ebp, esp
579 sub esp, 10h
580 leave
581 ret
582fakeKMEnterKmodeSEF endp
583
584
585;;
586; This is called at kernel exit.
587; @cproto none
588; @returns nothing
589; @param none
590; @uses nothing
591; @status stub.
592; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
593fakeKMExitKmodeSEF8 proc near
594 ; dummy prolog.
595 push ebp
596 mov ebp, esp
597 sub esp, 10h
598 leave
599 ret
600fakeKMExitKmodeSEF8 endp
601
602CODE32 ENDS
603
604END
Note: See TracBrowser for help on using the repository browser.