Rev 533 |
Rev 563 |
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 - Actual Chunk Position
04 - Actual Chunk Start
08 - Actual Chunk Size
12 - Actual Chunk Emergency Size
16 - Actual Chunk Flags
20 - Next OSD pointer
*/
void FTrace_safe_ipoint(WORD type, WORD par1, DWORD par2)
{
extern void *OSD_current_pointer;
extern BYTE FTrace_enable;
DWORD tsclow, tschigh;
DWORD current;
DWORD start;
DWORD size;
DWORD flags;
SYS_FLAGS f;
f = ll_fsave();
if (FTrace_enable) {
current = *(DWORD *)(OSD_current_pointer);
start = *(DWORD *)(OSD_current_pointer + 4);
size = *(DWORD *)(OSD_current_pointer + 8);
flags = *(DWORD *)(OSD_current_pointer + 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 {
*(DWORD *)(OSD_current_pointer + 16) |= FTRACE_CHUNK_FLAG_FULL;
if ((flags & 0x0C) == FTRACE_CHUNK_FLAG_JTN) {
OSD_current_pointer = (void *)(*(DWORD *)(OSD_current_pointer + 20));
ll_frestore(f);
return;
}
}
}
__asm__("cpuid\n\t"
"rdtsc\n\t"
: "=a" (tsclow), "=d" (tschigh) : : "ecx","ebx");
*(DWORD *)current = (DWORD)(par1 << 16 | type);
*(DWORD *)(current + 4) = tschigh;
*(DWORD *)(current + 8) = tsclow;
*(DWORD *)(current + 12) = par2;
*(DWORD *)(OSD_current_pointer) = current + 16;
} else {
*(WORD *)(OSD_current_pointer + 16) |= FTRACE_CHUNK_FLAG_FULL;
OSD_current_pointer = (void *)(*(DWORD *)(OSD_current_pointer + 20));
ll_frestore(f);
return;
}
}
ll_frestore(f);
}
void FTrace_unsafe_ipoint(WORD type, WORD par1)
{
extern void *OSD_current_pointer;
__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 */
"addl $16,(%%edi)\n\t" /* Inc Position */
"popfl\n\t"
:: "D" ((DWORD *)(OSD_current_pointer)), "S" (par1 << 16 | (type | 0x8000)));
}
void FTrace_dump_ipoints(void *OSD_current)
{
DWORD p = *(DWORD *)(OSD_current+4);
DWORD end = *(DWORD *)(OSD_current+4) + *(DWORD *)(OSD_current+8) + *(DWORD *)(OSD_current+16);
while (p <= end) {
if (*(WORD *)(p) != 0x0000) {
FTrace_printf("Event %4x TSC %8x:%8xd PAR1 %8d PAR2 %8d\n",
*(WORD *)(p),*(DWORD *)(p+4),*(DWORD *)(p+8),*(WORD *)(p+2),*(DWORD *)(p+12));
}
p += 16;
}
}