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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [module/] [memory/] [WriteListener.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
public class WriteListener implements Listener {
32
 
33
    public interface WriteInterface {
34
        void written(int cycle) throws Exception;
35
        void write_page_fault(int cycle, long cr2, long error_code) throws Exception;
36
        void write_ac_fault(int cycle) throws Exception;
37
    }
38
 
39
    public void write(int cycle, long cpl, long address, long length, boolean lock, boolean rmw, long data, WriteListener.WriteInterface write_interface) throws Exception {
40
        if(map.containsKey(cycle)) throw new Exception("Double write in cycle: " + cycle);
41
 
42
        Input input = new Input();
43
        input.write_address = address;
44
        input.write_cpl     = cpl;
45
        input.write_length  = length;
46
        input.write_lock    = lock;
47
        input.write_rmw     = rmw;
48
        input.write_data    = data;
49
 
50
        map.put(cycle, input);
51
        write_map.put(cycle, write_interface);
52
    }
53
 
54
    //------------------------------
55
 
56
 
57
    @Override
58
    public void set_input(int cycle, Input input) throws Exception {
59
        if(write != null && map.containsKey(cycle)) throw new Exception("Overlapping write detected on cycle " + cycle);
60
 
61
        if(write != null) {
62
            input.write_do       = true;
63
            input.write_cpl      = write_input.write_cpl;
64
            input.write_address  = write_input.write_address;
65
            input.write_length   = write_input.write_length;
66
            input.write_lock     = write_input.write_lock;
67
            input.write_rmw      = write_input.write_rmw;
68
            input.write_data     = write_input.write_data;
69
        }
70
 
71
        Input local_input = map.get(cycle);
72
        if(local_input != null) {
73
            write = write_map.get(cycle);
74
 
75
            input.write_do       = true;
76
            input.write_cpl      = local_input.write_cpl;
77
            input.write_address  = local_input.write_address;
78
            input.write_length   = local_input.write_length;
79
            input.write_lock     = local_input.write_lock;
80
            input.write_rmw      = local_input.write_rmw;
81
            input.write_data     = local_input.write_data;
82
 
83
            write_input = input;
84
        }
85
    }
86
 
87
    @Override
88
    public void get_output(int cycle, Output output) throws Exception {
89
        if(write == null && output.write_page_fault == false && (output.write_done || output.write_page_fault || output.write_ac_fault)) {
90
            throw new Exception("Unexpected write done.");
91
        }
92
 
93
        if(output.write_done       && output.write_page_fault)    throw new Exception("Double write result.");
94
        if(output.write_done       && output.write_ac_fault)      throw new Exception("Double write result.");
95
        if(output.write_page_fault && output.write_ac_fault)      throw new Exception("Double write result.");
96
 
97
        if(write != null && output.write_done) {
98
            write.written(cycle);
99
            write = null;
100
        }
101
        if(write != null && output.write_page_fault) {
102
            write.write_page_fault(cycle, output.tlb_write_pf_cr2, output.tlb_write_pf_error_code);
103
            write = null;
104
        }
105
        if(write != null && output.write_ac_fault) {
106
            write.write_ac_fault(cycle);
107
            write = null;
108
        }
109
    }
110
 
111
    /*
112
    //Input
113
    public boolean write_do                        = false;
114
    public long    write_cpl                       = 0; //2
115
    public long    write_address                   = 0; //32
116
    public long    write_length                    = 0; //3
117
    public boolean write_lock                      = false;
118
    public boolean write_rmw                       = false;
119
    public long    write_data                      = 0; //32
120
 
121
    //Output
122
    public boolean write_done;
123
    public boolean write_page_fault;
124
    public boolean write_ac_fault;
125
    */
126
 
127
    WriteInterface write;
128
    Input          write_input;
129
 
130
    HashMap<Integer, Input> map                = new HashMap<>();
131
    HashMap<Integer, WriteInterface> write_map = new HashMap<>();
132
}

powered by: WebSVN 2.1.0

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