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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [module/] [memory/] [test/] [TestPrefetchCache.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.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.PrefetchListener;
35
import ao486.module.memory.Test;
36
import java.util.LinkedList;
37
import java.util.Random;
38
 
39
public class TestPrefetchCache extends Test implements Listener, PrefetchListener.PrefetchInterface {
40
 
41
    void go(long seed) throws Exception {
42
        random = new Random(seed);
43
 
44
        avalon   = new AvalonListener(random, this);
45
        prefetch = new PrefetchListener();
46
        global   = new GlobalListener();
47
 
48
        finish_cycle = 0;
49
        counter = 1;
50
 
51
 
52
        code_stream   = new LinkedList<>();
53
 
54
        long cs_base = 0xFFFFFFF0L;
55
        long eip     = 0x00000;
56
        long cpl     = 0;
57
        long cs_limit= 0x00000 + 16;
58
 
59
        for(int i=0; i<16; i++) {
60
            long b = avalon.get_memory(cs_base + eip + i);
61
            code_stream.add((byte)b);
62
 
63
            //System.out.printf("[%x] = %x\n", cs_base + eip + i, b);
64
        }
65
 
66
        global.set(false, false, false, false, random.nextBoolean(), false, 0x12345678, false, false, false, false);
67
 
68
        prefetch.prefetch(cpl, eip, cs_base, cs_limit, this);
69
 
70
        //----------
71
 
72
        LinkedList<Listener> listeners = new LinkedList<>();
73
        listeners.add(avalon);
74
        listeners.add(prefetch);
75
        listeners.add(global);
76
        listeners.add(this);
77
 
78
        run_simulation(listeners);
79
    }
80
 
81
    @Override
82
    public void prefetched(int cycle, long value, long size) throws Exception {
83
        for(int i=0; i<size; i++) {
84
            if(code_stream.isEmpty()) throw new Exception("Code stream is empty: i: " + i);
85
 
86
            byte expected = code_stream.pop();
87
            if(expected != (byte)value) throw new Exception("Invalid prefetched code: i: " + i + String.format(", expected: %x, value: %x", expected, (byte)value));
88
 
89
            //System.out.printf("expected: %x == value: %x, size: %d\n", expected, (byte)value, code_stream.size());
90
 
91
            value >>= 8;
92
        }
93
    }
94
    @Override
95
    public void prefetch_page_fault(int cycle, long cr2, long error_code) throws Exception {
96
        throw new Exception("prefetch pf.");
97
    }
98
    @Override
99
    public void prefetch_gp_fault(int cycle) throws Exception {
100
        if(code_stream.size() > 0) throw new Exception("prefetch gp fault before limit reached.");
101
 
102
        counter++;
103
 
104
        if(counter >= 100) {
105
            finish_cycle = cycle+1;
106
            return;
107
        }
108
 
109
        do {
110
            long cs_base = random.nextLong() & 0x0000FFFFL;
111
            long eip     = random.nextLong() & 0x0000FFFFL;
112
            long cpl     = 0;
113
            long cs_limit= eip + random.nextInt(512);
114
 
115
            if(cs_limit >= 0x100000L) while((cs_limit & 0xFFFL) != 0xFFFL) cs_limit++;
116
 
117
            if(cs_base + eip >= 0x100000000L) continue;
118
 
119
            for(int i=0; i<cs_limit - eip + 1; i++) {
120
                long b = avalon.get_memory(cs_base + eip + i);
121
 
122
                code_stream.add((byte)b);
123
 
124
                //System.out.printf("[%x] = %x\n", cs_base + eip + i, b);
125
            }
126
 
127
            prefetch.prefetch(cpl, eip, cs_base, cs_limit, this);
128
            break;
129
        }while(true);
130
 
131
        global.set_reset(true, false, false, false);
132
        reset_cycle = cycle+1;
133
    }
134
 
135
 
136
    @Override
137
    public void set_input(int cycle, Input input) throws Exception {
138
        if(cycle >= finish_cycle && finish_cycle > 0) input.finished = true;
139
 
140
        if(cycle >= reset_cycle && reset_cycle > 0) {
141
            global.set_reset(false, false, false, false);
142
            reset_cycle = 0;
143
        }
144
    }
145
 
146
    @Override
147
    public void get_output(int cycle, Output output) throws Exception {
148
 
149
    }
150
 
151
    LinkedList<Byte> code_stream;
152
 
153
    int counter;
154
    Random random;
155
 
156
    int finish_cycle;
157
    int reset_cycle;
158
 
159
    AvalonListener      avalon;
160
    GlobalListener      global;
161
    PrefetchListener    prefetch;
162
 
163
    //-------------
164
 
165
    public static void main(String args[]) throws Exception {
166
        TestPrefetchCache test1 = new TestPrefetchCache();
167
 
168
        for(int i=0; i<100; i++) {
169
            test1.go(i);
170
 
171
            System.out.println("Run " + i + " complete.");
172
        }
173
 
174
        System.out.println("[Main] thread end.");
175
    }
176
}

powered by: WebSVN 2.1.0

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