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 // a few assumptions about endianness, including freg_t union
19 static_assert(BYTE_ORDER
== LITTLE_ENDIAN
);
20 static_assert(sizeof(freg_t
) == 8);
21 static_assert(sizeof(reg_t
) == 8);
23 static_assert(sizeof(insn_t
) == 4);
24 static_assert(sizeof(uint128_t
) == 16 && sizeof(int128_t
) == 16);
34 processor_t::~processor_t()
41 itlbsim
->print_stats();
49 dtlbsim
->print_stats();
53 void processor_t::init(uint32_t _id
, icsim_t
* default_icache
,
54 icsim_t
* default_dcache
)
58 for (int i
=0; i
<MAX_UTS
; i
++)
60 uts
[i
] = new processor_t(sim
, mmu
.mem
, mmu
.memsz
);
62 uts
[i
]->set_sr(uts
[i
]->sr
| SR_EF
);
63 uts
[i
]->set_sr(uts
[i
]->sr
| SR_EV
);
67 #ifdef RISCV_ENABLE_ICSIM
68 icsim
= new icsim_t(*default_icache
);
70 itlbsim
= new icsim_t(1, 8, 4096, "ITLB");
71 mmu
.set_itlbsim(itlbsim
);
73 #ifdef RISCV_ENABLE_ICSIM
74 dcsim
= new icsim_t(*default_dcache
);
76 dtlbsim
= new icsim_t(1, 8, 4096, "DTLB");
77 mmu
.set_dtlbsim(dtlbsim
);
81 void processor_t::reset()
85 memset(XPR
,0,sizeof(XPR
));
86 memset(FPR
,0,sizeof(FPR
));
100 set_sr(SR_S
| SR_SX
); // SX ignored if 64b mode not supported
112 for (int i
=0; i
<MAX_UTS
; i
++)
116 void processor_t::set_sr(uint32_t val
)
119 #ifndef RISCV_ENABLE_64BIT
120 sr
&= ~(SR_SX
| SR_UX
);
122 #ifndef RISCV_ENABLE_FPU
125 #ifndef RISCV_ENABLE_RVC
128 #ifndef RISCV_ENABLE_VEC
132 mmu
.set_vm_enabled(sr
& SR_VM
);
133 mmu
.set_supervisor(sr
& SR_S
);
136 xprlen
= ((sr
& SR_S
) ? (sr
& SR_SX
) : (sr
& SR_UX
)) ? 64 : 32;
139 void processor_t::set_fsr(uint32_t val
)
141 fsr
= val
& ~FSR_ZERO
;
144 void processor_t::vcfg()
146 if (nxpr_use
+ nfpr_use
< 2)
147 vlmax
= nxfpr_bank
* vecbanks_count
;
149 vlmax
= (nxfpr_bank
/ (nxpr_use
+ nfpr_use
- 1)) * vecbanks_count
;
151 vlmax
= std::min(vlmax
, MAX_UTS
);
154 void processor_t::setvl(int vlapp
)
156 vl
= std::min(vlmax
, vlapp
);
159 void processor_t::step(size_t n
, bool noisy
)
166 uint32_t interrupts
= (cause
& CAUSE_IP
) >> CAUSE_IP_SHIFT
;
167 interrupts
&= (sr
& SR_IM
) >> SR_IM_SHIFT
;
168 if(interrupts
&& (sr
& SR_ET
))
169 take_trap(trap_interrupt
,noisy
);
171 insn_t insn
= mmu
.load_insn(pc
, sr
& SR_EC
);
173 reg_t npc
= pc
+ insn_length(insn
);
183 if(count
++ == compare
)
184 cause
|= 1 << (TIMER_IRQ
+CAUSE_IP_SHIFT
);
194 catch(vt_command_t cmd
)
196 if (cmd
== vt_command_stop
)
205 void processor_t::take_trap(trap_t t
, bool noisy
)
207 demand(t
< NUM_TRAPS
, "internal error: bad trap number %d", int(t
));
208 demand(sr
& SR_ET
, "error mode on core %d!\ntrap %s, pc 0x%016llx",
209 id
, trap_name(t
), (unsigned long long)pc
);
211 printf("core %3d: trap %s, pc 0x%016llx\n",
212 id
, trap_name(t
), (unsigned long long)pc
);
214 set_sr((((sr
& ~SR_ET
) | SR_S
) & ~SR_PS
) | ((sr
& SR_S
) ? SR_PS
: 0));
215 cause
= (cause
& ~CAUSE_EXCCODE
) | (t
<< CAUSE_EXCCODE_SHIFT
);
218 badvaddr
= mmu
.get_badvaddr();
221 void processor_t::deliver_ipi()
223 cause
|= 1 << (IPI_IRQ
+CAUSE_IP_SHIFT
);
227 void processor_t::disasm(insn_t insn
, reg_t pc
)
229 printf("core %3d: 0x%016llx (0x%08x) ",id
,(unsigned long long)pc
,insn
.bits
);
231 #ifdef RISCV_HAVE_LIBOPCODES
232 disassemble_info info
;
233 INIT_DISASSEMBLE_INFO(info
, stdout
, fprintf
);
234 info
.flavour
= bfd_target_unknown_flavour
;
235 info
.arch
= bfd_arch_mips
;
236 info
.mach
= 101; // XXX bfd_mach_mips_riscv requires modified bfd.h
237 info
.endian
= BFD_ENDIAN_LITTLE
;
238 info
.buffer
= (bfd_byte
*)&insn
;
239 info
.buffer_length
= sizeof(insn
);
240 info
.buffer_vma
= pc
;
242 int ret
= print_insn_little_mips(pc
, &info
);
243 demand(ret
== (INSN_IS_RVC(insn
.bits
) ? 2 : 4), "disasm bug!");