add more ship files
[fleet.git] / ships / Iscratch.ship
1 ship: Iscratch
2
3 == Ports ===========================================================
4 data  in:    write_addr
5 data  in:    write_data
6 token out:   write_done
7
8 data  in:    cbd
9
10 == Fleeterpreter ====================================================
11
12     private long[] mem = new long[0];
13     public long readMem(int addr) { return mem[addr]; }
14     public void writeMem(int addr, long val) {
15         if (addr >= mem.length) {
16             long[] newmem = new long[addr * 2 + 1];
17             System.arraycopy(mem, 0, newmem, 0, mem.length);
18             mem = newmem;
19         }
20         mem[addr] = val;
21     }
22
23     public void dispatch(int addr, int size) {
24         for(int i=addr; i<addr+size; i++) {
25             Instruction instr = ((Interpreter)getFleet()).readInstruction(readMem(i));
26             ((Interpreter)getFleet()).dispatch(instr, i);
27         }
28     }
29
30     public void service() {
31         if (box_cbd.dataReadyForShip()) {
32             int val = box_cbd.removeDataForShip();
33             int addr = val >> 6;
34             int size = val & 0x3f;
35             dispatch(addr, size);
36         }
37
38         if (box_write_addr.dataReadyForShip() &&
39             box_write_data.dataReadyForShip() &&
40             box_write_done.readyForItemFromShip()) {
41             Interpreter f = (Interpreter)getFleet();
42             f.writeMem(box_write_addr.removeDataForShip(),
43                        box_write_data.removeDataForShip());
44             box_write_done.addTokenFromShip();
45         }
46     }
47
48     public void boot(byte[] instructions) {
49         Interpreter fleet = (Interpreter)getFleet();
50         // load the iscratch and take note of the 0-address CBD
51         long launch = 0;
52         for(int i=0; i<instructions.length; i+=6) {
53             long word = 0;
54             for(int j=0; j<6; j++)
55                 word = (word << 8) | (instructions[i+j] & 0xff);
56             writeMem(i/6, word);
57             if (i==0) launch = word;
58         }
59
60         // dispatch the 0-address CBD
61         int base = (int)(launch >> 6);
62         base = base & ~(0xffffffff << 18);
63         int size = (int)launch;
64         size = size & ~(0xffffffff <<  6);
65         dispatch(base, size);
66     }
67
68 == Constants ========================================================
69 == TeX ==============================================================
70 == ArchSim ==============================================================
71 == FPGA ==============================================================
72
73 == Contributors =========================================================
74 Adam Megacz <megacz@cs.berkeley.edu>