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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [test/] [debug/] [Test_write.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_write extends TestUnit implements Serializable {
48
    public static void main(String args[]) throws Exception {
49
        run_test(Test_write.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(1 + index);
64
 
65
        String instruction;
66
        while(true) {
67
            layers.clear();
68
 
69
            /* 0 - REP STOS write breakpoint
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
            if(cs_d_b == true) continue;
101
 
102
            boolean vmflag = getInput("vmflag") == 1;
103
 
104
            long cs_limit = getInput("cs_limit");
105
            long cs_base  = getInput("cs_base");
106
 
107
            boolean a32 = random.nextBoolean();
108
            boolean o32 = true;
109
 
110
            final boolean iflag = (type == -1)? true : random.nextBoolean();
111
            final int ecx = (type == 0)? 4 : random.nextInt();
112
            Layer debug_layer = new Layer() {
113
 
114
                long rflag()    { return 0; }
115
                long tflag()    { return 0; }
116
                long iflag()    { return iflag? 1 : 0; }
117
                long ecx()      { return ecx; }
118
                long edx()      { return 0x10000040; } // LEN3 = 1 byte(00); RW3 = write only(01)
119
 
120
                long dflag()    { return 0; }
121
                long es_base()  { return 0; }
122
                long edi()      { return 0; }
123
                long dr3()      { return 3; }
124
 
125
                long check_interrupt(long counter) { return (type == -1 && (counter == 6))?  0xAB : 0x100; }
126
                long get_test_type() { return 18; }
127
            };
128
            layers.addFirst(debug_layer);
129
 
130
            long handler = cs_limit;
131
 
132
            //debug vector = 0x01*4 = 0x04 linear
133
            MemoryPatchLayer int_patch = new MemoryPatchLayer(random, prohibited_list, (int)(0x01*4), (byte)(handler&0xFF),(byte)((handler>>8)&0xFF), 0x00,0x00);
134
            layers.addFirst(int_patch);
135
 
136
            //interrupt handler: simply IRET
137
            MemoryPatchLayer handler_patch = new MemoryPatchLayer(random, prohibited_list, (int)handler, 0xCF);
138
            layers.addFirst(handler_patch);
139
 
140
 
141
            String prefix = "";
142
            if(cs_d_b != o32) { prefix = "66" + prefix; }
143
 
144
            int eflags_start = 0x00000300; //TF and IF set
145
            int eflags_end   = 0x00000200; //IF set
146
            stack.push_dword(eflags_start);
147
            stack.push_dword(eflags_end);
148
 
149
            instruction = "";
150
            if(type == 0) {
151
                // MOV to DR from edx; REP STOSB
152
                instruction = prefix + "0F23FA" + "F3" + "AA" + "90909090909090909090900F0F";
153
            }
154
 
155
            // add instruction
156
            instr.add_instruction(instruction);
157
 
158
            // end condition
159
            break;
160
        }
161
 
162
        System.out.println("Instruction: [" + instruction + "]");
163
    }
164
}

powered by: WebSVN 2.1.0

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