Rev 907 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
498 | giacomo | 1 | #include <FTrace_types.h> |
2 | #include <FTrace_OSD.h> |
||
1027 | tullio | 3 | #include <FTrace.h> |
498 | giacomo | 4 | |
501 | giacomo | 5 | #include <ll/i386/hw-instr.h> |
6 | |||
498 | giacomo | 7 | /* OSD_pointers |
8 | |||
532 | giacomo | 9 | 00 - Actual Chunk Position |
10 | 04 - Actual Chunk Start |
||
11 | 08 - Actual Chunk Size |
||
12 | 12 - Actual Chunk Emergency Size |
||
13 | 16 - Actual Chunk Flags |
||
501 | giacomo | 14 | |
532 | giacomo | 15 | 20 - Next OSD pointer |
498 | giacomo | 16 | |
17 | */ |
||
18 | |||
1027 | tullio | 19 | extern WORD FTrace_filter_mask; |
20 | |||
21 | /** |
||
22 | * This is the function that actually store the event into the selected chunk. |
||
23 | */ |
||
501 | giacomo | 24 | void FTrace_safe_ipoint(WORD type, WORD par1, DWORD par2) |
498 | giacomo | 25 | { |
26 | |||
532 | giacomo | 27 | extern void *OSD_current_pointer; |
562 | giacomo | 28 | extern int FTraceEnable; |
498 | giacomo | 29 | |
501 | giacomo | 30 | DWORD tsclow, tschigh; |
503 | giacomo | 31 | DWORD current; |
32 | DWORD start; |
||
33 | DWORD size; |
||
34 | DWORD flags; |
||
501 | giacomo | 35 | |
36 | SYS_FLAGS f; |
||
498 | giacomo | 37 | |
503 | giacomo | 38 | f = ll_fsave(); |
39 | |||
562 | giacomo | 40 | if (FTraceEnable) { |
1027 | tullio | 41 | |
42 | /** Tool: do not filter the "filter" event family. */ |
||
43 | if ((type & 0xF0) != 0xF0) |
||
44 | if (FTrace_filter_mask & (0x01 << (type & FTrace_family_mask))) |
||
45 | return; |
||
46 | |||
532 | giacomo | 47 | current = *(DWORD *)(OSD_current_pointer); |
48 | start = *(DWORD *)(OSD_current_pointer + 4); |
||
49 | size = *(DWORD *)(OSD_current_pointer + 8); |
||
50 | flags = *(DWORD *)(OSD_current_pointer + 16); |
||
501 | giacomo | 51 | |
503 | giacomo | 52 | if (current == NULL) { |
53 | ll_frestore(f); |
||
54 | return; |
||
55 | } |
||
56 | |||
501 | giacomo | 57 | if (type != FTrace_EVT_next_chunk) { |
58 | |||
59 | if ((flags & FTRACE_CHUNK_FLAG_FULL) == FTRACE_CHUNK_FLAG_FULL) { |
||
60 | ll_frestore(f); |
||
61 | return; |
||
62 | } |
||
907 | mauro | 63 | |
1027 | tullio | 64 | /** Cyclical Buffer */ |
501 | giacomo | 65 | if (current + 16 >= (start + size)) { |
66 | if ((flags & 0x0C) == FTRACE_CHUNK_FLAG_CYC) { |
||
67 | current = start; |
||
68 | } else { |
||
532 | giacomo | 69 | *(DWORD *)(OSD_current_pointer + 16) |= FTRACE_CHUNK_FLAG_FULL; |
501 | giacomo | 70 | if ((flags & 0x0C) == FTRACE_CHUNK_FLAG_JTN) { |
532 | giacomo | 71 | OSD_current_pointer = (void *)(*(DWORD *)(OSD_current_pointer + 20)); |
72 | ll_frestore(f); |
||
73 | return; |
||
501 | giacomo | 74 | } |
75 | } |
||
76 | } |
||
77 | |||
78 | __asm__("cpuid\n\t" |
||
79 | "rdtsc\n\t" |
||
503 | giacomo | 80 | : "=a" (tsclow), "=d" (tschigh) : : "ecx","ebx"); |
501 | giacomo | 81 | |
593 | giacomo | 82 | *(DWORD *)current = (DWORD)((DWORD)(par1) << 16 | (DWORD)(type)); |
501 | giacomo | 83 | *(DWORD *)(current + 4) = tschigh; |
84 | *(DWORD *)(current + 8) = tsclow; |
||
534 | giacomo | 85 | *(DWORD *)(current + 12) = par2; |
501 | giacomo | 86 | |
532 | giacomo | 87 | *(DWORD *)(OSD_current_pointer) = current + 16; |
501 | giacomo | 88 | |
89 | } else { |
||
90 | |||
532 | giacomo | 91 | *(WORD *)(OSD_current_pointer + 16) |= FTRACE_CHUNK_FLAG_FULL; |
92 | OSD_current_pointer = (void *)(*(DWORD *)(OSD_current_pointer + 20)); |
||
93 | ll_frestore(f); |
||
94 | return; |
||
501 | giacomo | 95 | |
96 | } |
||
97 | |||
98 | } |
||
99 | |||
503 | giacomo | 100 | ll_frestore(f); |
101 | |||
498 | giacomo | 102 | } |
103 | |||
501 | giacomo | 104 | void FTrace_unsafe_ipoint(WORD type, WORD par1) |
498 | giacomo | 105 | { |
106 | |||
533 | giacomo | 107 | extern void *OSD_current_pointer; |
498 | giacomo | 108 | |
109 | __asm__("pushfl\n\t" /* Critical Section */ |
||
110 | "cli\n\t" |
||
111 | "cpuid\n\t" |
||
112 | "rdtsc\n\t" |
||
501 | giacomo | 113 | "movl (%%edi),%%ebx\n\t" |
503 | giacomo | 114 | "movl %%esi,(%%ebx)\n\t" /* Save TYPE + WORD par1 */ |
115 | "movl %%edx,4(%%ebx)\n\t" /* Save TSC HIGH */ |
||
116 | "movl %%eax,8(%%ebx)\n\t" /* Save TSC LOW */ |
||
117 | "addl $16,(%%edi)\n\t" /* Inc Position */ |
||
498 | giacomo | 118 | "popfl\n\t" |
533 | giacomo | 119 | :: "D" ((DWORD *)(OSD_current_pointer)), "S" (par1 << 16 | (type | 0x8000))); |
498 | giacomo | 120 | |
121 | } |
||
122 |