Subversion Repositories shark

Rev

Rev 1365 | Rev 1568 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1296 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *    Giacomo Guidi      <giacomo@gandalf.sssup.it>
10
 *
11
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
12
 *
13
 * http://www.sssup.it
14
 * http://retis.sssup.it
15
 * http://shark.sssup.it
16
 */
17
 
18
#include <stdio.h>
19
#include <unistd.h>
20
#include <stdlib.h>
21
#include <string.h>
22
 
23
#define READ_BUFFER 2000
24
#define DELTA_BUFFER 100
25
 
26
int main(int argc, char *argv[])
27
{
28
 
29
  char buffer[READ_BUFFER+DELTA_BUFFER];
30
  void *p, *last;
1365 giacomo 31
  int n,delta,size;
1296 giacomo 32
 
1297 giacomo 33
  unsigned long long ev = 0;
34
 
1296 giacomo 35
  FILE *input_file;
36
 
37
  if (argc < 2) {
38
    printf("%s: Enter the input file name [%s filename]\n",argv[0],argv[0]);
39
    exit(1);
40
  }
41
 
42
  input_file = fopen(argv[1],"rb");
43
 
44
  last = buffer + READ_BUFFER;
45
 
46
  while(!feof(input_file)) {
47
 
48
    //move remaining byte
49
    delta = (unsigned int)(buffer) + READ_BUFFER - (unsigned int)(last);
50
    if (delta > 0) memcpy(buffer,last,delta);    
51
 
1301 giacomo 52
    n = fread(buffer+delta,1,READ_BUFFER+10,input_file);
53
    fseek(input_file,-(delta+10),SEEK_CUR);
1296 giacomo 54
 
55
    p = buffer;
56
 
1365 giacomo 57
    while ((unsigned int)(p) + 16 <= (unsigned int)(buffer + READ_BUFFER) &&
58
           (unsigned int)(p) + 16 <= (unsigned int)(buffer + n + delta)) {
1296 giacomo 59
 
1365 giacomo 60
      printf("%08d Type = %02x ",(unsigned int)ev,*(unsigned short int *)(p));
1296 giacomo 61
 
1412 giacomo 62
      printf("TSC = %08x:%08x",*(unsigned int *)(p+4),*(unsigned int *)(p+8));
1296 giacomo 63
 
1365 giacomo 64
      size = 16;
1296 giacomo 65
 
1365 giacomo 66
      printf(" Par1 = %d",*(unsigned short int *)(p+2));
67
      printf(" Par2 = %d\n",*(unsigned int *)(p+12));
1301 giacomo 68
 
1297 giacomo 69
      ev++;
70
 
1365 giacomo 71
      p += 16;
1301 giacomo 72
 
73
      if ((unsigned int)(p) + 10 > (unsigned int)(buffer + n + delta)) break;
74
 
1296 giacomo 75
      last = p;
1297 giacomo 76
 
1296 giacomo 77
    }
1301 giacomo 78
 
79
    if ((unsigned int)(p) + 10 > (unsigned int)(buffer + n + delta)) break;
1296 giacomo 80
 
81
  }
82
 
83
  fclose(input_file);
84
 
85
  return 0;
86
 
87
}
88