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;
|
28 |
|
|
|
29 |
|
|
import java.util.HashMap;
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
public class ReadListener implements Listener {
|
33 |
|
|
|
34 |
|
|
public interface ReadInterface {
|
35 |
|
|
void read(int cycle, long data) throws Exception;
|
36 |
|
|
void read_page_fault(int cycle, long cr2, long error_code) throws Exception;
|
37 |
|
|
void read_ac_fault(int cycle) throws Exception;
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
public void read(int cycle, long cpl, long address, long length, boolean lock, boolean rmw, ReadInterface read_interface) throws Exception {
|
42 |
|
|
if(map.containsKey(cycle)) throw new Exception("Double read in cycle: " + cycle);
|
43 |
|
|
|
44 |
|
|
Input input = new Input();
|
45 |
|
|
input.read_address = address;
|
46 |
|
|
input.read_cpl = cpl;
|
47 |
|
|
input.read_length = length;
|
48 |
|
|
input.read_lock = lock;
|
49 |
|
|
input.read_rmw = rmw;
|
50 |
|
|
|
51 |
|
|
map.put(cycle, input);
|
52 |
|
|
read_map.put(cycle, read_interface);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
//------------------------------
|
56 |
|
|
|
57 |
|
|
@Override
|
58 |
|
|
public void set_input(int cycle, Input input) throws Exception {
|
59 |
|
|
if(read != null && map.containsKey(cycle)) throw new Exception("Overlapping read detected on cycle " + cycle);
|
60 |
|
|
|
61 |
|
|
if(read != null) {
|
62 |
|
|
input.read_do = true;
|
63 |
|
|
input.read_cpl = read_input.read_cpl;
|
64 |
|
|
input.read_address = read_input.read_address;
|
65 |
|
|
input.read_length = read_input.read_length;
|
66 |
|
|
input.read_lock = read_input.read_lock;
|
67 |
|
|
input.read_rmw = read_input.read_rmw;
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
Input local_input = map.get(cycle);
|
71 |
|
|
if(local_input != null) {
|
72 |
|
|
read = read_map.get(cycle);
|
73 |
|
|
|
74 |
|
|
input.read_do = true;
|
75 |
|
|
input.read_cpl = local_input.read_cpl;
|
76 |
|
|
input.read_address = local_input.read_address;
|
77 |
|
|
input.read_length = local_input.read_length;
|
78 |
|
|
input.read_lock = local_input.read_lock;
|
79 |
|
|
input.read_rmw = local_input.read_rmw;
|
80 |
|
|
|
81 |
|
|
read_input = input;
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
@Override
|
87 |
|
|
public void get_output(int cycle, Output output) throws Exception {
|
88 |
|
|
|
89 |
|
|
if(read == null && output.read_page_fault == false && (output.read_done || output.read_page_fault || output.read_ac_fault)) throw new Exception("Unexpected read done.");
|
90 |
|
|
|
91 |
|
|
if(output.read_done && output.read_page_fault) throw new Exception("Double read result.");
|
92 |
|
|
if(output.read_done && output.read_ac_fault) throw new Exception("Double read result.");
|
93 |
|
|
if(output.read_page_fault && output.read_ac_fault) throw new Exception("Double read result.");
|
94 |
|
|
|
95 |
|
|
if(read != null && output.read_done) {
|
96 |
|
|
read.read(cycle, output.read_data);
|
97 |
|
|
read = null;
|
98 |
|
|
}
|
99 |
|
|
if(read != null && output.read_page_fault) {
|
100 |
|
|
read.read_page_fault(cycle, output.tlb_read_pf_cr2, output.tlb_read_pf_error_code);
|
101 |
|
|
read = null;
|
102 |
|
|
}
|
103 |
|
|
if(read != null && output.read_ac_fault) {
|
104 |
|
|
read.read_ac_fault(cycle);
|
105 |
|
|
read = null;
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
/*
|
110 |
|
|
//Input
|
111 |
|
|
boolean read_do = false;
|
112 |
|
|
long read_cpl = 0; //2
|
113 |
|
|
long read_address = 0; //32
|
114 |
|
|
long read_length = 0; //4
|
115 |
|
|
boolean read_lock = false;
|
116 |
|
|
boolean read_rmw = false;
|
117 |
|
|
|
118 |
|
|
//Output
|
119 |
|
|
boolean read_done;
|
120 |
|
|
boolean read_page_fault;
|
121 |
|
|
boolean read_ac_fault;
|
122 |
|
|
long read_data; //64
|
123 |
|
|
*/
|
124 |
|
|
|
125 |
|
|
ReadInterface read;
|
126 |
|
|
Input read_input;
|
127 |
|
|
|
128 |
|
|
HashMap<Integer, Input> map = new HashMap<>();
|
129 |
|
|
HashMap<Integer, ReadInterface> read_map = new HashMap<>();
|
130 |
|
|
}
|