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

Subversion Repositories ao486

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

powered by: WebSVN 2.1.0

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