Subversion Repositories shark

Rev

Rev 498 | Rev 503 | 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
 
501 giacomo 8
   00 - Next pointer
9
 
10
   04 - Actual Chunk Position
498 giacomo 11
   08 - Actual Chunk Start
501 giacomo 12
   12 - Actual Chunk Size
13
   16 - Actual Chunk Emergency Size
14
   20 - Actual Chunk Flags
498 giacomo 15
 
501 giacomo 16
   24 - Next1 Chunk Position
17
   28 - Next1 Chunk Start
18
   32 - Next1 Chunk Size
19
   36 - Next1 Chunk Emergency Size
20
   60 - Next1 Chunk Flags
498 giacomo 21
 
22
*/
23
 
501 giacomo 24
void FTrace_safe_ipoint(WORD type, WORD par1, DWORD par2)
498 giacomo 25
{
26
 
27
  extern BYTE OSD_pointers[FTRACE_OSD_CHUNK_HEAD];
28
  extern BYTE FTrace_enable;
29
 
501 giacomo 30
  DWORD tsclow, tschigh;
31
  DWORD next = *(DWORD *)(OSD_pointers);
32
  DWORD current = *(DWORD *)(OSD_pointers + next);
33
  DWORD start   = *(DWORD *)(OSD_pointers + next + 4);
34
  DWORD size    = *(DWORD *)(OSD_pointers + next + 8);
35
  DWORD flags   = *(DWORD *)(OSD_pointers + next + 16);
36
 
37
  SYS_FLAGS f;
498 giacomo 38
 
501 giacomo 39
  if (FTrace_enable) {
40
 
41
    f = ll_fsave();
42
 
43
    if (type != FTrace_EVT_next_chunk) {
44
 
45
      if ((flags & FTRACE_CHUNK_FLAG_FULL) == FTRACE_CHUNK_FLAG_FULL) {
46
	ll_frestore(f);
47
	return;
48
      }
49
 
50
      /* Cyclical Buffer */
51
      if (current + 16 >= (start + size)) {
52
	if ((flags & 0x0C) == FTRACE_CHUNK_FLAG_CYC) {
53
          current = start;
54
	} else {
55
	  *(WORD *)(OSD_pointers + next + 16) &= FTRACE_CHUNK_FLAG_FULL;
56
	  if ((flags & 0x0C) ==  FTRACE_CHUNK_FLAG_JTN) {
57
		*(DWORD *)(OSD_pointers) += 20;
58
		next = *(DWORD *)(OSD_pointers);
59
          }
60
	}
61
      }
62
 
63
      __asm__("cpuid\n\t"
64
              "rdtsc\n\t"
65
	      : "=a" (tsclow), "=b" (tschigh) : : "ecx","edx");
66
 
67
      *(DWORD *)current = (DWORD)(type << 16 | par1);
68
      *(DWORD *)(current + 4) = tschigh;
69
      *(DWORD *)(current + 8) = tsclow;
70
      *(DWORD *)(current + 16) = par2;
71
 
72
      *(DWORD *)(OSD_pointers + next) = current + 16;
73
 
74
    } else {
75
 
76
      *(WORD *)(OSD_pointers + next + 16) &= FTRACE_CHUNK_FLAG_FULL;
77
      if ((flags & 0x0C) ==  FTRACE_CHUNK_FLAG_JTN)
78
        *(DWORD *)(OSD_pointers) += 20;
79
 
80
    }
81
 
82
    ll_frestore(f);
83
 
84
  }
85
 
498 giacomo 86
}
87
 
501 giacomo 88
void FTrace_unsafe_ipoint(WORD type, WORD par1)
498 giacomo 89
{
90
 
91
  extern BYTE OSD_pointers[FTRACE_OSD_CHUNK_HEAD];
92
 
93
  __asm__("pushfl\n\t" /* Critical Section */
94
          "cli\n\t"
95
	  "cpuid\n\t"
96
	  "rdtsc\n\t"
501 giacomo 97
	  "movl (%%edi),%%ebx\n\t"
98
          "movl %%esi,(%%ebx)\n\t"  /* Save TYPE + WORD par1 */
99
          "movl %%edx,4(%%ebx)\n\t" /* Save TSC HIGH */
100
          "movl %%eax,8(%%ebx)\n\t" /* Save TSC LOW */
101
	  "addl $12,(%%edi)\n\t"    /* Inc Position */
498 giacomo 102
	  "popfl\n\t"
501 giacomo 103
          :: "D" ((DWORD *)(OSD_pointers)), "S" ((type | 0x8000) << 16 | par1));
498 giacomo 104
 
105
}
106