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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [test/] [segment/] [TestPOP_seg_real_v86.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.segment;
28
 
29
import ao486.test.TestUnit;
30
import static ao486.test.TestUnit.run_test;
31
import ao486.test.layers.FlagsLayer;
32
import ao486.test.layers.GeneralRegisterLayer;
33
import ao486.test.layers.HandleModeChangeLayer;
34
import ao486.test.layers.IOLayer;
35
import ao486.test.layers.InstructionLayer;
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 TestPOP_seg_real_v86 extends TestUnit implements Serializable {
46
    public static void main(String args[]) throws Exception {
47
        run_test(TestPOP_seg_real_v86.class);
48
    }
49
 
50
    //--------------------------------------------------------------------------
51
    @Override
52
    public int get_test_count() throws Exception {
53
        return 100;
54
    }
55
 
56
    @Override
57
    public void init() throws Exception {
58
 
59
        random = new Random(354 + index);
60
 
61
        String instruction;
62
        while(true) {
63
            layers.clear();
64
 
65
            should_be_ss = random.nextInt(3) == 0;
66
 
67
            //0-real; 1-v8086; 2-protected
68
            int mode = random.nextInt(2);
69
 
70
            LinkedList<Pair<Long, Long>> prohibited_list = new LinkedList<>();
71
 
72
            InstructionLayer instr = new InstructionLayer(random, prohibited_list);
73
            layers.add(instr);
74
            StackLayer stack = new StackLayer(random, prohibited_list);
75
            layers.add(stack);
76
            layers.add(new OtherLayer((mode >= 1)? OtherLayer.Type.PROTECTED_OR_V8086 : OtherLayer.Type.REAL, random));
77
            layers.add(new FlagsLayer((mode == 1)? FlagsLayer.Type.V8086 : (mode == 2)? FlagsLayer.Type.NOT_V8086 : FlagsLayer.Type.RANDOM, random));
78
            layers.add(new GeneralRegisterLayer(random));
79
            layers.add(new SegmentLayer(random));
80
            layers.add(new MemoryLayer(random));
81
            layers.add(new IOLayer(random));
82
            layers.addFirst(new HandleModeChangeLayer(
83
                    getInput("cr0_pe"),
84
                    getInput("vmflag"),
85
                    getInput("cs_rpl"),
86
                    getInput("cs_p"),
87
                    getInput("cs_s"),
88
                    getInput("cs_type")
89
            ));
90
 
91
            // instruction size
92
            boolean cs_d_b = getInput("cs_d_b") == 1;
93
            long    cs_rpl = getInput("cs_rpl");
94
 
95
            boolean a32 = random.nextBoolean();
96
            boolean o32 = random.nextBoolean();
97
 
98
            long selector = random.nextInt(65536);
99
 
100
System.out.printf("selector: %x\n", selector);
101
 
102
            stack.push_word((int)selector);
103
            stack.push_word((int)selector);
104
 
105
            // instruction
106
            instruction = prepare_instr(cs_d_b, a32, o32);
107
 
108
            instruction += instruction;
109
            instruction += "0F0F";
110
 
111
            // add instruction
112
            instr.add_instruction(instruction);
113
 
114
            // end condition
115
            break;
116
        }
117
 
118
        System.out.println("Instruction: [" + instruction + "]");
119
    }
120
 
121
    String prepare_instr(boolean cs_d_b, boolean a32, boolean o32) throws Exception {
122
 
123
        int opcodes[] = {
124
            0x07,0x17,0x1F,0xA1,0xA9
125
        };
126
 
127
        String prefix = "";
128
        if(cs_d_b != o32) { prefix = "66" + prefix; }
129
        if(cs_d_b != a32) { prefix = "67" + prefix; }
130
 
131
        int opcode = opcodes[random.nextInt(opcodes.length)];
132
 
133
        if(should_be_ss) opcode = 0x17;
134
 
135
        byte instr[] = new byte[1];
136
        instr[0] = (byte)opcode;
137
 
138
        return prefix + ((opcode == 0xA1 || opcode == 0xA9)? "0F" : "") + bytesToHex(instr);
139
    }
140
 
141
    boolean should_be_ss;
142
}

powered by: WebSVN 2.1.0

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