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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [test/] [transfer_data/] [TestMOVSX_MOVZX.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.transfer_data;
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 TestMOVSX_MOVZX extends TestUnit implements Serializable {
46
    public static void main(String args[]) throws Exception {
47
        run_test(TestMOVSX_MOVZX.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
        random = new Random(5 + index);
59
 
60
        long rpl = random.nextInt(4);
61
 
62
        String instruction;
63
        while(true) {
64
            layers.clear();
65
 
66
            LinkedList<Pair<Long, Long>> prohibited_list = new LinkedList<>();
67
 
68
            InstructionLayer instr = new InstructionLayer(random, prohibited_list);
69
            layers.add(instr);
70
            layers.add(new StackLayer(random, prohibited_list));
71
            layers.add(new OtherLayer(OtherLayer.Type.RANDOM, random));
72
            layers.add(new FlagsLayer(FlagsLayer.Type.RANDOM, random));
73
            layers.add(new GeneralRegisterLayer(random));
74
            layers.add(new SegmentLayer(random));
75
            layers.add(new MemoryLayer(random));
76
            layers.add(new IOLayer(random));
77
            layers.addFirst(new HandleModeChangeLayer(
78
                    getInput("cr0_pe"),
79
                    getInput("vmflag"),
80
                    rpl, //getInput("cs_rpl"),
81
                    getInput("cs_p"),
82
                    getInput("cs_s"),
83
                    getInput("cs_type")
84
            ));
85
 
86
            // instruction size
87
            boolean cs_d_b = getInput("cs_d_b") == 1;
88
 
89
            boolean a32 = random.nextBoolean();
90
            boolean o32 = random.nextBoolean();
91
 
92
            // instruction
93
            instruction = prepare_instr(cs_d_b, a32, o32, null);
94
 
95
            instruction += instruction;
96
            instruction += "0F0F";
97
 
98
            // add instruction
99
            instr.add_instruction(instruction);
100
 
101
            // end condition
102
            break;
103
        }
104
 
105
        System.out.println("Instruction: [" + instruction + "]");
106
    }
107
 
108
    String prepare_instr(boolean cs_d_b, boolean a32, boolean o32, byte modregrm_bytes[]) throws Exception {
109
 
110
        int opcodes[] = {
111
            0xB6,0xB7,0xBE,0xBF
112
        };
113
 
114
        String prefix = "";
115
        if(cs_d_b != o32) { prefix = "66" + prefix; }
116
        if(cs_d_b != a32) { prefix = "67" + prefix; }
117
 
118
        int     opcode      = opcodes[random.nextInt(opcodes.length)];
119
        boolean is_modregrm = true;
120
 
121
        byte possible_modregrm = (byte)random.nextInt();
122
        byte possible_sib      = (byte)random.nextInt();
123
 
124
        int len = (is_modregrm == false)? 1 : 1 + modregrm_len(!a32, unsigned(possible_modregrm), unsigned(possible_sib));
125
 
126
        byte instr[] = new byte[len];
127
        instr[0] = (byte)opcode;
128
        for(int i=1; i<len; i++) {
129
            if(i==1)        instr[1] = possible_modregrm;
130
            else if(i==2)   instr[2] = possible_sib;
131
            else            instr[i] = (byte)random.nextInt();
132
        }
133
        return prefix + "0F" + bytesToHex(instr);
134
    }
135
}
136
 
137
 
138
/*
139
class TestMOVSX_MOVZXSerializable extends TestBase implements Test, Serializable {
140
    TestMOVSX_MOVZXSerializable() {
141
        random = new Random(0);
142
    }
143
 
144
    Random random;
145
    int index;
146
 
147
    boolean d_b;
148
 
149
    //--------------------------------------------------------------------------
150
    @Override
151
    public int get_test_count() throws Exception {
152
        return 2000;
153
    }
154
 
155
    @Override
156
    public void init() throws Exception {
157
        d_b = random.nextBoolean();
158
    }
159
 
160
    @Override
161
    public boolean fini() throws Exception {
162
        return index < get_test_count();
163
    }
164
 
165
    int imm_len(boolean o16, int opcode) {
166
        return 0;
167
    }
168
    String prepare_instr() throws Exception {
169
        int opcodes[] = {
170
            0xB6,0xB7,0xBE,0xBF
171
        };
172
 
173
        boolean a16 = !d_b;
174
        boolean o16 = !d_b;
175
        String prefix = "";
176
        if(random.nextBoolean()) { prefix = "66" + prefix; o16 = !o16; }
177
        if(random.nextBoolean()) { prefix = "67" + prefix; a16 = !a16; }
178
 
179
        int opcode = opcodes[random.nextInt(opcodes.length)];
180
        boolean is_modregrm = true;
181
 
182
        byte possible_modregrm = (byte)random.nextInt();
183
        byte possible_sib      = (byte)random.nextInt();
184
 
185
        int len = (is_modregrm == false)? 1 : 1 + modregrm_len(a16, unsigned(possible_modregrm), unsigned(possible_sib));
186
System.out.printf("[len: %d, d_b: %b, modregrm: %02x, sib: %02x]\n", len, d_b, unsigned(possible_modregrm), unsigned(possible_sib));
187
        //len += imm_len(o16, opcode);
188
//System.out.println("[len final: " + len + "]");
189
 
190
        byte instr[] = new byte[len];
191
        instr[0] = (byte)opcode;
192
        for(int i=1; i<len; i++) {
193
            if(i==1)        instr[1] = possible_modregrm;
194
            else if(i==2)   instr[2] = possible_sib;
195
            else            instr[i] = (byte)random.nextInt();
196
        }
197
 
198
        return prefix + "0F" + bytesToHex(instr);
199
    }
200
 
201
    public String get_instructions() throws Exception {
202
        String instr = "";
203
 
204
        while(instr.length() < 2*15) {
205
            instr += prepare_instr();
206
        }
207
        instr = instr.substring(0, 2*15);
208
 
209
System.out.println("[get_instructions: " + instr + "]");
210
        return instr;
211
    }
212
    @Override
213
    public byte get_memory(int address) throws Exception {
214
        return (byte)random.nextInt();
215
    }
216
    @Override
217
    public int eax() throws Exception {
218
        return random.nextInt() & ((random.nextInt(3) == 0)? 0xFFFFFFFF : 0x00000FFF);
219
    }
220
    @Override
221
    public int get_ebx() throws Exception {
222
        return random.nextInt() & ((random.nextInt(3) == 0)? 0xFFFFFFFF : 0x00000FFF);
223
    }
224
    @Override
225
    public int get_ecx() throws Exception {
226
        return random.nextInt() & ((random.nextInt(3) == 0)? 0xFFFFFFFF : 0x00000FFF);
227
    }
228
    @Override
229
    public int get_edx() throws Exception {
230
        return random.nextInt() & ((random.nextInt(3) == 0)? 0xFFFFFFFF : 0x00000FFF);
231
    }
232
    @Override
233
    public int get_esi() throws Exception {
234
        return random.nextInt() & ((random.nextInt(3) == 0)? 0xFFFFFFFF : 0x00000FFF);
235
    }
236
    @Override
237
    public int get_edi() throws Exception {
238
        return random.nextInt() & ((random.nextInt(3) == 0)? 0xFFFFFFFF : 0x00000FFF);
239
    }
240
    @Override
241
    public int get_ebp() throws Exception {
242
        return random.nextInt() & ((random.nextInt(3) == 0)? 0xFFFFFFFF : 0x00000FFF);
243
    }
244
    @Override
245
    public int get_esp() throws Exception {
246
        return random.nextInt() & ((random.nextInt(3) == 0)? 0xFFFFFFFF : 0x00000FFF);
247
    }
248
    @Override
249
    public boolean get_cf() throws Exception {
250
        return random.nextBoolean();
251
    }
252
    @Override
253
    public boolean get_pf() throws Exception {
254
        return random.nextBoolean();
255
    }
256
    @Override
257
    public boolean get_af() throws Exception {
258
        return random.nextBoolean();
259
    }
260
    @Override
261
    public boolean get_zf() throws Exception {
262
        return random.nextBoolean();
263
    }
264
    @Override
265
    public boolean get_sf() throws Exception {
266
        return random.nextBoolean();
267
    }
268
    @Override
269
    public boolean get_tf() throws Exception {
270
        return random.nextBoolean();
271
    }
272
    @Override
273
    public boolean get_if() throws Exception {
274
        return random.nextBoolean();
275
    }
276
    @Override
277
    public boolean get_df() throws Exception {
278
        return random.nextBoolean();
279
    }
280
    @Override
281
    public boolean get_of() throws Exception {
282
        return random.nextBoolean();
283
    }
284
    @Override
285
    public int get_iopl() throws Exception {
286
        return random.nextInt(4);
287
    }
288
    @Override
289
    public boolean get_nt() throws Exception {
290
        return random.nextBoolean();
291
    }
292
    @Override
293
    public boolean get_rf() throws Exception {
294
        return random.nextBoolean();
295
    }
296
    @Override
297
    public boolean get_vm() throws Exception {
298
        return random.nextBoolean();
299
    }
300
    @Override
301
    public boolean get_ac() throws Exception {
302
        return random.nextBoolean();
303
    }
304
    @Override
305
    public boolean get_id() throws Exception {
306
        return random.nextBoolean();
307
    }
308
    @Override
309
    public int get_cs_base() throws Exception {
310
        return 0;
311
    }
312
    @Override
313
    public int get_cs_limit() throws Exception {
314
        return 0x000FFFFF;
315
    }
316
    @Override
317
    public boolean get_cs_d_b() throws Exception {
318
        return d_b;
319
    }
320
    @Override
321
    public int get_ds_base() throws Exception {
322
        return 0;
323
    }
324
    @Override
325
    public int get_ds_limit() throws Exception {
326
        return 0x000FFFFF;
327
    }
328
    @Override
329
    public int get_es_base() throws Exception {
330
        return 0;
331
    }
332
    @Override
333
    public int get_es_limit() throws Exception {
334
        return 0x000FFFFF;
335
    }
336
    @Override
337
    public int get_fs_base() throws Exception {
338
        return 0;
339
    }
340
    @Override
341
    public int get_fs_limit() throws Exception {
342
        return 0x000FFFFF;
343
    }
344
    @Override
345
    public int get_gs_base() throws Exception {
346
        return 0;
347
    }
348
    @Override
349
    public int get_gs_limit() throws Exception {
350
        return 0x000FFFFF;
351
    }
352
    @Override
353
    public int get_ss_base() throws Exception {
354
        return 0;
355
    }
356
    @Override
357
    public int get_ss_limit() throws Exception {
358
        return 0x000FFFFF;
359
    }
360
}
361
*/

powered by: WebSVN 2.1.0

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