| 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 tlb_data_till_exc_init(tst_t *tst, shared_mem_t *shared_ptr) {
|
| 16 |
|
|
|
| 17 |
|
|
for(int i=1; i<32; i++) shared_ptr->initial.reg[i-1] = rand_uint32();
|
| 18 |
|
|
|
| 19 |
|
|
shared_ptr->initial.pc = (rand() % 2)? 0x00091000 : 0xF0001000;
|
| 20 |
|
|
|
| 21 |
|
|
shared_ptr->initial.index_p = rand() & 0x1;
|
| 22 |
|
|
shared_ptr->initial.index_index = rand() & 0x3F;
|
| 23 |
|
|
|
| 24 |
|
|
shared_ptr->initial.random = rand() & 0x3F;
|
| 25 |
|
|
|
| 26 |
|
|
shared_ptr->initial.entrylo_pfn = rand() & 0xFFFFF;
|
| 27 |
|
|
shared_ptr->initial.entrylo_n = rand() & 0x1;
|
| 28 |
|
|
shared_ptr->initial.entrylo_d = rand() & 0x1;
|
| 29 |
|
|
shared_ptr->initial.entrylo_v = rand() & 0x1;
|
| 30 |
|
|
shared_ptr->initial.entrylo_g = rand() & 0x1;
|
| 31 |
|
|
|
| 32 |
|
|
shared_ptr->initial.context_ptebase = rand() & 0x7FF;
|
| 33 |
|
|
shared_ptr->initial.context_badvpn = rand() & 0x7FFFF;
|
| 34 |
|
|
|
| 35 |
|
|
shared_ptr->initial.bad_vaddr = rand_uint32();
|
| 36 |
|
|
|
| 37 |
|
|
shared_ptr->initial.entryhi_vpn = rand() & 0xFFFFF;
|
| 38 |
|
|
shared_ptr->initial.entryhi_asid = rand() & 0x3F;
|
| 39 |
|
|
|
| 40 |
|
|
shared_ptr->initial.sr_cp_usable = rand() & 0xF;
|
| 41 |
|
|
shared_ptr->initial.sr_rev_endian = rand() & 0x1;
|
| 42 |
|
|
shared_ptr->initial.sr_bootstrap_vec = rand() & 0x1;
|
| 43 |
|
|
shared_ptr->initial.sr_tlb_shutdown = rand() & 0x1;
|
| 44 |
|
|
shared_ptr->initial.sr_parity_err = rand() & 0x1;
|
| 45 |
|
|
shared_ptr->initial.sr_cache_miss = rand() & 0x1;
|
| 46 |
|
|
shared_ptr->initial.sr_parity_zero = rand() & 0x1;
|
| 47 |
|
|
shared_ptr->initial.sr_switch_cache = 0; //rand() & 0x1;
|
| 48 |
|
|
shared_ptr->initial.sr_isolate_cache = 0; //rand() & 0x1;
|
| 49 |
|
|
shared_ptr->initial.sr_irq_mask = rand() & 0xFF;
|
| 50 |
|
|
shared_ptr->initial.sr_ku_ie = rand() & 0x3F;
|
| 51 |
|
|
|
| 52 |
|
|
shared_ptr->initial.cause_branch_delay = rand() & 0x1;
|
| 53 |
|
|
shared_ptr->initial.cause_cp_error = rand() & 0x3;
|
| 54 |
|
|
shared_ptr->initial.cause_irq_pending = 0;
|
| 55 |
|
|
shared_ptr->initial.cause_exc_code = rand() & 0x1F;
|
| 56 |
|
|
|
| 57 |
|
|
shared_ptr->initial.epc = rand_uint32();
|
| 58 |
|
|
|
| 59 |
|
|
//
|
| 60 |
|
|
shared_ptr->irq2_at_event = 0xFFFFFFFF;
|
| 61 |
|
|
shared_ptr->irq3_at_event = 0xFFFFFFFF;
|
| 62 |
|
|
|
| 63 |
|
|
//pc
|
| 64 |
|
|
uint32 vaddr_pc = shared_ptr->initial.pc;
|
| 65 |
|
|
uint32 paddr_pc = 0x5000;
|
| 66 |
|
|
|
| 67 |
|
|
shared_ptr->initial.tlb[55].vpn = (vaddr_pc >> 12) & 0xFFFFF;
|
| 68 |
|
|
shared_ptr->initial.tlb[55].asid = ((rand() % 5) == 0)? (rand() % 0x1F) : shared_ptr->initial.entryhi_asid;
|
| 69 |
|
|
shared_ptr->initial.tlb[55].pfn = (paddr_pc >> 12) & 0xFFFFF;
|
| 70 |
|
|
shared_ptr->initial.tlb[55].n = rand() % 2;
|
| 71 |
|
|
shared_ptr->initial.tlb[55].d = rand() % 2;
|
| 72 |
|
|
shared_ptr->initial.tlb[55].v = rand() % 2;
|
| 73 |
|
|
shared_ptr->initial.tlb[55].g = rand() % 2;
|
| 74 |
|
|
|
| 75 |
|
|
uint32 *ptr = &shared_ptr->mem.ints[paddr_pc / 4];
|
| 76 |
|
|
|
| 77 |
|
|
//data
|
| 78 |
|
|
uint32 vaddr_data = (rand() % 2)? 0x000C1000 : 0xF01C1000;
|
| 79 |
|
|
uint32 paddr_data = 0x000A0000;
|
| 80 |
|
|
|
| 81 |
|
|
for(uint32 i=0; i<14; i++) { //14 * 4096 - virtual memory
|
| 82 |
|
|
shared_ptr->initial.tlb[5+i].vpn = ((vaddr_data - ((8-i)*4096)) >> 12) & 0xFFFFF;
|
| 83 |
|
|
shared_ptr->initial.tlb[5+i].asid = ((rand() % 5) == 0)? (rand() % 0x1F) : shared_ptr->initial.entryhi_asid;
|
| 84 |
|
|
shared_ptr->initial.tlb[5+i].pfn = ((paddr_data - ((8-i)*4096)) >> 12) & 0xFFFFF;
|
| 85 |
|
|
shared_ptr->initial.tlb[5+i].n = rand() % 2;
|
| 86 |
|
|
shared_ptr->initial.tlb[5+i].d = rand() % 2;
|
| 87 |
|
|
shared_ptr->initial.tlb[5+i].v = rand() % 2;
|
| 88 |
|
|
shared_ptr->initial.tlb[5+i].g = rand() % 2;
|
| 89 |
|
|
}
|
| 90 |
|
|
|
| 91 |
|
|
uint32 scope = 65536;
|
| 92 |
|
|
|
| 93 |
|
|
uint32 loading_reg = 0;
|
| 94 |
|
|
|
| 95 |
|
|
shared_ptr->initial.reg[0] = vaddr_data;
|
| 96 |
|
|
|
| 97 |
|
|
for(int operation=0; operation<100; operation++) {
|
| 98 |
|
|
|
| 99 |
|
|
uint32 type = rand() % 12;
|
| 100 |
|
|
|
| 101 |
|
|
uint32 storing_reg = 2 + (rand() % 30);
|
| 102 |
|
|
while(storing_reg == loading_reg) storing_reg = 2 + (rand() % 30);
|
| 103 |
|
|
|
| 104 |
|
|
if(type == 0) { //LB
|
| 105 |
|
|
loading_reg = 2 + (rand() % 30);
|
| 106 |
|
|
|
| 107 |
|
|
(*ptr) = (0b100000 << 26) | (1 << 21) | (loading_reg << 16) | (rand() % scope);
|
| 108 |
|
|
ptr++;
|
| 109 |
|
|
}
|
| 110 |
|
|
else if(type == 1) { //LBU
|
| 111 |
|
|
loading_reg = 2 + (rand() % 30);
|
| 112 |
|
|
|
| 113 |
|
|
(*ptr) = (0b100100 << 26) | (1 << 21) | (loading_reg << 16) | (rand() % scope);
|
| 114 |
|
|
ptr++;
|
| 115 |
|
|
}
|
| 116 |
|
|
else if(type == 2) { //LH
|
| 117 |
|
|
loading_reg = 2 + (rand() % 30);
|
| 118 |
|
|
|
| 119 |
|
|
(*ptr) = (0b100001 << 26) | (1 << 21) | (loading_reg << 16) | ((rand() % scope) & 0xFFFE) | (((rand() % 5) == 0)? 1 : 0);
|
| 120 |
|
|
ptr++;
|
| 121 |
|
|
}
|
| 122 |
|
|
else if(type == 3) { //LHU
|
| 123 |
|
|
loading_reg = 2 + (rand() % 30);
|
| 124 |
|
|
|
| 125 |
|
|
(*ptr) = (0b100101 << 26) | (1 << 21) | (loading_reg << 16) | ((rand() % scope) & 0xFFFE) | (((rand() % 5) == 0)? 1 : 0);
|
| 126 |
|
|
ptr++;
|
| 127 |
|
|
}
|
| 128 |
|
|
else if(type == 4) { //LW
|
| 129 |
|
|
loading_reg = 2 + (rand() % 30);
|
| 130 |
|
|
|
| 131 |
|
|
(*ptr) = (0b100011 << 26) | (1 << 21) | (loading_reg << 16) | ((rand() % scope) & 0xFFFC) | (((rand() % 5) == 0)? (1 + (rand() % 3)) : 0);
|
| 132 |
|
|
ptr++;
|
| 133 |
|
|
}
|
| 134 |
|
|
else if(type == 5) { //LWL
|
| 135 |
|
|
loading_reg = 2 + (rand() % 30);
|
| 136 |
|
|
|
| 137 |
|
|
(*ptr) = (0b100010 << 26) | (1 << 21) | (loading_reg << 16) | (rand() % scope);
|
| 138 |
|
|
ptr++;
|
| 139 |
|
|
}
|
| 140 |
|
|
else if(type == 6) { //LWR
|
| 141 |
|
|
loading_reg = 2 + (rand() % 30);
|
| 142 |
|
|
|
| 143 |
|
|
(*ptr) = (0b100110 << 26) | (1 << 21) | (loading_reg << 16) | (rand() % scope);
|
| 144 |
|
|
ptr++;
|
| 145 |
|
|
}
|
| 146 |
|
|
else if(type == 7) { //SB
|
| 147 |
|
|
loading_reg = 0;
|
| 148 |
|
|
|
| 149 |
|
|
(*ptr) = (0b101000 << 26) | (1 << 21) | (storing_reg << 16) | (rand() % scope);
|
| 150 |
|
|
ptr++;
|
| 151 |
|
|
}
|
| 152 |
|
|
else if(type == 8) { //SH
|
| 153 |
|
|
loading_reg = 0;
|
| 154 |
|
|
|
| 155 |
|
|
(*ptr) = (0b101001 << 26) | (1 << 21) | (storing_reg << 16) | ((rand() % scope) & 0xFFFE) | (((rand() % 5) == 0)? 1 : 0);
|
| 156 |
|
|
ptr++;
|
| 157 |
|
|
}
|
| 158 |
|
|
else if(type == 9) { //SW
|
| 159 |
|
|
loading_reg = 0;
|
| 160 |
|
|
|
| 161 |
|
|
(*ptr) = (0b101011 << 26) | (1 << 21) | (storing_reg << 16) | ((rand() % scope) & 0xFFFC) | (((rand() % 5) == 0)? (1 + (rand() % 3)) : 0);
|
| 162 |
|
|
ptr++;
|
| 163 |
|
|
}
|
| 164 |
|
|
else if(type == 10) { //SWL
|
| 165 |
|
|
loading_reg = 0;
|
| 166 |
|
|
|
| 167 |
|
|
(*ptr) = (0b101010 << 26) | (1 << 21) | (storing_reg << 16) | (rand() % scope);
|
| 168 |
|
|
ptr++;
|
| 169 |
|
|
}
|
| 170 |
|
|
else if(type == 11) { //SWR
|
| 171 |
|
|
loading_reg = 0;
|
| 172 |
|
|
|
| 173 |
|
|
(*ptr) = (0b101110 << 26) | (1 << 21) | (storing_reg << 16) | (rand() % scope);
|
| 174 |
|
|
ptr++;
|
| 175 |
|
|
}
|
| 176 |
|
|
}
|
| 177 |
|
|
|
| 178 |
|
|
for(uint32 i=paddr_data - 32768; i<paddr_data + 32768; i++) {
|
| 179 |
|
|
shared_ptr->mem.ints[i/4] = rand_uint32();
|
| 180 |
|
|
}
|
| 181 |
|
|
|
| 182 |
|
|
(*ptr) = rand() & 0x03FFFFC0;
|
| 183 |
|
|
(*ptr) |= 0b001100; //SYSCALL
|
| 184 |
|
|
ptr++;
|
| 185 |
|
|
}
|
| 186 |
|
|
|
| 187 |
|
|
//------------------------------------------------------------------------------
|