Subversion Repositories shark

Rev

Rev 563 | Rev 594 | 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
 
593 giacomo 67
      __asm__("":::"memory");
68
 
501 giacomo 69
      __asm__("cpuid\n\t"
70
              "rdtsc\n\t"
503 giacomo 71
	      : "=a" (tsclow), "=d" (tschigh) : : "ecx","ebx");
501 giacomo 72
 
593 giacomo 73
      __asm__("":::"memory");
74
 
75
      *(DWORD *)current = (DWORD)((DWORD)(par1) << 16 | (DWORD)(type));
501 giacomo 76
      *(DWORD *)(current + 4) = tschigh;
77
      *(DWORD *)(current + 8) = tsclow;
534 giacomo 78
      *(DWORD *)(current + 12) = par2;
501 giacomo 79
 
532 giacomo 80
      *(DWORD *)(OSD_current_pointer) = current + 16;
501 giacomo 81
 
82
    } else {
83
 
532 giacomo 84
      *(WORD *)(OSD_current_pointer + 16) |= FTRACE_CHUNK_FLAG_FULL;
85
      OSD_current_pointer = (void *)(*(DWORD *)(OSD_current_pointer + 20));
86
      ll_frestore(f);
87
      return;
501 giacomo 88
 
89
    }
90
 
91
  }
92
 
503 giacomo 93
  ll_frestore(f);
94
 
498 giacomo 95
}
96
 
501 giacomo 97
void FTrace_unsafe_ipoint(WORD type, WORD par1)
498 giacomo 98
{
99
 
533 giacomo 100
  extern void *OSD_current_pointer;
498 giacomo 101
 
102
  __asm__("pushfl\n\t" /* Critical Section */
103
          "cli\n\t"
104
	  "cpuid\n\t"
105
	  "rdtsc\n\t"
501 giacomo 106
	  "movl (%%edi),%%ebx\n\t"
503 giacomo 107
          "movl %%esi,(%%ebx)\n\t"   /* Save TYPE + WORD par1 */
108
          "movl %%edx,4(%%ebx)\n\t"  /* Save TSC HIGH */
109
          "movl %%eax,8(%%ebx)\n\t"  /* Save TSC LOW */
110
	  "addl $16,(%%edi)\n\t"     /* Inc Position */
498 giacomo 111
	  "popfl\n\t"
533 giacomo 112
          :: "D" ((DWORD *)(OSD_current_pointer)), "S" (par1 << 16 | (type | 0x8000)));
498 giacomo 113
 
114
}
115