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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [test/] [other/] [TestMOV_DRx_store.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.other;
28
 
29
import ao486.test.TestUnit;
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.*;
42
import java.util.LinkedList;
43
import java.util.Random;
44
 
45
 
46
public class TestMOV_DRx_store extends TestUnit implements Serializable {
47
    public static void main(String args[]) throws Exception {
48
        run_test(TestMOV_DRx_store.class);
49
    }
50
 
51
    //--------------------------------------------------------------------------
52
    @Override
53
    public int get_test_count() throws Exception {
54
        return 100;
55
    }
56
 
57
    @Override
58
    public void init() throws Exception {
59
 
60
        random = new Random(5 + index);
61
 
62
        String instruction;
63
        while(true) {
64
            layers.clear();
65
 
66
            /* 0 - CPL != 0
67
             * 1 - dr7.gd = 1
68
             * 2 - all ok
69
             */
70
            int type = random.nextInt(3);
71
 
72
            LinkedList<Pair<Long, Long>> prohibited_list = new LinkedList<>();
73
 
74
            // if false: v8086 mode
75
            boolean is_real = (type == 0 || type == 1)? false : random.nextBoolean();
76
 
77
            InstructionLayer instr  = new InstructionLayer(random, prohibited_list);
78
            layers.add(instr);
79
            StackLayer stack        = new StackLayer(random, prohibited_list);
80
            layers.add(stack);
81
            layers.add(new OtherLayer(is_real ? OtherLayer.Type.REAL : OtherLayer.Type.PROTECTED_OR_V8086, random));
82
            layers.add(new FlagsLayer(FlagsLayer.Type.RANDOM, random));
83
            layers.add(new GeneralRegisterLayer(random));
84
            layers.add(new SegmentLayer(random));
85
            layers.add(new MemoryLayer(random));
86
            layers.add(new IOLayer(random));
87
            layers.addFirst(new HandleModeChangeLayer(
88
                    getInput("cr0_pe"),
89
                    getInput("vmflag"),
90
                    getInput("cs_rpl"),
91
                    getInput("cs_p"),
92
                    getInput("cs_s"),
93
                    getInput("cs_type")
94
            ));
95
 
96
            // instruction size
97
            boolean cs_d_b = getInput("cs_d_b") == 1;
98
            boolean vmflag = getInput("vmflag") == 1;
99
 
100
            boolean a32 = random.nextBoolean();
101
            boolean o32 = random.nextBoolean();
102
 
103
            if(type == 0) {
104
                final int cs_rpl = (vmflag)? 3 : 1 + random.nextInt(3);
105
                Layer cs_rpl_layer = new Layer() {
106
                    long cs_rpl() { return cs_rpl; }
107
                };
108
                layers.addFirst(cs_rpl_layer);
109
            }
110
 
111
            if(type == 1) {
112
 
113
                final int dr7 = random.nextInt() | 0x00002000;
114
                final int cs_rpl = (vmflag)? 3 : random.nextInt(4);
115
                Layer cs_rpl_layer = new Layer() {
116
                    long cs_rpl()   { return cs_rpl; }
117
 
118
                    long dr7()      { return dr7; }
119
 
120
                    long rflag()    { return 0; }
121
                };
122
                layers.addFirst(cs_rpl_layer);
123
            }
124
 
125
            int cr_reg = random.nextInt(8);
126
 
127
            int cr_mod = random.nextInt(4);
128
            int cr_rm  = random.nextInt(8);
129
 
130
            // instruction
131
            byte modregrm_byte = (byte)((cr_mod << 6) | (cr_reg << 3) | (cr_rm));
132
 
133
            instruction = prepare_instr(cs_d_b, a32, o32, modregrm_byte);
134
 
135
            instruction += instruction;
136
            instruction += "0F0F";
137
 
138
            // add instruction
139
            instr.add_instruction(instruction);
140
 
141
            // end condition
142
            break;
143
        }
144
 
145
        System.out.println("Instruction: [" + instruction + "]");
146
    }
147
 
148
    String prepare_instr(boolean cs_d_b, boolean a32, boolean o32, byte modregrm_byte) throws Exception {
149
        int opcodes[] = {
150
            0x21
151
        };
152
 
153
        String prefix = "";
154
        if(cs_d_b != o32) { prefix = "66" + prefix; }
155
        if(cs_d_b != a32) { prefix = "67" + prefix; }
156
 
157
        prefix += "0F";
158
        int opcode = opcodes[random.nextInt(opcodes.length)];
159
 
160
        byte instr[] = new byte[1 + 1];
161
        instr[0] = (byte)opcode;
162
        instr[1] = modregrm_byte;
163
 
164
        return prefix + bytesToHex(instr);
165
    }
166
}

powered by: WebSVN 2.1.0

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