Subversion Repositories shark

Rev

Rev 1027 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1063 tullio 1
 
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program; if not, write to the Free Software
15
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 *
17
 */
18
 
498 giacomo 19
#include <FTrace_types.h>
20
#include <FTrace_OSD.h>
1027 tullio 21
#include <FTrace.h>
498 giacomo 22
 
501 giacomo 23
#include <ll/i386/hw-instr.h>
24
 
498 giacomo 25
/* OSD_pointers
26
 
532 giacomo 27
   00 - Actual Chunk Position
28
   04 - Actual Chunk Start
29
   08 - Actual Chunk Size
30
   12 - Actual Chunk Emergency Size
31
   16 - Actual Chunk Flags
501 giacomo 32
 
532 giacomo 33
   20 - Next OSD pointer
498 giacomo 34
 
35
*/
36
 
1027 tullio 37
extern WORD FTrace_filter_mask;
38
 
39
/**
40
 * This is the function that actually store the event into the selected chunk.
41
 */
501 giacomo 42
void FTrace_safe_ipoint(WORD type, WORD par1, DWORD par2)
498 giacomo 43
{
44
 
532 giacomo 45
  extern void *OSD_current_pointer;
562 giacomo 46
  extern int FTraceEnable;
498 giacomo 47
 
501 giacomo 48
  DWORD tsclow, tschigh;
503 giacomo 49
  DWORD current;
50
  DWORD start;
51
  DWORD size;
52
  DWORD flags;
501 giacomo 53
 
54
  SYS_FLAGS f;
498 giacomo 55
 
503 giacomo 56
  f = ll_fsave();
57
 
562 giacomo 58
  if (FTraceEnable) {
1027 tullio 59
 
60
    /** Tool: do not filter the "filter" event family. */
61
    if ((type & 0xF0) != 0xF0)  
62
      if (FTrace_filter_mask & (0x01 << (type & FTrace_family_mask)))
63
        return;
64
 
532 giacomo 65
    current = *(DWORD *)(OSD_current_pointer);
66
    start   = *(DWORD *)(OSD_current_pointer + 4);
67
    size    = *(DWORD *)(OSD_current_pointer + 8);
68
    flags   = *(DWORD *)(OSD_current_pointer + 16);
501 giacomo 69
 
503 giacomo 70
    if (current == NULL) {
71
      ll_frestore(f);
72
      return;
73
    }
74
 
501 giacomo 75
    if (type != FTrace_EVT_next_chunk) {
76
 
77
      if ((flags & FTRACE_CHUNK_FLAG_FULL) == FTRACE_CHUNK_FLAG_FULL) {
78
        ll_frestore(f);
79
        return;
80
      }
907 mauro 81
 
1027 tullio 82
      /** Cyclical Buffer */
501 giacomo 83
      if (current + 16 >= (start + size)) {
84
        if ((flags & 0x0C) == FTRACE_CHUNK_FLAG_CYC) {
85
          current = start;
86
        } else {
532 giacomo 87
          *(DWORD *)(OSD_current_pointer + 16) |= FTRACE_CHUNK_FLAG_FULL;
501 giacomo 88
          if ((flags & 0x0C) ==  FTRACE_CHUNK_FLAG_JTN) {
532 giacomo 89
                OSD_current_pointer = (void *)(*(DWORD *)(OSD_current_pointer + 20));
90
                ll_frestore(f);
91
                return;
501 giacomo 92
          }
93
        }
94
      }
95
 
96
      __asm__("cpuid\n\t"
97
              "rdtsc\n\t"
503 giacomo 98
              : "=a" (tsclow), "=d" (tschigh) : : "ecx","ebx");
501 giacomo 99
 
593 giacomo 100
      *(DWORD *)current = (DWORD)((DWORD)(par1) << 16 | (DWORD)(type));
501 giacomo 101
      *(DWORD *)(current + 4) = tschigh;
102
      *(DWORD *)(current + 8) = tsclow;
534 giacomo 103
      *(DWORD *)(current + 12) = par2;
501 giacomo 104
 
532 giacomo 105
      *(DWORD *)(OSD_current_pointer) = current + 16;
501 giacomo 106
 
107
    } else {
108
 
532 giacomo 109
      *(WORD *)(OSD_current_pointer + 16) |= FTRACE_CHUNK_FLAG_FULL;
110
      OSD_current_pointer = (void *)(*(DWORD *)(OSD_current_pointer + 20));
111
      ll_frestore(f);
112
      return;  
501 giacomo 113
 
114
    }
115
 
116
  }
117
 
503 giacomo 118
  ll_frestore(f);
119
 
498 giacomo 120
}
121
 
501 giacomo 122
void FTrace_unsafe_ipoint(WORD type, WORD par1)
498 giacomo 123
{
124
 
533 giacomo 125
  extern void *OSD_current_pointer;
498 giacomo 126
 
127
  __asm__("pushfl\n\t" /* Critical Section */
128
          "cli\n\t"
129
          "cpuid\n\t"
130
          "rdtsc\n\t"
501 giacomo 131
          "movl (%%edi),%%ebx\n\t"
503 giacomo 132
          "movl %%esi,(%%ebx)\n\t"   /* Save TYPE + WORD par1 */
133
          "movl %%edx,4(%%ebx)\n\t"  /* Save TSC HIGH */
134
          "movl %%eax,8(%%ebx)\n\t"  /* Save TSC LOW */
135
          "addl $16,(%%edi)\n\t"     /* Inc Position */
498 giacomo 136
          "popfl\n\t"
533 giacomo 137
          :: "D" ((DWORD *)(OSD_current_pointer)), "S" (par1 << 16 | (type | 0x8000)));
498 giacomo 138
 
139
}
140