OpenCores
URL https://opencores.org/ocsvn/or2k/or2k/trunk

Subversion Repositories or2k

[/] [or2k/] [trunk/] [analysis-bin/] [insnanalysis/] [insnanalysis.c] - Blame information for rev 17

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 julius
/*
2
  File for analysis of an architecture's instructions in binary format
3
 
4
  Julius Baxter, julius.baxter@orsoc.se
5
 
6
*/
7
 
8
#include<stdio.h>
9
#include <stdlib.h>
10
#include <string.h>
11
#include <stdint.h>
12
#include <arpa/inet.h> // for htonl()
13
 
14
#include "insnanalysis.h"
15
 
16
// Access to list management functions
17
#include "insn-lists.h"
18
 
19
int analyse_insn(instruction insn,
20
                 instruction_properties *insn_props)
21
{
22
  // For now no other instruction sets supported
23
  return or1k_32_analyse_insn(insn, insn_props);
24
}
25
 
26
 
27
void print_insn(instruction_properties *insn_props)
28
{
29
  if (insn_props->insn_string != NULL)
30
    printf("%s", insn_props->insn_string);
31
}
32
 
33
void collect_stats(instruction insn,
34
                 instruction_properties *insn_props)
35
{
36
  or1k_32_collect_stats(insn, insn_props);
37
}
38
 
39 17 julius
 
40
void generate_stats(FILE * stream)
41
{
42
  or1k_32_generate_stats(stream);
43
}
44
 
45 16 julius
int main(int argc, char *argv[])
46
{
47
  FILE *fp;
48
 
49
  char insn_buff[INSN_SIZE_BYTES]; // Buffer for instruction data
50
 
51
  int insns_seen_total = 0; // Keep track of total number of instructions read
52
 
53
  // Try to open the file passed as first parameter
54
  if((fp = fopen(argv[ 1 ], "rb"))==NULL) {
55
    printf("Cannot open file.\n");
56
    exit(1);
57
  }
58
 
59
  instruction * insn = (instruction *)insn_buff;
60
 
61
  instruction_properties insn_props;
62
 
63
  // Do initial analysis - frequency of each instruction
64
 
65
  insn_lists_init();
66
 
67
  while(!feof(fp)) {
68
 
69
    if (fread(insn_buff, INSN_SIZE_BYTES, 1, fp) != 1)
70
      break;
71
 
72
    // Endianness is little when read in from binary file created with 
73
    // or32-elf-objcopy, so swap;
74
    *insn = htonl(*insn);
75
 
76 17 julius
    if (*insn == 0) // most probably dead space in binary, skip
77
      continue;
78
 
79 16 julius
    reset_instruction_properties(&insn_props);
80
 
81 17 julius
    if (analyse_insn(*insn, &insn_props) == 0)
82
      {
83
        /*
84
        print_insn(&insn_props);
85
        printf("\n");
86
        */
87
        insns_seen_total++;
88
 
89
        collect_stats(*insn, &insn_props);
90
      }
91
    else
92
      {
93
        printf("\n");
94
      }
95 16 julius
 
96
  }
97
 
98
  fclose(fp);
99 17 julius
 
100
  printf("Saw %d instructions\n", insns_seen_total);
101 16 julius
 
102 17 julius
  generate_stats(stdout);
103 16 julius
 
104 17 julius
  insn_lists_free();
105
 
106 16 julius
  return 0;
107
 
108
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.