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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [test/] [TestRandom.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.test;
28
 
29
import static ao486.test.TestUnit.run_test;
30
import ao486.test.layers.FlagsLayer;
31
import ao486.test.layers.GeneralRegisterLayer;
32
import ao486.test.layers.HandleModeChangeLayer;
33
import ao486.test.layers.IOLayer;
34
import ao486.test.layers.InstructionLayer;
35
import ao486.test.layers.Layer;
36
import ao486.test.layers.MemoryLayer;
37
import ao486.test.layers.OtherLayer;
38
import ao486.test.layers.Pair;
39
import ao486.test.layers.SegmentLayer;
40
import ao486.test.layers.StackLayer;
41
import java.io.Serializable;
42
import java.util.LinkedList;
43
import java.util.Random;
44
 
45
public class TestRandom extends TestUnit implements Serializable {
46
    public static void main(String args[]) throws Exception {
47
        run_test(TestRandom.class);
48
    }
49
 
50
    //--------------------------------------------------------------------------
51
    @Override
52
    public int get_test_count() throws Exception {
53
        return 5000;
54
    }
55
 
56
    @Override
57
    public void init() throws Exception {
58
 
59
        random = new Random(4+index);
60
 
61
        String instruction;
62
        while(true) {
63
            layers.clear();
64
 
65
            LinkedList<Pair<Long, Long>> prohibited_list = new LinkedList<>();
66
 
67
            InstructionLayer instr = new InstructionLayer(random, prohibited_list);
68
            layers.add(instr);
69
            layers.add(new StackLayer(random, prohibited_list));
70
            layers.add(new OtherLayer(OtherLayer.Type.RANDOM, random));
71
            layers.add(new FlagsLayer(FlagsLayer.Type.RANDOM, random));
72
            layers.add(new GeneralRegisterLayer(random));
73
            layers.add(new SegmentLayer(random));
74
            layers.add(new MemoryLayer(random));
75
            layers.add(new IOLayer(random));
76
            layers.addFirst(new HandleModeChangeLayer(
77
                    getInput("cr0_pe"),
78
                    getInput("vmflag"),
79
                    getInput("cs_rpl"),
80
                    getInput("cs_p"),
81
                    getInput("cs_s"),
82
                    getInput("cs_type")
83
            ));
84
 
85
            Layer debug_layer = new Layer() {
86
                long get_test_type() { return 4; }
87
            };
88
            layers.addFirst(debug_layer);
89
 
90
            // instruction size
91
            boolean cs_d_b = getInput("cs_d_b") == 1;
92
 
93
            boolean a32 = random.nextBoolean();
94
            boolean o32 = random.nextBoolean();
95
 
96
            // instruction
97
            instruction = prepare_instr(cs_d_b, a32, o32, null);
98
 
99
            instruction += "0F0F";
100
 
101
            // add instruction
102
            instr.add_instruction(instruction);
103
 
104
            // end condition
105
            break;
106
        }
107
 
108
        System.out.println("Instruction: [" + instruction + "]");
109
    }
110
 
111
    String prepare_instr(boolean cs_d_b, boolean a32, boolean o32, byte modregrm_bytes[]) throws Exception {
112
 
113
        String prefix = "";
114
        if(cs_d_b != o32) { prefix = "66" + prefix; }
115
        if(cs_d_b != a32) { prefix = "67" + prefix; }
116
 
117
        byte instr[] = new byte[512];
118
        random.nextBytes(instr);
119
 
120
        return prefix + bytesToHex(instr);
121
   }
122
}

powered by: WebSVN 2.1.0

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