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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [module/] [memory/] [CheckListener.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.module.memory;
28
 
29
import java.util.HashMap;
30
 
31
 
32
public class CheckListener implements Listener {
33
 
34
    public interface CheckInterface {
35
        void checked(int cycle) throws Exception;
36
        void check_page_fault(int cycle, long cr2, long error_code) throws Exception;
37
    }
38
 
39
    public void check(int cycle, long address, boolean write, CheckInterface check_interface) throws Exception {
40
        if(map.containsKey(cycle)) throw new Exception("Double check in cycle: " + cycle);
41
 
42
        Input input = new Input();
43
        input.tlbcheck_address = address;
44
        input.tlbcheck_rw      = write;
45
 
46
        map.put(cycle, input);
47
        check_map.put(cycle, check_interface);
48
    }
49
 
50
    //------------------------------
51
 
52
    @Override
53
    public void set_input(int cycle, Input input) throws Exception {
54
        if(check != null && map.containsKey(cycle)) throw new Exception("Overlapping check detected on cycle " + cycle);
55
 
56
        if(check != null) {
57
            input.tlbcheck_do      = true;
58
            input.tlbcheck_address = check_input.tlbcheck_address;
59
            input.tlbcheck_rw      = check_input.tlbcheck_rw;
60
        }
61
 
62
        Input local_input = map.get(cycle);
63
        if(local_input != null) {
64
            check = check_map.get(cycle);
65
 
66
            input.tlbcheck_do      = true;
67
            input.tlbcheck_address = local_input.tlbcheck_address;
68
            input.tlbcheck_rw      = local_input.tlbcheck_rw;
69
 
70
            check_input = input;
71
        }
72
    }
73
 
74
 
75
    @Override
76
    public void get_output(int cycle, Output output) throws Exception {
77
 
78
        if(check == null && output.tlbcheck_page_fault == false && (output.tlbcheck_done || output.tlbcheck_page_fault)) throw new Exception("Unexpected check done.");
79
 
80
        if(output.tlbcheck_done && output.tlbcheck_page_fault) throw new Exception("Double read result.");
81
 
82
        if(check != null && output.tlbcheck_done) {
83
            check.checked(cycle);
84
            check = null;
85
        }
86
        if(check != null && output.tlbcheck_page_fault) {
87
            check.check_page_fault(cycle, output.tlb_check_pf_cr2, output.tlb_check_pf_error_code);
88
            check = null;
89
        }
90
    }
91
 
92
    /*
93
    //Input
94
    public boolean tlbcheck_do                     = false;
95
    public long    tlbcheck_address                = 0; //32
96
    public boolean tlbcheck_rw                     = false;
97
 
98
    //Output
99
    public boolean tlbcheck_done;
100
    public boolean tlbcheck_page_fault;
101
    */
102
 
103
    CheckInterface check;
104
    Input          check_input;
105
 
106
    HashMap<Integer, Input> map                = new HashMap<>();
107
    HashMap<Integer, CheckInterface> check_map = new HashMap<>();
108
}

powered by: WebSVN 2.1.0

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