Subversion Repositories shark

Rev

Rev 506 | Rev 533 | 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;
498 giacomo 22
  extern BYTE FTrace_enable;
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
 
501 giacomo 34
  if (FTrace_enable) {
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;
74
      *(DWORD *)(current + 16) = par2;
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
 
96
  extern BYTE OSD_pointers[FTRACE_OSD_CHUNK_HEAD];
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
	  "movl %%eax,12(%%ebx)\n\t" /* DWORD par2 */
107
	  "addl $16,(%%edi)\n\t"     /* Inc Position */
498 giacomo 108
	  "popfl\n\t"
532 giacomo 109
          :: "D" ((DWORD *)(OSD_pointers)), "S" (par1 << 16 | (type | 0x8000)));
498 giacomo 110
 
111
}
112