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

Subversion Repositories xgate

[/] [xgate/] [trunk/] [sw/] [tools/] [misc/] [make_decode.pl] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 rehayes
#!/usr/bin/perl -w
2
 
3
sub month_to_number {
4
  if ($_[0] eq "0") {
5
      $_[0] = "0";
6
  } elsif ($_[0] eq "1") {
7
      $_[0] = "1";
8
  } elsif ($_[0] eq "IMM3") {
9
      $_[0] = "???";
10
  } elsif ($_[0] eq "RS") {
11
      $_[0] = "???";
12
  } elsif ($_[0] eq "RD") {
13
      $_[0] = "???";
14
  } elsif ($_[0] eq "IMM4") {
15
      $_[0] = "????";
16
  } elsif ($_[0] eq "RS1") {
17
      $_[0] = "???";
18
  } elsif ($_[0] eq "RS2") {
19
      $_[0] = "???";
20
  } elsif ($_[0] eq "REL9") {
21
      $_[0] = "?????????";
22
  } elsif ($_[0] eq "REL10") {
23
      $_[0] = "??????????";
24
  } elsif ($_[0] eq "RB") {
25
      $_[0] = "???";
26
  } elsif ($_[0] eq "OFFS5") {
27
      $_[0] = "?????";
28
  } elsif ($_[0] eq "RI") {
29
      $_[0] = "???";
30
  } elsif ($_[0] eq "IMM8") {
31
      $_[0] = "????????";
32
  } else {
33
      printf "Bad Instruction Parameter: %s\n", $_[0];
34
      $_[0] = "";
35
  }
36
}
37
 
38
sub set_default_values {
39
    print "  always \@*\n";
40
    print "    begin\n";
41
    print "      enable_rd = 0;\n";
42
    print "      enable_imm3 = 0;\n";
43
    print "      enable_rs = 0;\n";
44
    print "      enable_imm4 = 0;\n";
45
    print "      enable_rs1 = 0;\n";
46
    print "      enable_rs2 = 0;\n";
47
    print "      enable_rel9 = 0;\n";
48
    print "      enable_rel10 = 0;\n";
49
    print "      enable_rb = 0;\n";
50
    print "      enable_offs5 = 0;\n";
51
    print "      enable_ri = 0;\n";
52
    print "      enable_imm8 = 0;\n";
53
    print "      ena_rd_low_byte = 0;\n";
54
    print "      ena_rd_high_byte = 0;\n";
55
    print "      ena_bra_ = 0;\n";
56
    print "      ena_alu_ = 0;\n";
57
    print "\n";
58
    print "      case (op_code)\n";
59
}
60
 
61
 
62
if( @ARGV < 1 ) {
63
  $progname = `basename $0`;
64
  chomp($progname);
65
  print "Syntax: $progname <Infile> <Outfile>\n";
66
  die;
67
} elsif ( @ARGV < 2 ) {
68
  print "Using default output file \"temp.v\"\n";
69
  $Infile = shift @ARGV;
70
  $Outfile = 'temp.v';
71
} else {
72
  $Infile = shift @ARGV;
73
  $Outfile = shift @ARGV;
74
}
75
 
76
open( source_file,  "<$Infile" )  || die "Could not open Input file";
77
open( verilog_file, ">$Outfile" ) || die "Could not open Output file";
78
 
79
$i = 1;
80
@op_code_list = ();
81
set_default_values;
82
while (<source_file>) {
83
  chomp;
84
  s/\\$//;      # remove trailing \
85
  s/}$//;       # remove trailing }
86
  s/{.*//;      # get rid of all the lines starting with {
87
  s/\\\w*//g;   # get rid of all words starting with \
88
  s/^ *//g;     # get rid of all leading blanks
89
  s/'96RI/-RI/; # swap oddball minus sign format
90
  if ($_) {
91
    if (! / [01] [01] / ) {
92
      print "\n      // Instruction Group -- $_ \n";
93
    } else {
94
      /( [01] )/;
95
      $inst = index($_, $1);
96
      $instruction = substr($_, 0, $inst);
97
      $op_code = substr($_, $inst++);
98
      # print "Instruction Line = $_\n";
99
      @bit_fields = split / /, $op_code;
100
      shift @bit_fields;  # get rid of leading blank element
101
      $case_var = "";
102
      foreach $field (@bit_fields) {
103
        $case_var = $case_var . &month_to_number($field);
104
      }
105
      push @op_code_list, $case_var;
106
      print "\n      // Instruction = $instruction, Op Code = $op_code\n";
107
      print "      16'b$case_var :\n";
108
      print "         begin\n";
109
      print "           ena_bra_ = 1;\n";
110
      print "           ena_alu_ = 1;\n";
111
      if (index($instruction, "RD") != -1) {
112
        print "           ena_rd_low_byte = 1;\n";
113
        print "           ena_rd_high_byte = 1;\n";
114
      }
115
      if (index($instruction, "IMM3") != -1) {print "           enable_imm3 = 1;\n"}
116
      if (index($instruction, "RS") != -1) {print "           enable_rs = 1;\n"}
117
      if (index($instruction, "IMM4") != -1) {print "           enable_imm4 = 1;\n"}
118
      if (index($instruction, "RS1") != -1) {print "           enable_rs1 = 1;\n"}
119
      if (index($instruction, "RS2") != -1) {print "           enable_rs2 = 1;\n"}
120
      if (index($instruction, "REL9") != -1) {print "           enable_rel9 = 1;\n"}
121
      if (index($instruction, "REL10") != -1) {print "           enable_rel10 = 1;\n"}
122
      if (index($instruction, "RB") != -1) {print "           enable_rb = 1;\n"}
123
      if (index($instruction, "OFFS5") != -1) {print "           enable_offs5 = 1;\n"}
124
      if (index($instruction, "RI") != -1) {print "           enable_ri = 1;\n"}
125
      if (index($instruction, "IMM8") != -1) {print "           enable_imm8 = 1;\n"}
126
      print "         end\n";
127
      $i++;
128
    }
129
  }
130
}
131
 
132
print "      default :\n";
133
print "        begin\n";
134
print "        end\n";
135
print "    endcase\n";
136
 
137
print "    end\n";
138
 
139
 
140
close( source_file );
141
close( verilog_file );
142
 
143
sort @op_code_list;
144
foreach $item (@op_code_list) {
145
  print "$item\n"
146
}
147
 

powered by: WebSVN 2.1.0

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