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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [test/] [segment/] [TestLxS_real_v86.java] - Blame information for rev 7

Go to most recent revision | 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.segment;
28
 
29
import ao486.test.TestUnit;
30
import static ao486.test.TestUnit.run_test;
31
import ao486.test.layers.EffectiveAddressLayerFactory;
32
import ao486.test.layers.FlagsLayer;
33
import ao486.test.layers.GeneralRegisterLayer;
34
import ao486.test.layers.HandleModeChangeLayer;
35
import ao486.test.layers.IOLayer;
36
import ao486.test.layers.InstructionLayer;
37
import ao486.test.layers.MemoryLayer;
38
import ao486.test.layers.OtherLayer;
39
import ao486.test.layers.Pair;
40
import ao486.test.layers.SegmentLayer;
41
import ao486.test.layers.StackLayer;
42
import java.io.Serializable;
43
import java.util.LinkedList;
44
import java.util.Random;
45
 
46
public class TestLxS_real_v86 extends TestUnit implements Serializable {
47
    public static void main(String args[]) throws Exception {
48
        run_test(TestLxS_real_v86.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(2500 + index);
61
 
62
 
63
        String instruction;
64
        while(true) {
65
            layers.clear();
66
 
67
            should_be_ss = random.nextInt(3) == 0;
68
 
69
            //0-real; 1-v8086; 2-protected
70
            int mode = random.nextInt(2);
71
 
72
            LinkedList<Pair<Long, Long>> prohibited_list = new LinkedList<>();
73
 
74
            InstructionLayer instr = new InstructionLayer(random, prohibited_list);
75
            layers.add(instr);
76
            layers.add(new StackLayer(random, prohibited_list));
77
            layers.add(new OtherLayer((mode >= 1)? OtherLayer.Type.PROTECTED_OR_V8086 : OtherLayer.Type.REAL, random));
78
            layers.add(new FlagsLayer((mode == 1)? FlagsLayer.Type.V8086 : (mode == 2)? FlagsLayer.Type.NOT_V8086 : FlagsLayer.Type.RANDOM, random));
79
            layers.add(new GeneralRegisterLayer(random));
80
            layers.add(new SegmentLayer(random));
81
            layers.add(new MemoryLayer(random));
82
            layers.add(new IOLayer(random));
83
            layers.addFirst(new HandleModeChangeLayer(
84
                    getInput("cr0_pe"),
85
                    getInput("vmflag"),
86
                    getInput("cs_rpl"),
87
                    getInput("cs_p"),
88
                    getInput("cs_s"),
89
                    getInput("cs_type")
90
            ));
91
 
92
            // instruction size
93
            boolean cs_d_b = getInput("cs_d_b") == 1;
94
            long    cs_rpl = getInput("cs_rpl");
95
 
96
            boolean a32 = random.nextBoolean();
97
            boolean o32 = random.nextBoolean();
98
 
99
            long selector = random.nextInt(65536);
100
 
101
            byte extra_bytes[] = null;
102
 
103
            if(o32) {
104
                selector <<= 32;
105
                selector |= random.nextInt() & 0xFFFFFFFFL;
106
            }
107
            else {
108
                selector <<= 16;
109
                selector |= random.nextInt() & 0xFFFFL;
110
            }
111
System.out.printf("selector: %x\n", selector);
112
            byte modregrm_bytes[] = EffectiveAddressLayerFactory.prepare(
113
                    selector,
114
                    0, EffectiveAddressLayerFactory.modregrm_reg_t.RANDOM,
115
                    (o32)? 6 : 4, a32,
116
                    layers, random, this, true, false);
117
            extra_bytes = modregrm_bytes;
118
 
119
            // instruction
120
            instruction = prepare_instr(cs_d_b, a32, o32, extra_bytes);
121
 
122
            instruction += instruction;
123
            instruction += "0F0F";
124
 
125
            // add instruction
126
            instr.add_instruction(instruction);
127
 
128
            // end condition
129
            break;
130
        }
131
 
132
        System.out.println("Instruction: [" + instruction + "]");
133
    }
134
 
135
    String prepare_instr(boolean cs_d_b, boolean a32, boolean o32, byte modregrm_bytes[]) throws Exception {
136
 
137
        int opcodes[] = {
138
            0xB2,0xB4,0xB5,0xC4,0xC5
139
        };
140
 
141
        String prefix = "";
142
        if(cs_d_b != o32) { prefix = "66" + prefix; }
143
        if(cs_d_b != a32) { prefix = "67" + prefix; }
144
 
145
        int opcode = opcodes[random.nextInt(opcodes.length)];
146
 
147
        if(should_be_ss) opcode = 0xB2;
148
 
149
        byte instr[] = new byte[1 + modregrm_bytes.length];
150
        instr[0] = (byte)opcode;
151
        System.arraycopy(modregrm_bytes, 0, instr, 1, modregrm_bytes.length);
152
 
153
        return prefix + ((opcode == 0xB2 || opcode == 0xB4 || opcode == 0xB5)? "0F" : "") + bytesToHex(instr);
154
    }
155
 
156
    boolean should_be_ss;
157
}

powered by: WebSVN 2.1.0

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