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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [ao486_tool/] [src/] [ao486/] [test/] [arithmetic_logic/] [TestMUL.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.arithmetic_logic;
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.Serializable;
41
import java.util.LinkedList;
42
import java.util.Random;
43
 
44
public class TestMUL extends TestUnit implements Serializable {
45
    public static void main(String args[]) throws Exception {
46
        run_test(TestMUL.class);
47
    }
48
 
49
    //--------------------------------------------------------------------------
50
    @Override
51
    public int get_test_count() throws Exception {
52
        return 100;
53
    }
54
 
55
    @Override
56
    public void init() throws Exception {
57
 
58
        random = new Random(3+index);
59
 
60
        String instruction;
61
        while(true) {
62
            layers.clear();
63
 
64
            LinkedList<Pair<Long, Long>> prohibited_list = new LinkedList<>();
65
 
66
            InstructionLayer instr = new InstructionLayer(random, prohibited_list);
67
            layers.add(instr);
68
            layers.add(new StackLayer(random, prohibited_list));
69
            layers.add(new OtherLayer(OtherLayer.Type.RANDOM, random));
70
            layers.add(new FlagsLayer(FlagsLayer.Type.RANDOM, random));
71
            layers.add(new GeneralRegisterLayer(random));
72
            layers.add(new SegmentLayer(random));
73
            layers.add(new MemoryLayer(random));
74
            layers.add(new IOLayer(random));
75
            layers.addFirst(new HandleModeChangeLayer(
76
                    getInput("cr0_pe"),
77
                    getInput("vmflag"),
78
                    getInput("cs_rpl"),
79
                    getInput("cs_p"),
80
                    getInput("cs_s"),
81
                    getInput("cs_type")
82
            ));
83
 
84
            // instruction size
85
            boolean cs_d_b = getInput("cs_d_b") == 1;
86
 
87
            boolean a32 = random.nextBoolean();
88
            boolean o32 = random.nextBoolean();
89
 
90
            // instruction
91
            instruction = prepare_instr(cs_d_b, a32, o32, null);
92
 
93
            instruction += "0F0F";
94
 
95
            // add instruction
96
            instr.add_instruction(instruction);
97
 
98
            // end condition
99
            break;
100
        }
101
 
102
        System.out.println("Instruction: [" + instruction + "]");
103
    }
104
 
105
    String prepare_instr(boolean cs_d_b, boolean a32, boolean o32, byte modregrm_bytes[]) throws Exception {
106
        int opcodes[] = {
107
            0xF6,0xF7
108
        };
109
 
110
        String prefix = "";
111
        if(cs_d_b != o32) { prefix = "66" + prefix; }
112
        if(cs_d_b != a32) { prefix = "67" + prefix; }
113
 
114
        int     opcode      = opcodes[random.nextInt(opcodes.length)];
115
        boolean is_modregrm = true;
116
 
117
        byte possible_modregrm = (byte)random.nextInt();
118
        possible_modregrm &= 0xC7; possible_modregrm |= (4 << 3); // reg in modregrm = 5
119
        byte possible_sib      = (byte)random.nextInt();
120
 
121
        int len = (is_modregrm == false)? 1 : 1 + modregrm_len(!a32, unsigned(possible_modregrm), unsigned(possible_sib));
122
System.out.println("[len final: " + len + "]");
123
 
124
        byte instr[] = new byte[len];
125
        instr[0] = (byte)opcode;
126
        for(int i=1; i<len; i++) {
127
            if(i==1)        instr[1] = possible_modregrm;
128
            else if(i==2)   instr[2] = possible_sib;
129
            else            instr[i] = (byte)random.nextInt();
130
        }
131
 
132
        return prefix + bytesToHex(instr);
133
   }
134
}

powered by: WebSVN 2.1.0

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