Subversion Repositories shark

Rev

Rev 1568 | 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>
1568 tullio 10
 *    Tullio Facchinetti <tullio.facchinetti@unipv.it>
1296 giacomo 11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
1568 tullio 17
 * http://robot.unipv.it
1296 giacomo 18
 */
19
 
1606 tullio 20
/*
21
 * This program is free software; you can redistribute it and/or modify
22
 * it under the terms of the GNU General Public License as published by
23
 * the Free Software Foundation; either version 2 of the License, or
24
 * (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34
 *
35
 */
36
 
1296 giacomo 37
#include <stdio.h>
38
#include <unistd.h>
39
#include <stdlib.h>
40
#include <string.h>
41
 
42
#define READ_BUFFER 2000
43
#define DELTA_BUFFER 100
44
 
45
int main(int argc, char *argv[])
46
{
47
 
48
  char buffer[READ_BUFFER+DELTA_BUFFER];
49
  void *p, *last;
1365 giacomo 50
  int n,delta,size;
1568 tullio 51
 
52
  unsigned long long tsc_value;
1296 giacomo 53
 
1297 giacomo 54
  unsigned long long ev = 0;
55
 
1296 giacomo 56
  FILE *input_file;
57
 
58
  if (argc < 2) {
59
    printf("%s: Enter the input file name [%s filename]\n",argv[0],argv[0]);
60
    exit(1);
61
  }
62
 
63
  input_file = fopen(argv[1],"rb");
64
 
65
  last = buffer + READ_BUFFER;
66
 
67
  while(!feof(input_file)) {
68
 
69
    //move remaining byte
70
    delta = (unsigned int)(buffer) + READ_BUFFER - (unsigned int)(last);
71
    if (delta > 0) memcpy(buffer,last,delta);    
72
 
1301 giacomo 73
    n = fread(buffer+delta,1,READ_BUFFER+10,input_file);
74
    fseek(input_file,-(delta+10),SEEK_CUR);
1296 giacomo 75
 
76
    p = buffer;
77
 
1365 giacomo 78
    while ((unsigned int)(p) + 16 <= (unsigned int)(buffer + READ_BUFFER) &&
79
           (unsigned int)(p) + 16 <= (unsigned int)(buffer + n + delta)) {
1296 giacomo 80
 
1365 giacomo 81
      printf("%08d Type = %02x ",(unsigned int)ev,*(unsigned short int *)(p));
1296 giacomo 82
 
1568 tullio 83
      tsc_value = (unsigned long long)(*(unsigned int *)(p+4)) << 32;
84
      tsc_value += (unsigned long long)(*(unsigned int *)(p+8));
85
 
86
      printf("TSC = %llu (%08x:%08x)",tsc_value, *(unsigned int *)(p+4),*(unsigned int *)(p+8));
1296 giacomo 87
 
1365 giacomo 88
      size = 16;
1296 giacomo 89
 
1568 tullio 90
      printf(" Par1 = %11d",*(unsigned short int *)(p+2));
91
      printf(" Par2 = %11d\n",*(unsigned int *)(p+12));
1301 giacomo 92
 
1297 giacomo 93
      ev++;
94
 
1365 giacomo 95
      p += 16;
1301 giacomo 96
 
97
      if ((unsigned int)(p) + 10 > (unsigned int)(buffer + n + delta)) break;
98
 
1296 giacomo 99
      last = p;
1297 giacomo 100
 
1296 giacomo 101
    }
1301 giacomo 102
 
103
    if ((unsigned int)(p) + 10 > (unsigned int)(buffer + n + delta)) break;
1296 giacomo 104
 
105
  }
106
 
107
  fclose(input_file);
108
 
109
  return 0;
110
 
111
}
112