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.module.memory.test;
|
28 |
|
|
|
29 |
|
|
import ao486.module.memory.AvalonListener;
|
30 |
|
|
import ao486.module.memory.GlobalListener;
|
31 |
|
|
import ao486.module.memory.Input;
|
32 |
|
|
import ao486.module.memory.Listener;
|
33 |
|
|
import ao486.module.memory.Output;
|
34 |
|
|
import ao486.module.memory.ReadListener;
|
35 |
|
|
import ao486.module.memory.Test;
|
36 |
|
|
import java.util.LinkedList;
|
37 |
|
|
import java.util.Random;
|
38 |
|
|
|
39 |
|
|
public class TestReadCache extends Test implements Listener, ReadListener.ReadInterface {
|
40 |
|
|
|
41 |
|
|
void go(long seed) throws Exception {
|
42 |
|
|
random = new Random(seed);
|
43 |
|
|
|
44 |
|
|
avalon = new AvalonListener(random, this);
|
45 |
|
|
read = new ReadListener();
|
46 |
|
|
global = new GlobalListener();
|
47 |
|
|
|
48 |
|
|
global.set(false, false, false, false, true, false, 0xABCDE000, false, false, false, false);
|
49 |
|
|
|
50 |
|
|
finish_cycle = 0;
|
51 |
|
|
address_base_read = false;
|
52 |
|
|
address_base_plus_1_read = false;
|
53 |
|
|
|
54 |
|
|
counter = 1;
|
55 |
|
|
|
56 |
|
|
address_base = random.nextLong();
|
57 |
|
|
address_base &= 0xFFFFFFF0L;
|
58 |
|
|
|
59 |
|
|
address = address_base + random.nextInt(16);
|
60 |
|
|
length = 1 + random.nextInt(8);
|
61 |
|
|
|
62 |
|
|
read.read(4, 0, address, length, false, false, this);
|
63 |
|
|
|
64 |
|
|
//----------
|
65 |
|
|
|
66 |
|
|
LinkedList<Listener> listeners = new LinkedList<>();
|
67 |
|
|
listeners.add(avalon);
|
68 |
|
|
listeners.add(read);
|
69 |
|
|
listeners.add(global);
|
70 |
|
|
listeners.add(this);
|
71 |
|
|
|
72 |
|
|
run_simulation(listeners);
|
73 |
|
|
}
|
74 |
|
|
@Override
|
75 |
|
|
public void read(int cycle, long data) throws Exception {
|
76 |
|
|
//System.out.printf("Read value: %x\n", data);
|
77 |
|
|
|
78 |
|
|
for(int i=0; i<length; i++) {
|
79 |
|
|
long value = avalon.get_memory(address+i);
|
80 |
|
|
|
81 |
|
|
if((value & 0xFF) != (data & 0xFF)) throw new Exception(String.format("Value mismatch: data: %x, value: %x, i: %d", data, value, i));
|
82 |
|
|
|
83 |
|
|
value >>= 8;
|
84 |
|
|
data >>= 8;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
counter++;
|
88 |
|
|
|
89 |
|
|
if(counter >= 1000) {
|
90 |
|
|
finish_cycle = cycle+1;
|
91 |
|
|
return;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
address = address_base + random.nextInt(16);
|
95 |
|
|
length = 1 + random.nextInt(8);
|
96 |
|
|
|
97 |
|
|
read.read(cycle+1, 0, address, length, false, false, this);
|
98 |
|
|
//System.out.printf("Next read: %d\n", cycle);
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
@Override
|
102 |
|
|
public void read_page_fault(int cycle, long cr2, long error_code) throws Exception {
|
103 |
|
|
throw new Exception("read_page_fault: cr2: " + cr2 + ", error_code: " + error_code);
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
@Override
|
107 |
|
|
public void read_ac_fault(int cycle) throws Exception {
|
108 |
|
|
throw new Exception("read_ac_fault.");
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
@Override
|
112 |
|
|
public void set_input(int cycle, Input input) throws Exception {
|
113 |
|
|
if(cycle >= finish_cycle && finish_cycle > 0) input.finished = true;
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
@Override
|
117 |
|
|
public void get_output(int cycle, Output output) throws Exception {
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
@Override
|
121 |
|
|
public void avalon_read(int cycle, long read_address) throws Exception {
|
122 |
|
|
if(cycle >= 257 && (read_address & 0xFFFFFFF0) == address_base) {
|
123 |
|
|
if(address_base_read) throw new Exception("Reading double address_base_read.");
|
124 |
|
|
address_base_read = true;
|
125 |
|
|
}
|
126 |
|
|
if(cycle >= 257 && (read_address & 0xFFFFFFF0) == address_base+1) {
|
127 |
|
|
if(address_base_plus_1_read) throw new Exception("Reading double address_base_plus_1_read.");
|
128 |
|
|
address_base_plus_1_read = true;
|
129 |
|
|
}
|
130 |
|
|
if(((read_address & 0xFFFFFFF0) != address_base) && ((read_address & 0xFFFFFFF0) == address_base+1)) throw new Exception("Unknown address read.");
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
int length;
|
134 |
|
|
long address;
|
135 |
|
|
long address_base;
|
136 |
|
|
|
137 |
|
|
Random random;
|
138 |
|
|
|
139 |
|
|
int counter;
|
140 |
|
|
int finish_cycle;
|
141 |
|
|
|
142 |
|
|
boolean address_base_read;
|
143 |
|
|
boolean address_base_plus_1_read;
|
144 |
|
|
|
145 |
|
|
AvalonListener avalon;
|
146 |
|
|
ReadListener read;
|
147 |
|
|
GlobalListener global;
|
148 |
|
|
|
149 |
|
|
//-------------
|
150 |
|
|
|
151 |
|
|
public static void main(String args[]) throws Exception {
|
152 |
|
|
TestReadCache test1 = new TestReadCache();
|
153 |
|
|
|
154 |
|
|
for(int i=0; i<10; i++) {
|
155 |
|
|
test1.go(i);
|
156 |
|
|
|
157 |
|
|
System.out.println("Run " + i + " complete.");
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
System.out.println("[Main] thread end.");
|
161 |
|
|
}
|
162 |
|
|
}
|