1 package edu.berkeley.fleet.slipway;
2 import edu.berkeley.fleet.interpreter.*;
3 import edu.berkeley.fleet.api.*;
4 import edu.berkeley.fleet.ies44.*;
5 import edu.berkeley.fleet.*;
6 import java.lang.reflect.*;
7 import edu.berkeley.sbp.chr.*;
8 import edu.berkeley.sbp.misc.*;
9 import edu.berkeley.sbp.meta.*;
10 import edu.berkeley.sbp.bind.*;
11 import edu.berkeley.sbp.util.*;
14 import edu.berkeley.fleet.ships.*;
19 DataInbox command = new DataInbox(this, "command", true);
20 DataOutbox ihorn = new DataOutbox(this, "ihorn", true, true, false);
21 DataOutbox dhorn = new DataOutbox(this, "dhorn", true, false, true);
26 public class Slipway extends Interpreter {
29 createShip("Alu2", "alu2a");
30 createShip("Alu2", "alu2b");
31 createShip("Alu2", "alu2c");
32 createShip("Alu2", "alu2d");
33 createShip("Debug", "debug");
34 createShip("Execute", "execute");
35 createShip("Fifo", "fifo1");
36 createShip("Fifo", "fifo2");
37 createShip("Fifo", "fifo3");
38 createShip("Fifo", "fifo4");
39 createShip("Icache", "icache1");
40 createShip("Icache", "icache2");
41 createShip("Dcache", "dcache1");
42 createShip("Dcache", "dcache2");
45 public FleetProcess run(final byte[] instructions) {
47 return new Client(instructions);
48 } catch (IOException e) { throw new RuntimeException(e); }
51 public void dumpFabric(boolean quiet) {
52 // FIXME: this is really ugly: the order of port declarations in
53 // the XXXShip.java file must match the order in the .balsa file!
55 ArrayList instructionports = new ArrayList<InterpreterBenkoBox>();
56 for(InterpreterShip ship : shiplist)
57 for(BenkoBox port : ship.getBenkoBoxes())
58 if (!((InterpreterBenkoBox)port).special())
59 instructionports.add(port);
60 FabricTree instructions =
61 new FabricTree((InterpreterBenkoBox[])instructionports.toArray(new InterpreterBenkoBox[0]),
65 ArrayList inputports = new ArrayList<InterpreterBenkoBox>();
66 for(InterpreterShip ship : shiplist)
67 for(BenkoBox port : ship.getBenkoBoxes())
68 if (!((InterpreterBenkoBox)port).special())
71 new FabricTree((InterpreterBenkoBox[])inputports.toArray(new InterpreterBenkoBox[0]),
75 ArrayList outputports = new ArrayList<InterpreterBenkoBox>();
76 for(InterpreterShip ship : shiplist)
77 for(BenkoBox port : ship.getBenkoBoxes())
78 if (!((InterpreterBenkoBox)port).special() || ((InterpreterBenkoBox)port).dhorn())
79 outputports.add(port);
81 new FabricTree((InterpreterBenkoBox[])outputports.toArray(new InterpreterBenkoBox[0]),
85 ArrayList ihornports = new ArrayList<InterpreterBenkoBox>();
86 for(InterpreterShip ship : shiplist)
87 for(BenkoBox port : ship.getBenkoBoxes())
88 if (((InterpreterBenkoBox)port).ihorn())
91 new FabricTree((InterpreterBenkoBox[])ihornports.toArray(new InterpreterBenkoBox[0]),
96 System.out.println("`include \"macros.v\"");
97 System.out.println("module fabric(clk, data_Icache0_command_r, data_Icache0_command_a, data_Icache0_command,");
98 System.out.println(" data_Debug0_out_r, data_Debug0_out_a, data_Debug0_out);");
99 System.out.println(" input clk;");
100 System.out.println(" input data_Icache0_command_r;");
101 System.out.println(" output data_Icache0_command_a;");
102 System.out.println(" output data_Debug0_out_r;");
103 System.out.println(" input data_Debug0_out_a;");
104 System.out.println(" output [(`PACKET_WIDTH-1):0] data_Debug0_out;");
105 System.out.println(" input [(`PACKET_WIDTH-1):0] data_Icache0_command;");
106 //System.out.println(" wire [(`INSTRUCTION_WIDTH-1):0] data_Icache0_ihorn;");
107 //System.out.println(" wire [(`PACKET_WIDTH-1):0] data_Icache0_dhorn;");
108 System.out.println();
110 System.out.println();
112 instructions.dumpChannels(true);
113 outputs.dumpChannels(true);
114 inputs.dumpChannels(true);
115 ihorns.dumpChannels(true);
116 for(InterpreterShip ship : shiplist)
117 for(BenkoBox port : ship.getBenkoBoxes())
118 if (!((InterpreterBenkoBox)port).special() || ((InterpreterBenkoBox)port).dhorn())
119 System.out.println(" wire [(`PACKET_WIDTH-1):0] data_"
120 +getUniqueName(ship)+"_"+port.getName()+";");
122 System.out.println("");
123 instructions.dumpChannels(false);
124 System.out.println("");
125 outputs.dumpChannels(false);
126 System.out.println("");
127 inputs.dumpChannels(false);
128 System.out.println("");
129 ihorns.dumpChannels(false);
130 System.out.println("");
131 for(InterpreterShip ship : shiplist) {
132 System.out.print(ship.getClass().getSimpleName().toLowerCase());
133 System.out.print(" ");
134 System.out.print("krunk"+(krunk++));
135 System.out.print("(clk, ");
136 boolean first = true;
137 for(BenkoBox port : ship.getBenkoBoxes()) {
138 if (!first) System.out.print(", ");
140 String prefix = "data_";
141 if (((InterpreterBenkoBox)port).ihorn()) prefix = "ihorn_";
142 if (((InterpreterBenkoBox)port).dhorn()) prefix = "source_";
143 System.out.print(prefix+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
144 System.out.print(prefix+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
145 System.out.print(prefix+getUniqueName(port.getShip())+"_"+port.getName());
146 System.out.print(" ");
148 System.out.println(");");
150 for(BenkoBox port : ship.getBenkoBoxes()) {
151 if (((InterpreterBenkoBox)port).special()) continue;
152 if (port instanceof Inbox) {
153 System.out.print("inbox");
155 System.out.print("outbox");
157 System.out.print(" krunk"+(krunk++)+"(clk, ");
158 System.out.print("instruction_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
159 System.out.print("instruction_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
160 System.out.print("instruction_"+getUniqueName(port.getShip())+"_"+port.getName()+", ");
161 System.out.print("dest_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
162 System.out.print("dest_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
163 System.out.print("dest_"+getUniqueName(port.getShip())+"_"+port.getName()+", ");
164 System.out.print("source_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
165 System.out.print("source_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
166 System.out.print("source_"+getUniqueName(port.getShip())+"_"+port.getName()+", ");
167 System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
168 System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
169 System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName());
170 System.out.print(");");
171 System.out.println();
176 System.out.println("funnel topfun(clk,"+
177 " dest_r, dest_a, dest,"+
178 " source_r, source_a, source,"+
179 " data_Icache0_dhorn_r, data_Icache0_dhorn_a, data_Icache0_dhorn);");
181 System.out.println("assign instruction_r = ihorn_r;");
182 System.out.println("assign ihorn_a = instruction_a;");
183 System.out.println("assign instruction = ihorn;");
184 System.out.println("assign dest_r = source_r;");
185 System.out.println("assign source_a = dest_a;");
186 System.out.println("assign dest = source;");
187 System.out.println("endmodule");
190 private static class FabricTree {
194 public void dumpChannels(boolean decl) { root.dumpChannels(0, decl); }
195 public FabricTree(InterpreterBenkoBox[] ports, String component, String prefix) {
196 this.prefix = prefix;
197 root = (Node)mkNode("", component, ports, 0, ports.length, 0, 0);
199 private Object mkNode(String name, String component, InterpreterBenkoBox[] ports,
200 int start, int end, int addr, int bits) {
201 if (end-start == 0) return null;
202 if (end-start == 1) {
203 InterpreterBenkoBox p = ports[start];
204 if (prefix.equals("instruction")) {
207 } else if (prefix.equals("dest")) {
214 return new Node(name,
216 mkNode(name+"_0", component, ports, start, start+len/2, addr, bits+1),
217 mkNode(name+"_1", component, ports, start+len/2, end, addr | (1 << bits), bits+1),
221 private String describe(String prefix, Object o) {
222 if (o==null) return null;
223 if (o instanceof InterpreterBenkoBox) {
224 InterpreterBenkoBox p = (InterpreterBenkoBox)o;
225 return prefix+"_"+getUniqueName(p.getShip())+"_"+p.getName();
227 if (o instanceof Node) {
228 return ((Node)o).describe(prefix);
239 public Node(String name, String component, Object left, Object right, int addr, int bits) {
243 this.component = component;
247 public void dumpChannels(int indentamount, boolean decl) {
249 for(int i=0; i<indentamount; i++) indent += " ";
251 String n = describe(prefix).startsWith("instruction")
252 ? "[(`INSTRUCTION_WIDTH-1):0]" : "[(`PACKET_WIDTH-1):0]";
253 System.out.println(" wire "+n+" "+indent+describe(prefix)+";");
255 System.out.println(" "+indent+
257 "krunk"+(krunk++)+"(clk, "+
258 describe(prefix)+"_r, "+
259 describe(prefix)+"_a, "+
260 describe(prefix)+", "+
261 FabricTree.this.describe(prefix, left)+"_r, "+
262 FabricTree.this.describe(prefix, left)+"_a, "+
263 FabricTree.this.describe(prefix, left)+", "+
264 FabricTree.this.describe(prefix, right)+"_r, "+
265 FabricTree.this.describe(prefix, right)+"_a, "+
266 FabricTree.this.describe(prefix, right)+
269 dumpChannels(left, indentamount+1, decl);
270 dumpChannels(right, indentamount+1, decl);
272 public void dumpChannels(Object o, int indentamount, boolean decl) {
274 if (o instanceof Node) {
275 ((Node)o).dumpChannels(indentamount, decl);
278 for(int i=0; i<indentamount; i++) indent += " ";
280 String n = FabricTree.this.describe(prefix,o).startsWith("instruction")
281 ? "[(`INSTRUCTION_WIDTH-1):0]" : "[(`PACKET_WIDTH-1):0]";
282 System.out.println(" wire "+n+" "+indent+FabricTree.this.describe(prefix,o)+";");
286 public String describe(String prefix) {
291 public static int krunk=0;
293 private static String getUniqueName(Ship ship) {
294 return ship.getType() + ship.getOrdinal();