10 #include "softfloat.h"
12 processor_t::processor_t(sim_t
* _sim
, char* _mem
, size_t _memsz
)
13 : sim(_sim
), mmu(_mem
,_memsz
)
15 memset(R
,0,sizeof(R
));
16 memset(FR
,0,sizeof(FR
));
28 interrupts_pending
= 0;
29 set_sr(SR_S
| (support_64bit
? SR_SX
: 0));
32 memset(counters
,0,sizeof(counters
));
34 // a few assumptions about endianness, including freg_t union
35 static_assert(BYTE_ORDER
== LITTLE_ENDIAN
);
36 static_assert(sizeof(freg_t
) == 8);
37 static_assert(sizeof(reg_t
) == 8);
39 static_assert(sizeof(insn_t
) == 4);
40 static_assert(sizeof(uint128_t
) == 16 && sizeof(int128_t
) == 16);
43 void processor_t::init(uint32_t _id
)
48 void processor_t::set_sr(uint32_t val
)
52 sr
&= ~(SR_SX
| SR_UX
);
54 gprlen
= ((sr
& SR_S
) ? (sr
& SR_SX
) : (sr
& SR_UX
)) ? 64 : 32;
57 void processor_t::set_fsr(uint32_t val
)
59 fsr
= val
& ~FSR_ZERO
;
60 softfloat_roundingMode
= (fsr
& FSR_RD
) >> FSR_RD_SHIFT
;
63 void processor_t::step(size_t n
, bool noisy
)
70 uint32_t interrupts
= interrupts_pending
& ((sr
& SR_IM
) >> SR_IM_SHIFT
);
71 if((sr
& SR_ET
) && interrupts
)
73 for(int i
= 0; interrupts
; i
++, interrupts
>>= 1)
78 insn_t insn
= mmu
.load_insn(pc
);
80 reg_t npc
= pc
+sizeof(insn
);
90 if(count
++ == compare
)
91 interrupts_pending
|= 1 << TIMER_IRQ
;
102 void processor_t::take_trap(trap_t t
, bool noisy
)
104 demand(t
< NUM_TRAPS
, "internal error: bad trap number %d", int(t
));
105 demand(sr
& SR_ET
, "error mode on core %d!\ntrap %s, pc 0x%016llx",
106 id
, trap_name(t
), (unsigned long long)pc
);
108 printf("core %3d: trap %s, pc 0x%016llx\n",
109 id
, trap_name(t
), (unsigned long long)pc
);
111 set_sr((((sr
& ~SR_ET
) | SR_S
) & ~SR_PS
) | ((sr
& SR_S
) ? SR_PS
: 0));
114 badvaddr
= mmu
.get_badvaddr();
117 void processor_t::disasm(insn_t insn
, reg_t pc
)
119 printf("core %3d: 0x%016llx (0x%08x) ",id
,(unsigned long long)pc
,insn
.bits
);
121 #ifdef RISCV_HAVE_LIBOPCODES
122 disassemble_info info
;
123 INIT_DISASSEMBLE_INFO(info
, stdout
, fprintf
);
124 info
.flavour
= bfd_target_unknown_flavour
;
125 info
.arch
= bfd_arch_mips
;
126 info
.mach
= 101; // XXX bfd_mach_mips_riscv requires modified bfd.h
127 info
.endian
= BFD_ENDIAN_LITTLE
;
128 info
.buffer
= (bfd_byte
*)&insn
;
129 info
.buffer_length
= sizeof(insn
);
130 info
.buffer_vma
= pc
;
132 demand(print_insn_little_mips(pc
, &info
) == sizeof(insn
), "disasm bug!");