Subversion Repositories shark

Rev

Rev 503 | Rev 533 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include <FTrace_types.h>
#include <FTrace_OSD.h>

#include <ll/i386/hw-instr.h>

/* OSD_pointers

   00 - Next pointer

   04 - Actual Chunk Position
   08 - Actual Chunk Start
   12 - Actual Chunk Size
   16 - Actual Chunk Emergency Size
   20 - Actual Chunk Flags

   24 - Next1 Chunk Position
   28 - Next1 Chunk Start
   32 - Next1 Chunk Size
   36 - Next1 Chunk Emergency Size
   40 - Next1 Chunk Flags

   44 - Next1 Chunk Position
   48 - Next1 Chunk Start
   52 - Next1 Chunk Size
   56 - Next1 Chunk Emergency Size
   60 - Next1 Chunk Flags

   64 - Fast_Access

*/


void FTrace_safe_ipoint(WORD type, WORD par1, DWORD par2)
{

  extern BYTE OSD_pointers[FTRACE_OSD_CHUNK_HEAD];
  extern BYTE FTrace_enable;

  DWORD tsclow, tschigh;
  DWORD next;
  DWORD current;
  DWORD start;
  DWORD size;
  DWORD flags;
 
  SYS_FLAGS f;

  f = ll_fsave();

  if (FTrace_enable) {

    next = *(DWORD *)(OSD_pointers);
    current = *(DWORD *)(OSD_pointers + next);
    start   = *(DWORD *)(OSD_pointers + next + 4);
    size    = *(DWORD *)(OSD_pointers + next + 8);
    flags   = *(DWORD *)(OSD_pointers + next + 16);

    if (current == NULL) {
      ll_frestore(f);
      return;
    }

    if (type != FTrace_EVT_next_chunk) {

      if ((flags & FTRACE_CHUNK_FLAG_FULL) == FTRACE_CHUNK_FLAG_FULL) {
        ll_frestore(f);
        return;
      }

      /* Cyclical Buffer */
      if (current + 16 >= (start + size)) {
        if ((flags & 0x0C) == FTRACE_CHUNK_FLAG_CYC) {
          current = start;
        } else {
          *(WORD *)(OSD_pointers + next + 16) |= FTRACE_CHUNK_FLAG_FULL;
          if ((flags & 0x0C) ==  FTRACE_CHUNK_FLAG_JTN) {
                *(DWORD *)(OSD_pointers) += 20;
                next = *(DWORD *)(OSD_pointers);
          }
        }
      }

      __asm__("cpuid\n\t"
              "rdtsc\n\t"
              : "=a" (tsclow), "=d" (tschigh) : : "ecx","ebx");
     
      *(DWORD *)current = (DWORD)(type << 16 | par1);
      *(DWORD *)(current + 4) = tschigh;
      *(DWORD *)(current + 8) = tsclow;
      *(DWORD *)(current + 16) = par2;

      *(DWORD *)(OSD_pointers + 64) = *(DWORD *)(OSD_pointers + next) = current + 16;

    } else {

      *(WORD *)(OSD_pointers + next + 16) |= FTRACE_CHUNK_FLAG_FULL;
      *(DWORD *)(OSD_pointers) += 20;
      *(DWORD *)(OSD_pointers + 64) = *(DWORD *)(OSD_pointers + *(DWORD *)(OSD_pointers) + 4); //Fast Access

    }

  }

  ll_frestore(f);

}

void FTrace_unsafe_ipoint(WORD type, WORD par1)
{

  extern BYTE OSD_pointers[FTRACE_OSD_CHUNK_HEAD];

  __asm__("pushfl\n\t" /* Critical Section */
          "cli\n\t"
          "cpuid\n\t"
          "rdtsc\n\t"
          "movl (%%edi),%%ebx\n\t"
          "movl %%esi,(%%ebx)\n\t"   /* Save TYPE + WORD par1 */
          "movl %%edx,4(%%ebx)\n\t"  /* Save TSC HIGH */
          "movl %%eax,8(%%ebx)\n\t"  /* Save TSC LOW */
          "movl %%eax,12(%%ebx)\n\t" /* DWORD par2 */
          "addl $16,(%%edi)\n\t"     /* Inc Position */
          "popfl\n\t"
          :: "D" ((DWORD *)(OSD_pointers+64)), "S" ((type | 0x8000) << 16 | par1));

}