Porting pice. Workaround for a bug in gcc. Some other small stuff.
[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 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__("
64 NewInt1Handler:
65 pushl %eax
66 movl %dr6,%eax
67 testl $(1<<14),%eax
68 jz exceptionnotsinglestep
69
70 popl %eax
71 pushl $" STR(REASON_SINGLESTEP) "
72 //call _ping1
73 jmp NewInt31Handler
74
75 exceptionnotsinglestep:
76 popl %eax
77 pushl $" STR(REASON_HARDWARE_BP) "
78 jmp NewInt31Handler
79 ");
80
81 void DeInstallTraceHook(void)
82 {
83 DPRINT((0,"DeInstallTraceHook(OldInt1Handler=%0.8x)...\n",OldInt1Handler));
84
85 MaskIrqs();
86 if(OldInt1Handler)
87 {
88 SetGlobalInt(0x01,(ULONG)OldInt1Handler);
89 OldInt1Handler = 0;
90 }
91 UnmaskIrqs();
92 }