:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / 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 BOOLEAN InstallTraceHook(void)
43 {
44         ULONG LocalInt1Handler;
45
46     DPRINT((0,"InstallTraceHook(OldInt1Handler=%0.8x)...\n",OldInt1Handler));
47
48         MaskIrqs();
49         if(!OldInt1Handler)
50         {
51                 __asm__("mov $NewInt1Handler,%0"
52                         :"=r" (LocalInt1Handler)
53                         :
54                         :"eax");
55                 OldInt1Handler=SetGlobalInt(0x01,(ULONG)LocalInt1Handler);
56         }
57         UnmaskIrqs();
58         return TRUE;
59 }
60
61 //this asm function must be at least second in the file. otherwise gcc does not
62 //generate correct code.
63 __asm__("\n\t \
64 NewInt1Handler:\n\t \
65        pushl %eax\n\t \
66                 movl %dr6,%eax\n\t \
67                 testl $(1<<14),%eax\n\t \
68                 jz exceptionnotsinglestep\n\t \
69 \n\t \
70         popl %eax\n\t \
71         pushl $" STR(REASON_SINGLESTEP) "\n\t \
72         jmp NewInt31Handler\n\t \
73 \n\t \
74 exceptionnotsinglestep:\n\t \
75         popl %eax\n\t \
76         pushl $" STR(REASON_HARDWARE_BP) "\n\t \
77         jmp NewInt31Handler\n\t \
78 ");
79
80 void DeInstallTraceHook(void)
81 {
82         DPRINT((0,"DeInstallTraceHook(OldInt1Handler=%0.8x)...\n",OldInt1Handler));
83
84         MaskIrqs();
85         if(OldInt1Handler)
86         {
87                 SetGlobalInt(0x01,(ULONG)OldInt1Handler);
88         OldInt1Handler = 0;
89         }
90         UnmaskIrqs();
91 }