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

Subversion Repositories zet86

[/] [zet86/] [trunk/] [bin/] [web2rom] - Blame information for rev 55

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

Line No. Rev Author Line
1 2 zeus
#!/usr/bin/php
2
3
  //
4
  //  Script which fetches the contents of the microinstruction definitions
5
  //  and translates them into a verilog ROM module.
6
  //  Possible upgrade: Take into account the "DON'T CARE" values in the
7
  //  micro-instructions, so the micro instruction ROM can be smaller
8
  //
9
 
10
  // Read all the instruction definitions
11
  //
12 15 zeus
  $f1 = fopen("http://zet.aluzina.org/index.php/8086_instructions", "r");
13 2 zeus
 
14
  if (!$f1)
15
    {
16
      echo "Error with the URL\n";
17
      exit(1);
18
    }
19
 
20
  while(!feof($f1)) $str .= fread($f1, 1024);
21
  fclose($f1);
22
 
23
  // 1. Get the array of pairs (NAME, instr)
24
  $arr1 = explode("######", $str);
25
  for($i=1, $seq=0; $i
26
    {
27
      $arr2 = explode("\n", $arr1[$i]);
28
      for($j=1; $j
29
        {
30
          if($arr2[$j]=="
") break;
31
          $arr3 = split("[ ]+", $arr2[$j]);
32
          $instr[$arr3[0]]['micro'][]['code'] = $arr3[1];
33
 
34
          if(isset($instr[$arr3[0]]['seq'])) $seq++;
35
          else $instr[$arr3[0]]['seq'] = $seq++;
36
        }
37
    }
38
 
39
  // 2. Replace x/d/m/s by zeros and remove _ from instr
40
  $micros = Array();
41
 
42
  foreach ($instr as $key => $value)
43
    {
44
      for($i=0; $i
45
        {
46
          $microi = ereg_replace ("_", "", ereg_replace( "[xdms]", "0",
47
                                  $value['micro'][$i]['code']));
48
          if (isset($micro_data_width)) {
49
            if ($micro_data_width!=strlen($microi))
50
              die ("Instruction $key does not have the same length\n");
51
          } else $micro_data_width = strlen($microi);
52
 
53
          $instr[$key]['micro'][$i]['code'] = $microi;
54
 
55
          for ($j=0; $j
56
              if (!strcmp($micros[$j], $microi)) break;
57
 
58
          if ($j == count($micros)) $micros[] = $microi;
59
          $instr[$key]['micro'][$i]['order'] = $j;
60
        }
61
    }
62
 
63
  // 3. Export the micro rom rounded to the next power of 2
64
  $fm = fopen ("micro_rom.dat", "w");
65
  for ($i=0, $j=0; $i
66
    {
67
      fwrite($fm, $micros[$i] . "\n");
68
      if ($i == pow(2, $j)) $j++;
69
    }
70
 
71
  for ($k=0; $k<$micro_data_width; $k++) $str_zero .= "0";
72
  while ($i++ < pow(2, $j)) fwrite($fm, $str_zero . "\n");
73
  fclose($fm);
74
 
75
  $micro_addr_width = $j;
76
 
77
  // 4. Export the sequencer rom rounded to the next power of 2
78
  $seq_data_width = $micro_addr_width + 1;
79
 
80
  $fs = fopen ("seq_rom.dat", "w");
81
  $l=0; $j=0;
82
  foreach ($instr as $key => $value)
83
    for($i=0; $i
84
      {
85
        $last = ($i == count($value['micro'])-1);
86
        $last = $last << $micro_addr_width;
87
        fprintf($fs, "%0${seq_data_width}b\n",
88
                     $value['micro'][$i][order] | $last);
89
        if($l == pow(2, $j)) $j++;
90
      }
91
 
92
  for ($k=0; $k<$seq_data_width; $k++) $str1_zero .= "0";
93
  while ($l++ < pow(2, $j)) fwrite($fs, $str1_zero . "\n");
94
  fclose($fs);
95
 
96
  $seq_addr_width = $j;
97
 
98
  // 5. Export the instruction sequencer code
99
  $fi = fopen ("rom_def.v", "w");
100
  fwrite($fi, "`define MICRO_DATA_WIDTH $micro_data_width\n");
101
  fwrite($fi, "`define MICRO_ADDR_WIDTH $micro_addr_width\n");
102
  fwrite($fi, "`define SEQ_DATA_WIDTH $seq_data_width\n");
103
  fwrite($fi, "`define SEQ_ADDR_WIDTH $seq_addr_width\n");
104
  fwrite($fi, "\n");
105
 
106
  foreach ($instr as $key => $value)
107
    fprintf ($fi, "`define $key\t$seq_addr_width'b%0${seq_addr_width}b\n",
108
             $value['seq']);
109
  fclose($fi);
110
?>

powered by: WebSVN 2.1.0

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