1 | ; $Id: profasm.asm,v 1.1 2001-11-22 10:43:59 phaller Exp $
|
---|
2 |
|
---|
3 | ;/*
|
---|
4 | ; * Project Odin Software License can be found in LICENSE.TXT
|
---|
5 | ; * Execution Trace Profiler
|
---|
6 | ; *
|
---|
7 | ; * Copyright 2001 Patrick Haller <patrick.haller@innotek.de>
|
---|
8 | ; *
|
---|
9 | ; */
|
---|
10 |
|
---|
11 | .586p
|
---|
12 | NAME profasm
|
---|
13 |
|
---|
14 | extrn C_ProfileHook32Enter: proc
|
---|
15 | extrn C_ProfileHook32Exit: proc
|
---|
16 |
|
---|
17 | CODE32 SEGMENT DWORD PUBLIC USE32 'CODE'
|
---|
18 | ASSUME DS:FLAT, SS:FLAT
|
---|
19 |
|
---|
20 | public odin_ProfileHook32
|
---|
21 | odin_ProfileHook32 proc near
|
---|
22 |
|
---|
23 | ; --------
|
---|
24 | ; top half
|
---|
25 | ; --------
|
---|
26 |
|
---|
27 | pushfd
|
---|
28 | push eax ; save altered registers
|
---|
29 | push edx
|
---|
30 | push ecx
|
---|
31 |
|
---|
32 | rdtsc ; push the machine timestamp
|
---|
33 | ; (assuming at least Pentium CPU is available)
|
---|
34 | push eax
|
---|
35 | push edx
|
---|
36 | mov edx, dword ptr [esp+1Ch]
|
---|
37 | push edx ; push return address for bottom half
|
---|
38 | mov edx, dword ptr [esp+1Ch]
|
---|
39 | push edx ; push entry address of caller function
|
---|
40 |
|
---|
41 | ; ret_addr _System C_ProfilerHook32Enter(ULONG eip_function, ULONG ret, ULONGLONG tsc)
|
---|
42 | call C_ProfileHook32Enter
|
---|
43 | add esp, 10h
|
---|
44 |
|
---|
45 | ; restore the stack as it was before
|
---|
46 | ; and replace the (saved) caller's address by the
|
---|
47 | ; hook's bottom half address
|
---|
48 | mov dword ptr [esp + 14h], eax
|
---|
49 |
|
---|
50 | pop ecx
|
---|
51 | pop edx
|
---|
52 | pop eax
|
---|
53 | popfd
|
---|
54 |
|
---|
55 | ret
|
---|
56 | odin_ProfileHook32 endp
|
---|
57 |
|
---|
58 |
|
---|
59 | public odin_ProfileHook32Bottom
|
---|
60 | odin_ProfileHook32Bottom proc near
|
---|
61 |
|
---|
62 | ; -----------
|
---|
63 | ; bottom half
|
---|
64 | ; -----------
|
---|
65 |
|
---|
66 | push 0 ; make room for virtual jump
|
---|
67 |
|
---|
68 | pushfd
|
---|
69 | push eax ; save altered registers
|
---|
70 | push edx
|
---|
71 | push ecx
|
---|
72 |
|
---|
73 | rdtsc ; push the machine timestamp
|
---|
74 | ; (assuming at least Pentium CPU is available)
|
---|
75 | push eax
|
---|
76 | push edx
|
---|
77 |
|
---|
78 | ; ret_addr _System C_ProfilerHook32Exit(ULONGLONG tsc)
|
---|
79 | call C_ProfileHook32Exit
|
---|
80 | add esp, 08h
|
---|
81 |
|
---|
82 | ; restore the stack as it was before
|
---|
83 | ; and virtually JUMP BACK to the caller's caller
|
---|
84 | ; eax now contains the return address
|
---|
85 | mov dword ptr [esp + 10h], eax
|
---|
86 |
|
---|
87 | pop ecx
|
---|
88 | pop edx ; restore altered registers
|
---|
89 | pop eax
|
---|
90 | popfd
|
---|
91 |
|
---|
92 | ; this is a virtual jump!
|
---|
93 | ret
|
---|
94 | odin_ProfileHook32Bottom endp
|
---|
95 |
|
---|
96 | public _ProfileGetTimestamp
|
---|
97 | _ProfileGetTimestamp proc near
|
---|
98 |
|
---|
99 | push eax ; save altered registers
|
---|
100 | push edx
|
---|
101 | push edi
|
---|
102 |
|
---|
103 | rdtsc ; push the machine timestamp
|
---|
104 | ; (assuming at least Pentium CPU is available)
|
---|
105 | mov edi, dword ptr [esp+14h]
|
---|
106 | mov dword ptr [edi], eax
|
---|
107 | mov edi, dword ptr [esp+10h]
|
---|
108 | mov dword ptr [edi], edx
|
---|
109 |
|
---|
110 | pop edi
|
---|
111 | pop edx
|
---|
112 | pop eax
|
---|
113 |
|
---|
114 | ret
|
---|
115 | _ProfileGetTimestamp endp
|
---|
116 |
|
---|
117 |
|
---|
118 | CODE32 ENDS
|
---|
119 | END
|
---|