Subversion Repositories shark

Rev

Rev 534 | Rev 563 | 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>
3
 
501 giacomo 4
#include <ll/i386/hw-instr.h>
5
 
498 giacomo 6
/* OSD_pointers
7
 
532 giacomo 8
   00 - Actual Chunk Position
9
   04 - Actual Chunk Start
10
   08 - Actual Chunk Size
11
   12 - Actual Chunk Emergency Size
12
   16 - Actual Chunk Flags
501 giacomo 13
 
532 giacomo 14
   20 - Next OSD pointer
498 giacomo 15
 
16
*/
17
 
501 giacomo 18
void FTrace_safe_ipoint(WORD type, WORD par1, DWORD par2)
498 giacomo 19
{
20
 
532 giacomo 21
  extern void *OSD_current_pointer;
562 giacomo 22
  extern int FTraceEnable;
498 giacomo 23
 
501 giacomo 24
  DWORD tsclow, tschigh;
503 giacomo 25
  DWORD current;
26
  DWORD start;
27
  DWORD size;
28
  DWORD flags;
501 giacomo 29
 
30
  SYS_FLAGS f;
498 giacomo 31
 
503 giacomo 32
  f = ll_fsave();
33
 
562 giacomo 34
  if (FTraceEnable) {
501 giacomo 35
 
532 giacomo 36
    current = *(DWORD *)(OSD_current_pointer);
37
    start   = *(DWORD *)(OSD_current_pointer + 4);
38
    size    = *(DWORD *)(OSD_current_pointer + 8);
39
    flags   = *(DWORD *)(OSD_current_pointer + 16);
501 giacomo 40
 
503 giacomo 41
    if (current == NULL) {
42
      ll_frestore(f);
43
      return;
44
    }
45
 
501 giacomo 46
    if (type != FTrace_EVT_next_chunk) {
47
 
48
      if ((flags & FTRACE_CHUNK_FLAG_FULL) == FTRACE_CHUNK_FLAG_FULL) {
49
        ll_frestore(f);
50
        return;
51
      }
52
 
53
      /* Cyclical Buffer */
54
      if (current + 16 >= (start + size)) {
55
        if ((flags & 0x0C) == FTRACE_CHUNK_FLAG_CYC) {
56
          current = start;
57
        } else {
532 giacomo 58
          *(DWORD *)(OSD_current_pointer + 16) |= FTRACE_CHUNK_FLAG_FULL;
501 giacomo 59
          if ((flags & 0x0C) ==  FTRACE_CHUNK_FLAG_JTN) {
532 giacomo 60
                OSD_current_pointer = (void *)(*(DWORD *)(OSD_current_pointer + 20));
61
                ll_frestore(f);
62
                return;
501 giacomo 63
          }
64
        }
65
      }
66
 
67
      __asm__("cpuid\n\t"
68
              "rdtsc\n\t"
503 giacomo 69
              : "=a" (tsclow), "=d" (tschigh) : : "ecx","ebx");
501 giacomo 70
 
532 giacomo 71
      *(DWORD *)current = (DWORD)(par1 << 16 | type);
501 giacomo 72
      *(DWORD *)(current + 4) = tschigh;
73
      *(DWORD *)(current + 8) = tsclow;
534 giacomo 74
      *(DWORD *)(current + 12) = par2;
501 giacomo 75
 
532 giacomo 76
      *(DWORD *)(OSD_current_pointer) = current + 16;
501 giacomo 77
 
78
    } else {
79
 
532 giacomo 80
      *(WORD *)(OSD_current_pointer + 16) |= FTRACE_CHUNK_FLAG_FULL;
81
      OSD_current_pointer = (void *)(*(DWORD *)(OSD_current_pointer + 20));
82
      ll_frestore(f);
83
      return;  
501 giacomo 84
 
85
    }
86
 
87
  }
88
 
503 giacomo 89
  ll_frestore(f);
90
 
498 giacomo 91
}
92
 
501 giacomo 93
void FTrace_unsafe_ipoint(WORD type, WORD par1)
498 giacomo 94
{
95
 
533 giacomo 96
  extern void *OSD_current_pointer;
498 giacomo 97
 
98
  __asm__("pushfl\n\t" /* Critical Section */
99
          "cli\n\t"
100
          "cpuid\n\t"
101
          "rdtsc\n\t"
501 giacomo 102
          "movl (%%edi),%%ebx\n\t"
503 giacomo 103
          "movl %%esi,(%%ebx)\n\t"   /* Save TYPE + WORD par1 */
104
          "movl %%edx,4(%%ebx)\n\t"  /* Save TSC HIGH */
105
          "movl %%eax,8(%%ebx)\n\t"  /* Save TSC LOW */
106
          "addl $16,(%%edi)\n\t"     /* Inc Position */
498 giacomo 107
          "popfl\n\t"
533 giacomo 108
          :: "D" ((DWORD *)(OSD_current_pointer)), "S" (par1 << 16 | (type | 0x8000)));
498 giacomo 109
 
110
}
111
 
534 giacomo 112
void FTrace_dump_ipoints(void *OSD_current)
113
{
114
 
115
  DWORD p = *(DWORD *)(OSD_current+4);
116
  DWORD end = *(DWORD *)(OSD_current+4) + *(DWORD *)(OSD_current+8) + *(DWORD *)(OSD_current+16);
117
 
118
  while (p <= end) {
119
 
120
        if (*(WORD *)(p) != 0x0000) {
121
                FTrace_printf("Event %4x TSC %8x:%8xd PAR1 %8d PAR2 %8d\n",
122
                *(WORD *)(p),*(DWORD *)(p+4),*(DWORD *)(p+8),*(WORD *)(p+2),*(DWORD *)(p+12));
123
        }
124
 
125
        p += 16;
126
 
127
  }
128
 
129
}
130