11 #include "softfloat.h"
12 #include "platform.h" // softfloat isNaNF32UI, etc.
13 #include "internals.h" // ditto
15 processor_t::processor_t(sim_t
* _sim
, char* _mem
, size_t _memsz
)
16 : sim(_sim
), mmu(_mem
,_memsz
)
18 memset(XPR
,0,sizeof(XPR
));
19 memset(FPR
,0,sizeof(FPR
));
31 set_sr(SR_S
| SR_SX
); // SX ignored if 64b mode not supported
34 memset(counters
,0,sizeof(counters
));
45 for (int i
=0; i
<MAX_UTS
; i
++)
48 // a few assumptions about endianness, including freg_t union
49 static_assert(BYTE_ORDER
== LITTLE_ENDIAN
);
50 static_assert(sizeof(freg_t
) == 8);
51 static_assert(sizeof(reg_t
) == 8);
53 static_assert(sizeof(insn_t
) == 4);
54 static_assert(sizeof(uint128_t
) == 16 && sizeof(int128_t
) == 16);
62 processor_t::~processor_t()
69 itlbsim
->print_stats();
77 dtlbsim
->print_stats();
81 void processor_t::init(uint32_t _id
, icsim_t
* default_icache
,
82 icsim_t
* default_dcache
)
86 for (int i
=0; i
<MAX_UTS
; i
++)
88 uts
[i
] = new processor_t(sim
, mmu
.mem
, mmu
.memsz
);
90 uts
[i
]->set_sr(uts
[i
]->sr
| SR_EF
);
91 uts
[i
]->set_sr(uts
[i
]->sr
| SR_EV
);
95 #ifdef RISCV_ENABLE_ICSIM
96 icsim
= new icsim_t(*default_icache
);
98 itlbsim
= new icsim_t(1, 8, 4096, "ITLB");
99 mmu
.set_itlbsim(itlbsim
);
101 #ifdef RISCV_ENABLE_ICSIM
102 dcsim
= new icsim_t(*default_dcache
);
103 mmu
.set_dcsim(dcsim
);
104 dtlbsim
= new icsim_t(1, 8, 4096, "DTLB");
105 mmu
.set_dtlbsim(dtlbsim
);
109 void processor_t::set_sr(uint32_t val
)
112 #ifndef RISCV_ENABLE_64BIT
113 sr
&= ~(SR_SX
| SR_UX
);
115 #ifndef RISCV_ENABLE_FPU
118 #ifndef RISCV_ENABLE_RVC
121 #ifndef RISCV_ENABLE_VEC
125 mmu
.set_vm_enabled(sr
& SR_VM
);
126 mmu
.set_supervisor(sr
& SR_S
);
129 xprlen
= ((sr
& SR_S
) ? (sr
& SR_SX
) : (sr
& SR_UX
)) ? 64 : 32;
132 void processor_t::set_fsr(uint32_t val
)
134 fsr
= val
& ~FSR_ZERO
;
137 void processor_t::vcfg()
139 if (nxpr_use
+ nfpr_use
< 2)
140 vlmax
= nxfpr_bank
* vecbanks_count
;
142 vlmax
= (nxfpr_bank
/ (nxpr_use
+ nfpr_use
- 1)) * vecbanks_count
;
144 vlmax
= std::min(vlmax
, MAX_UTS
);
147 void processor_t::setvl(int vlapp
)
149 vl
= std::min(vlmax
, vlapp
);
152 void processor_t::step(size_t n
, bool noisy
)
159 uint32_t interrupts
= (cause
& CAUSE_IP
) >> CAUSE_IP_SHIFT
;
160 interrupts
&= (sr
& SR_IM
) >> SR_IM_SHIFT
;
161 if(interrupts
&& (sr
& SR_ET
))
162 take_trap(trap_interrupt
,noisy
);
164 insn_t insn
= mmu
.load_insn(pc
, sr
& SR_EC
);
166 reg_t npc
= pc
+ insn_length(insn
);
176 if(count
++ == compare
)
177 cause
|= 1 << (TIMER_IRQ
+CAUSE_IP_SHIFT
);
186 catch(vt_command_t cmd
)
188 if (cmd
== vt_command_stop
)
193 void processor_t::take_trap(trap_t t
, bool noisy
)
195 demand(t
< NUM_TRAPS
, "internal error: bad trap number %d", int(t
));
196 demand(sr
& SR_ET
, "error mode on core %d!\ntrap %s, pc 0x%016llx",
197 id
, trap_name(t
), (unsigned long long)pc
);
199 printf("core %3d: trap %s, pc 0x%016llx\n",
200 id
, trap_name(t
), (unsigned long long)pc
);
202 set_sr((((sr
& ~SR_ET
) | SR_S
) & ~SR_PS
) | ((sr
& SR_S
) ? SR_PS
: 0));
203 cause
= (cause
& ~CAUSE_EXCCODE
) | (t
<< CAUSE_EXCCODE_SHIFT
);
206 badvaddr
= mmu
.get_badvaddr();
209 void processor_t::disasm(insn_t insn
, reg_t pc
)
211 printf("core %3d: 0x%016llx (0x%08x) ",id
,(unsigned long long)pc
,insn
.bits
);
213 #ifdef RISCV_HAVE_LIBOPCODES
214 disassemble_info info
;
215 INIT_DISASSEMBLE_INFO(info
, stdout
, fprintf
);
216 info
.flavour
= bfd_target_unknown_flavour
;
217 info
.arch
= bfd_arch_mips
;
218 info
.mach
= 101; // XXX bfd_mach_mips_riscv requires modified bfd.h
219 info
.endian
= BFD_ENDIAN_LITTLE
;
220 info
.buffer
= (bfd_byte
*)&insn
;
221 info
.buffer_length
= sizeof(insn
);
222 info
.buffer_vma
= pc
;
224 int ret
= print_insn_little_mips(pc
, &info
);
225 demand(ret
== (INSN_IS_RVC(insn
.bits
) ? 2 : 4), "disasm bug!");