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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [test/] [io/] [TestOUT_real.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.io;
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.MemoryLayer;
36
import ao486.test.layers.OtherLayer;
37
import ao486.test.layers.Pair;
38
import ao486.test.layers.SegmentLayer;
39
import ao486.test.layers.StackLayer;
40
import java.io.*;
41
import java.util.LinkedList;
42
import java.util.Random;
43
 
44
 
45
public class TestOUT_real extends TestUnit implements Serializable {
46
    public static void main(String args[]) throws Exception {
47
        run_test(TestOUT_real.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(100 + index);
60
 
61
        String instruction;
62
        while(true) {
63
            layers.clear();
64
 
65
            LinkedList<Pair<Long, Long>> prohibited_list = new LinkedList<>();
66
 
67
            // if false: v8086 mode
68
            boolean is_real = true;
69
 
70
            InstructionLayer instr  = new InstructionLayer(random, prohibited_list, true);
71
            layers.add(instr);
72
            StackLayer stack        = new StackLayer(random, prohibited_list);
73
            layers.add(stack);
74
            layers.add(new OtherLayer(is_real ? OtherLayer.Type.REAL : OtherLayer.Type.PROTECTED_OR_V8086, random));
75
            layers.add(new FlagsLayer(is_real ? FlagsLayer.Type.RANDOM : FlagsLayer.Type.V8086, random));
76
            layers.add(new GeneralRegisterLayer(random));
77
            layers.add(new SegmentLayer(random));
78
            layers.add(new MemoryLayer(random));
79
            layers.add(new IOLayer(random));
80
            layers.addFirst(new HandleModeChangeLayer(
81
                    getInput("cr0_pe"),
82
                    getInput("vmflag"),
83
                    getInput("cs_rpl"),
84
                    getInput("cs_p"),
85
                    getInput("cs_s"),
86
                    getInput("cs_type")
87
            ));
88
 
89
            // instruction size
90
            boolean cs_d_b = getInput("cs_d_b") == 1;
91
 
92
            boolean a32 = random.nextBoolean();
93
            boolean o32 = random.nextBoolean();
94
 
95
            long cs_limit = getInput("cs_limit");
96
 
97
 
98
            String instruction_string = prepare_instr(cs_d_b, a32, o32);
99
 
100
            // add instruction
101
            instruction = instruction_string + instruction_string + "9090900F0F";
102
 
103
            instr.add_instruction(instruction);
104
 
105
            // end condition
106
            break;
107
        }
108
 
109
        System.out.println("Instruction: [" + instruction + "]");
110
    }
111
    String prepare_instr(boolean cs_d_b, boolean a32, boolean o32) throws Exception {
112
        int opcodes[] = {
113
            0xE6,0xE7,0xEE,0xEF
114
        };
115
 
116
        String prefix = "";
117
        if(cs_d_b != o32) { prefix = "66" + prefix; }
118
        if(cs_d_b != a32) { prefix = "67" + prefix; }
119
 
120
        int opcode = opcodes[random.nextInt(opcodes.length)];
121
 
122
        int len = (opcode == 0xE6 || opcode == 0xE7)? 2 : 1;
123
 
124
        byte instr[] = new byte[len];
125
        instr[0] = (byte)opcode;
126
        if(len >= 2) instr[1] = (byte)random.nextInt();
127
 
128
        return prefix + bytesToHex(instr);
129
    }
130
}

powered by: WebSVN 2.1.0

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