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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [test/] [debug/] [Test_execute.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.debug;
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.MemoryPatchLayer;
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.*;
43
import java.util.LinkedList;
44
import java.util.Random;
45
 
46
 
47
public class Test_execute extends TestUnit implements Serializable {
48
    public static void main(String args[]) throws Exception {
49
        run_test(Test_execute.class);
50
    }
51
 
52
    //--------------------------------------------------------------------------
53
    @Override
54
    public int get_test_count() throws Exception {
55
        return 1;
56
    }
57
 
58
    int type;
59
 
60
    @Override
61
    public void init() throws Exception {
62
 
63
        random = new Random(0 + index);
64
 
65
        String instruction;
66
        while(true) {
67
            layers.clear();
68
 
69
            /* 0 -
70
             */
71
 
72
            type = 0;
73
 
74
            LinkedList<Pair<Long, Long>> prohibited_list = new LinkedList<>();
75
 
76
            // if false: v8086 mode
77
            boolean is_real = true;
78
 
79
            InstructionLayer instr  = new InstructionLayer(random, prohibited_list, true);
80
            layers.add(instr);
81
            StackLayer stack        = new StackLayer(random, prohibited_list);
82
            layers.add(stack);
83
            layers.add(new OtherLayer(is_real ? OtherLayer.Type.REAL : OtherLayer.Type.PROTECTED_OR_V8086, random));
84
            layers.add(new FlagsLayer(FlagsLayer.Type.RANDOM, random));
85
            layers.add(new GeneralRegisterLayer(random));
86
            layers.add(new SegmentLayer(random));
87
            layers.add(new MemoryLayer(random));
88
            layers.add(new IOLayer(random));
89
            layers.addFirst(new HandleModeChangeLayer(
90
                    getInput("cr0_pe"),
91
                    getInput("vmflag"),
92
                    getInput("cs_rpl"),
93
                    getInput("cs_p"),
94
                    getInput("cs_s"),
95
                    getInput("cs_type")
96
            ));
97
 
98
            // instruction size
99
            boolean cs_d_b = getInput("cs_d_b") == 1;
100
            boolean vmflag = getInput("vmflag") == 1;
101
 
102
            long cs_limit = getInput("cs_limit");
103
            long cs_base  = getInput("cs_base");
104
            long eip  = getInput("eip");
105
 
106
            long current_linear_code = cs_base + eip;
107
 
108
            boolean a32 = random.nextBoolean();
109
            boolean o32 = true;
110
 
111
            final boolean iflag = (type == -1)? true : random.nextBoolean();
112
            final int dr3 = (int)current_linear_code + 6;
113
            Layer debug_layer = new Layer() {
114
 
115
                long rflag()    { return 0; }
116
                long tflag()    { return 0; }
117
                long iflag()    { return iflag? 1 : 0; }
118
 
119
                long edx()       { return 0x00000040; } // LEN3 = 1 byte(00); RW3 = execute(00)
120
 
121
                long dr3()       { return dr3; }
122
 
123
                long get_test_type() { return 18; }
124
 
125
                long check_interrupt(long counter) { return (type == -1 && (counter == 6))?  0xAB : 0x100; }
126
            };
127
            layers.addFirst(debug_layer);
128
 
129
            long handler = cs_limit;
130
 
131
            //debug vector = 0x01*4 = 0x04 linear
132
            MemoryPatchLayer int_patch = new MemoryPatchLayer(random, prohibited_list, (int)(0x01*4), (byte)(handler&0xFF),(byte)((handler>>8)&0xFF), 0x00,0x00);
133
            layers.addFirst(int_patch);
134
 
135
            //interrupt handler: simply IRET
136
            MemoryPatchLayer handler_patch = new MemoryPatchLayer(random, prohibited_list, (int)handler, 0xCF);
137
            layers.addFirst(handler_patch);
138
 
139
            String prefix = "";
140
            if(cs_d_b != o32) { prefix = "66" + prefix; }
141
 
142
            instruction = "";
143
            if(type == 0) {
144
                // MOV to DR from edx; DAA(to increment eip)
145
                instruction = prefix + "0F23FA" + "2727272727" + "90909090909090909090909090909090909090900F0F";
146
            }
147
 
148
 
149
            // add instruction
150
            instr.add_instruction(instruction);
151
 
152
            // end condition
153
            break;
154
        }
155
 
156
        System.out.println("Instruction: [" + instruction + "]");
157
    }
158
 
159
}

powered by: WebSVN 2.1.0

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