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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [test/] [debug/] [Test_trace.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_trace extends TestUnit implements Serializable {
48
    public static void main(String args[]) throws Exception {
49
        run_test(Test_trace.class);
50
    }
51
 
52
    //--------------------------------------------------------------------------
53
    @Override
54
    public int get_test_count() throws Exception {
55
        return 100;
56
    }
57
 
58
    int type;
59
 
60
    @Override
61
    public void init() throws Exception {
62
 
63
        random = new Random(8 + index);
64
 
65
        String instruction;
66
        while(true) {
67
            layers.clear();
68
 
69
            /* 0 - tf enable; some instructions; disable tf
70
             * 1 - tf enable; some instructions with inhibit; disable tf
71
             * 2 - like 0 but enable interrupts
72
             * 3 - tf enabled; REP LODS; disable tf
73
             * 4 - tf enable; HLT; interrupt with debug; disable tf
74
             */
75
 
76
            type = random.nextInt(5);
77
 
78
            LinkedList<Pair<Long, Long>> prohibited_list = new LinkedList<>();
79
 
80
            // if false: v8086 mode
81
            boolean is_real = true;
82
 
83
            InstructionLayer instr  = new InstructionLayer(random, prohibited_list, true);
84
            layers.add(instr);
85
            StackLayer stack        = new StackLayer(random, prohibited_list);
86
            layers.add(stack);
87
            layers.add(new OtherLayer(is_real ? OtherLayer.Type.REAL : OtherLayer.Type.PROTECTED_OR_V8086, random));
88
            layers.add(new FlagsLayer(FlagsLayer.Type.RANDOM, random));
89
            layers.add(new GeneralRegisterLayer(random));
90
            layers.add(new SegmentLayer(random));
91
            layers.add(new MemoryLayer(random));
92
            layers.add(new IOLayer(random));
93
            layers.addFirst(new HandleModeChangeLayer(
94
                    getInput("cr0_pe"),
95
                    getInput("vmflag"),
96
                    getInput("cs_rpl"),
97
                    getInput("cs_p"),
98
                    getInput("cs_s"),
99
                    getInput("cs_type")
100
            ));
101
 
102
            // instruction size
103
            boolean cs_d_b = getInput("cs_d_b") == 1;
104
            if(cs_d_b == true) continue;
105
 
106
            boolean vmflag = getInput("vmflag") == 1;
107
 
108
            long cs_limit = getInput("cs_limit");
109
            long cs_base  = getInput("cs_base");
110
 
111
            boolean a32 = random.nextBoolean();
112
            boolean o32 = true;
113
 
114
            final boolean iflag = (type == 2)? true : random.nextBoolean();
115
            final int ecx = (type == 3)? 4 : random.nextInt();
116
            Layer debug_layer = new Layer() {
117
 
118
                long rflag()    { return 0; }
119
                long tflag()    { return 0; }
120
                long iflag()    { return iflag? 1 : 0; }
121
                long ecx()      { return ecx; }
122
 
123
                long check_interrupt(long counter) { return (type == 2 && (counter == 6))? 0xAB : (type == 4 && (counter == 2))? 0xAB : 0x100; }
124
 
125
                long get_test_type() { return 12; }
126
            };
127
            layers.addFirst(debug_layer);
128
 
129
            long handler = cs_limit;
130
 
131
            //0xAB -- interrupt vector = 0xAB*4 = 0x2AC 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
            MemoryPatchLayer interrupt_patch = new MemoryPatchLayer(random, prohibited_list, (int)(0xAB*4), (byte)(handler&0xFF),(byte)((handler>>8)&0xFF), 0x00,0x00);
136
            layers.addFirst(interrupt_patch);
137
 
138
            //interrupt handler: simply IRET
139
            MemoryPatchLayer handler_patch = new MemoryPatchLayer(random, prohibited_list, (int)handler, 0xCF);
140
            layers.addFirst(handler_patch);
141
 
142
            String prefix = "";
143
            if(cs_d_b != o32) { prefix = "66" + prefix; }
144
 
145
            int eflags_start = 0x00000300; //TF and IF set
146
            int eflags_end   = 0x00000200; //IF set
147
            stack.push_dword(eflags_start);
148
            stack.push_dword(eflags_end);
149
 
150
            instruction = "";
151
            if(type == 0 || type == 2) {
152
                // POPF + DAA(don't care) + POPF
153
                instruction = prefix + "9D" + "272727" + "9D" + "90909090909090909090900F0F";
154
            }
155
            else if(type == 1) {
156
                // POPF + DAA(don't care) + POP SS(for inhibit) + POPF
157
                instruction = prefix + "9D" + "27" + "17" + "2727" + "9D" + "90909090909090909090900F0F";
158
            }
159
            else if(type == 3) {
160
                // POPF + LODS + POPF
161
                instruction = prefix + "9D" + "F3" + "AD" + "9D" + "90909090909090909090900F0F";
162
            }
163
            else if(type == 4) {
164
                // POPF + HLT + POPF
165
                instruction = prefix + "9D" + "F4" + "9D" + "90909090909090909090900F0F";
166
            }
167
 
168
            // add instruction
169
            instr.add_instruction(instruction);
170
 
171
            // end condition
172
            break;
173
        }
174
 
175
        System.out.println("Instruction: [" + instruction + "]");
176
    }
177
 
178
}

powered by: WebSVN 2.1.0

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