497bc5034406194a037e977dc0696266b698de1d
[reactos.git] / reactos / apps / utils / pice / module / trace.c
1 /*++
2
3 Copyright (c) 1998-2001 Klaus P. Gerlicher
4
5 Module Name:
6
7 trace.c
8
9 Abstract:
10
11 Environment:
12
13 Kernel mode only
14
15 Author:
16
17 Klaus P. Gerlicher
18
19 Revision History:
20
21 19-Aug-1998: created
22
23 Copyright notice:
24
25 This file may be distributed under the terms of the GNU Public License.
26
27 --*/
28
29 ////////////////////////////////////////////////////
30 // INCLUDES
31 ////
32 #include "remods.h"
33
34 #include "precomp.h"
35
36 extern void NewInt31Handler(void);
37
38 void DeInstallTraceHook(void);
39
40 volatile ULONG OldInt1Handler=0;
41
42 __asm__("
43 NewInt1Handler:
44 pushl %eax
45 movl %dr6,%eax
46 testl $(1<<14),%eax
47 jz exceptionnotsinglestep
48
49 popl %eax
50 pushl $" STR(REASON_SINGLESTEP) "
51 jmp NewInt31Handler
52
53 exceptionnotsinglestep:
54 popl %eax
55 pushl $" STR(REASON_HARDWARE_BP) "
56 jmp NewInt31Handler
57 ");
58
59 BOOLEAN InstallTraceHook(void)
60 {
61 ULONG LocalInt1Handler;
62
63 DPRINT((0,"InstallTraceHook(OldInt1Handler=%0.8x)...\n",OldInt1Handler));
64
65 MaskIrqs();
66 if(!OldInt1Handler)
67 {
68 __asm__("mov $NewInt1Handler,%0"
69 :"=r" (LocalInt1Handler)
70 :
71 :"eax");
72 OldInt1Handler=SetGlobalInt(0x01,(ULONG)LocalInt1Handler);
73 }
74 UnmaskIrqs();
75 return TRUE;
76 }
77
78 void DeInstallTraceHook(void)
79 {
80 DPRINT((0,"DeInstallTraceHook(OldInt1Handler=%0.8x)...\n",OldInt1Handler));
81
82 MaskIrqs();
83 if(OldInt1Handler)
84 {
85 SetGlobalInt(0x01,(ULONG)OldInt1Handler);
86 OldInt1Handler = 0;
87 }
88 UnmaskIrqs();
89 }