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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [utils/] [IOParser.java] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/*
2
 * Copyright (c) 2014, Aleksander Osman
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * * Redistributions of source code must retain the above copyright notice, this
9
 *   list of conditions and the following disclaimer.
10
 *
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 *   this list of conditions and the following disclaimer in the documentation
13
 *   and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
 
27
package ao486.utils;
28
 
29
import java.io.DataInputStream;
30
import java.io.EOFException;
31
import java.io.File;
32
import java.io.FileInputStream;
33
import java.io.FileOutputStream;
34
import java.net.DatagramPacket;
35
import java.net.DatagramSocket;
36
import java.net.SocketTimeoutException;
37
 
38
public class IOParser {
39
    public static int read(DataInputStream dis, FileOutputStream fos) throws Exception {
40
        int val = dis.readInt();
41
 
42
        if(((val >> 24) & 0xFF) == 0xC0) {
43
            fos.write(String.format("IAC 0x%02x\n", val & 0xFF).getBytes());
44
            return 0;
45
        }
46
        if(((val >> 24) & 0xFF) == 0xC1) {
47
            fos.write(String.format("Exception 0x%02x\n", val & 0xFF).getBytes());
48
            return 0;
49
        }
50
        return val;
51
    }
52
 
53
    static void capture(String prefix) throws Exception {
54
        DatagramSocket socket = new DatagramSocket(52446);
55
        socket.setReceiveBufferSize(10000000);
56
        socket.setSoTimeout(5000);
57
        System.out.println("Recv buffer size: " + socket.getReceiveBufferSize());
58
 
59
        byte buf[] = new byte[1500];
60
        byte global[] = new byte[1073741824 + 1073741800];
61
        int index = 0;
62
 
63
        DatagramPacket packet = new DatagramPacket(buf, 1500);
64
 
65
        while(true) {
66
            try {
67
                socket.receive(packet);
68
            }
69
            catch(SocketTimeoutException e) {
70
                System.out.println("Checking end...");
71
                File end_file = new File("end");
72
                if(end_file.exists()) {
73
                    end_file.delete();
74
                    break;
75
                }
76
                continue;
77
            }
78
            System.arraycopy(buf, packet.getOffset(), global, index, packet.getLength());
79
            index += packet.getLength();
80
        }
81
 
82
        FileOutputStream fos = new FileOutputStream(prefix + ".dat");
83
        fos.write(global, 0, index);
84
        fos.close();
85
    }
86
 
87
    public static void main(String args[]) throws Exception {
88
        String prefix = "io_sndblaster_7";
89
 
90
        capture(prefix);
91
 
92
 
93
        FileInputStream fis = new FileInputStream(prefix + ".dat");
94
        DataInputStream dis = new DataInputStream(fis);
95
 
96
        FileOutputStream fos = new FileOutputStream(prefix + ".txt");
97
 
98
        Integer counter_prev = null;
99
 
100
        long input_length = new File(prefix + ".dat").length();
101
        input_length /= 1462;
102
 
103
        int val1 = 0, val2 = 0, val3 = 0;
104
        int state = 0;
105
        int total_counter = 0;
106
 
107
        int last_percent = 0;
108
        while(true) {
109
 
110
            int counter;
111
            try {
112
                total_counter++;
113
                counter = dis.readShort();
114
                if(counter < 0) counter += 65536;
115
            }
116
            catch(EOFException e) {
117
                System.out.println("Finished: total_counter: " + total_counter);
118
                break;
119
            }
120
 
121
            if(counter_prev == null) {
122
                counter_prev = counter;
123
            }
124
            else {
125
                int counter_compare = counter_prev + 1;
126
                if(counter_compare > 0xFFFF) counter_compare = 0;
127
                if(counter != counter_compare) {
128
                    System.out.println("Missing: counter: " + counter + " != counter_prev: " + counter_compare + " (" + total_counter + ")");
129
                    //return;
130
                }
131
                counter_prev = counter;
132
            }
133
 
134
            int next_percent = total_counter * 100 / (int)input_length;
135
            if(next_percent != last_percent) {
136
                last_percent = next_percent;
137
                System.out.println(next_percent + "%");
138
            }
139
 
140
            for(int i=0; i<365; i++) {
141
                if(state == 0) {
142
                    val1 = dis.readInt();
143
                    if(((val1 >> 30) & 3) != 0) state++;
144
                }
145
                else if(state == 1) {
146
                    val2 = dis.readInt();
147
                    state++;
148
                }
149
                else if(state == 2) {
150
                    val3 = dis.readInt();
151
                    state++;
152
                }
153
 
154
                if(state == 3) {
155
                    state = 0;
156
 
157
                    int header1 = (val1 >> 30) & 3;
158
                    int header2 = (val1 >> 29) & 1;
159
                    int address = (val1 << 2) | ((val2 >> 30) & 3);
160
                    int data    = (val2 << 2) | ((val3 >> 30) & 3);
161
                    int byteena = (val3 >> 26) & 0xF;
162
                    boolean write = ((val3 >> 25) & 1) == 1;
163
                    boolean read  = ((val3 >> 24) & 1) == 1;
164
                    long instr_cnt= ((val1 & 0xFFL) << 32) | val2;
165
                    int vector    = (val3 >> 24) & 0xFF;
166
 
167
                    if(header1 != 1 && header1 != 2 && header1 != 3) System.out.println("Inv header1: " + header1);
168
 
169
                    if(byteena == 1) data &= 0x000000FF;
170
                    if(byteena == 2) data &= 0x0000FF00;
171
                    if(byteena == 4) data &= 0x00FF0000;
172
                    if(byteena == 8) data &= 0xFF000000;
173
                    if(byteena == 3) data &= 0x0000FFFF;
174
                    if(byteena == 6) data &= 0x00FFFF00;
175
                    if(byteena == 12)data &= 0xFFFF0000;
176
                    if(byteena == 7) data &= 0x00FFFFFF;
177
                    if(byteena == 14)data &= 0xFFFFFF00;
178
 
179
                    if(header1 == 1) {
180
                        //mem
181
                        if(read == false && write == false) System.out.println("Inv mem read/write");
182
                        if(read == true  && write == true)  System.out.println("Inv mem read/write");
183
 
184
                        fos.write(String.format("mem %s %08x %x %08x\n", write? "wr" : "rd", address, byteena, data).getBytes());
185
                    }
186
                    else if(header1 == 2) {
187
                        //io
188
                        if(read == false && write == false) System.out.println("Inv io read/write");
189
                        if(read == true  && write == true)  System.out.println("Inv io read/write");
190
 
191
                        fos.write(String.format("io %s %04x %x %08x\n", write? "wr" : "rd", address, byteena, data).getBytes());
192
                    }
193
                    else if(header1 == 3 && header2 == 0) {
194
                        //interrupt
195
                        fos.write(String.format("IAC 0x%02x at %d\n", vector, instr_cnt).getBytes());
196
                    }
197
                    else if(header1 == 3 && header2 == 1) {
198
                        //interrupt
199
                        fos.write(String.format("Exception 0x%02x at %d\n", vector, instr_cnt).getBytes());
200
                    }
201
 
202
                }
203
 
204
            }
205
        }
206
        fos.close();
207
    }
208
}

powered by: WebSVN 2.1.0

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