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

Subversion Repositories aor3000

[/] [aor3000/] [trunk/] [sim/] [tester/] [test_arithmetic_logic.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/*
2
 * This file is subject to the terms and conditions of the BSD License. See
3
 * the file "LICENSE" in the main directory of this archive for more details.
4
 *
5
 * Copyright (C) 2014 Aleksander Osman
6
 */
7
 
8
#include <cstdio>
9
#include <cstdlib>
10
 
11
#include "tests.h"
12
 
13
//------------------------------------------------------------------------------
14
 
15
void put_instruction(uint32 *ptr, bool &was_mul, bool &was_div) {
16
 
17
    uint32 instr_special[] = {
18
        0b000000, //SSL
19
        0b000010, //SRL
20
        0b000011, //SRA
21
        0b000100, //SLLV
22
        0b000110, //SRLV
23
        0b000111, //SRAV
24
        0b010000, //MFHI
25
        0b010001, //MTHI     i
26
        0b010010, //MFLO
27
        0b010011, //MTLO     i
28
        0b011000, //MULT     i
29
        0b011001, //MULTU    i
30
        0b011010, //DIV
31
        0b011011, //DIVU
32
        0b100000, //ADD      e
33
        0b100001, //ADDU
34
        0b100010, //SUB      e
35
        0b100011, //SUBU
36
        0b100100, //AND
37
        0b100101, //OR
38
        0b100110, //XOR
39
        0b100111, //NOR
40
        0b101010, //SLT
41
        0b101011, //SLTU
42
    };
43
    uint32 instr_imm[] = {
44
        0b001000, //ADDI     e
45
        0b001001, //ADDIU
46
        0b001010, //SLTI
47
        0b001011, //SLTIU
48
        0b001100, //ANDI
49
        0b001101, //ORI
50
        0b001110, //XORI
51
        0b001111, //LUI
52
    };
53
 
54
    while(true) {
55
        uint32 instr = rand() & 0x03FFFFFF;
56
        uint32 count = (sizeof(instr_special) + sizeof(instr_imm)) / sizeof(uint32);
57
        uint32 index = rand() % count;
58
 
59
        //sequences not generated:
60
        //mul* -> mt*; mul* -> div*
61
        //div* -> mt*; div* -> mul*
62
        //mul* and div* finish after mf*
63
 
64
        if(was_div == false && (index == 10 || index == 11)) was_mul = true;
65
        if(was_mul == false && (index == 12 || index == 13)) was_div = true;
66
        if(was_div && (index == 10 || index == 11)) continue;
67
        if(was_mul && (index == 12 || index == 13)) continue;
68
        if((was_div || was_mul) && (index == 7 || index == 9)) continue;
69
        if((index == 6 || index == 8)) was_div = was_mul = false;
70
 
71
        if(index >= (sizeof(instr_special) / sizeof(uint32))) {
72
            index -= (sizeof(instr_special) / sizeof(uint32));
73
            instr |= instr_imm[index] << 26;
74
 
75
            if(index == 7 || index == 9 || index == 10 || index == 11) if((rand() % 3) != 0) instr &= 0xFFFF07FF;
76
        }
77
        else {
78
            instr &= 0xFFFFFFC0;
79
            instr |= instr_special[index];
80
        }
81
        (*ptr) = instr;
82
        break;
83
    }
84
}
85
 
86
void arith_logic_till_exc_init(tst_t *tst, shared_mem_t *shared_ptr) {
87
 
88
    for(int i=1; i<32; i++) shared_ptr->initial.reg[i-1] = rand_uint32();
89
 
90
    shared_ptr->initial.pc = 0xA0001000;
91
 
92
    //tlb left zero
93
 
94
    shared_ptr->initial.index_p             = rand() & 0x1;
95
    shared_ptr->initial.index_index         = rand() & 0x3F;
96
 
97
    shared_ptr->initial.random              = rand() & 0x3F;
98
 
99
    shared_ptr->initial.entrylo_pfn         = rand() & 0xFFFFF;
100
    shared_ptr->initial.entrylo_n           = rand() & 0x1;
101
    shared_ptr->initial.entrylo_d           = rand() & 0x1;
102
    shared_ptr->initial.entrylo_v           = rand() & 0x1;
103
    shared_ptr->initial.entrylo_g           = rand() & 0x1;
104
 
105
    shared_ptr->initial.context_ptebase     = rand() & 0x7FF;
106
    shared_ptr->initial.context_badvpn      = rand() & 0x7FFFF;
107
 
108
    shared_ptr->initial.bad_vaddr           = rand_uint32();
109
 
110
    shared_ptr->initial.entryhi_vpn         = rand() & 0xFFFFF;
111
    shared_ptr->initial.entryhi_asid        = rand() & 0x3F;
112
 
113
    shared_ptr->initial.sr_cp_usable        = rand() & 0xF;
114
    shared_ptr->initial.sr_rev_endian       = rand() & 0x1;
115
    shared_ptr->initial.sr_bootstrap_vec    = rand() & 0x1;
116
    shared_ptr->initial.sr_tlb_shutdown     = rand() & 0x1;
117
    shared_ptr->initial.sr_parity_err       = rand() & 0x1;
118
    shared_ptr->initial.sr_cache_miss       = rand() & 0x1;
119
    shared_ptr->initial.sr_parity_zero      = rand() & 0x1;
120
    shared_ptr->initial.sr_switch_cache     = rand() & 0x1;
121
    shared_ptr->initial.sr_isolate_cache    = rand() & 0x1;
122
    shared_ptr->initial.sr_irq_mask         = rand() & 0xFF;
123
    shared_ptr->initial.sr_ku_ie            = rand() & 0x3F;
124
 
125
    shared_ptr->initial.cause_branch_delay  = rand() & 0x1;
126
    shared_ptr->initial.cause_cp_error      = rand() & 0x3;
127
    shared_ptr->initial.cause_irq_pending   = 0;
128
    shared_ptr->initial.cause_exc_code      = rand() & 0x1F;
129
 
130
    shared_ptr->initial.epc                 = rand_uint32();
131
 
132
    //
133
    shared_ptr->irq2_at_event = 0xFFFFFFFF;
134
    shared_ptr->irq3_at_event = 0xFFFFFFFF;
135
 
136
    //
137
    bool was_mul = false;
138
    bool was_div = false;
139
 
140
    //
141
    uint32 *ptr = &shared_ptr->mem.ints[(shared_ptr->initial.pc & 0x1FFFFFFF) / 4];
142
    for(int i=0; i<5; i++) {
143
        put_instruction(ptr, was_mul, was_div);
144
        ptr++;
145
    }
146
 
147
    //finish with SYSCALL or BREAK
148
    (*ptr) = rand() & 0x03FFFFC0;
149
    if(rand() % 2)  (*ptr) |= 0b001100;
150
    else            (*ptr) |= 0b001101;
151
}
152
 
153
//------------------------------------------------------------------------------
154
 
155
//------------------------------------------------------------------------------
156
 
157
//------------------------------------------------------------------------------
158
 
159
//------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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