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

Subversion Repositories or2k

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

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
int main(int argc, char *argv[])
40
{
41
  FILE *fp;
42
 
43
  char insn_buff[INSN_SIZE_BYTES]; // Buffer for instruction data
44
 
45
  int insns_seen_total = 0; // Keep track of total number of instructions read
46
 
47
  // Try to open the file passed as first parameter
48
  if((fp = fopen(argv[ 1 ], "rb"))==NULL) {
49
    printf("Cannot open file.\n");
50
    exit(1);
51
  }
52
 
53
  instruction * insn = (instruction *)insn_buff;
54
 
55
  instruction_properties insn_props;
56
 
57
  // Do initial analysis - frequency of each instruction
58
 
59
  insn_lists_init();
60
 
61
  while(!feof(fp)) {
62
 
63
    if (fread(insn_buff, INSN_SIZE_BYTES, 1, fp) != 1)
64
      break;
65
 
66
    // Endianness is little when read in from binary file created with 
67
    // or32-elf-objcopy, so swap;
68
    *insn = htonl(*insn);
69
 
70
    reset_instruction_properties(&insn_props);
71
 
72
    analyse_insn(*insn, &insn_props);
73
 
74
    print_insn(&insn_props);
75
    printf("\n");
76
 
77
    insns_seen_total++;
78
 
79
    collect_stats(*insn, &insn_props);
80
 
81
  }
82
 
83
  insn_lists_free();
84
 
85
  fclose(fp);
86
 
87
  printf("Saw %d instructions\n", insns_seen_total);
88
 
89
  return 0;
90
 
91
}

powered by: WebSVN 2.1.0

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