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
));
29 interrupts_pending
= 0;
30 set_sr(SR_S
| (support_64bit
? SR_SX
: 0));
33 memset(counters
,0,sizeof(counters
));
35 // a few assumptions about endianness, including freg_t union
36 static_assert(BYTE_ORDER
== LITTLE_ENDIAN
);
37 static_assert(sizeof(freg_t
) == 8);
38 static_assert(sizeof(reg_t
) == 8);
40 static_assert(sizeof(insn_t
) == 4);
41 static_assert(sizeof(uint128_t
) == 16 && sizeof(int128_t
) == 16);
44 void processor_t::init(uint32_t _id
)
49 void processor_t::set_sr(uint32_t val
)
53 sr
&= ~(SR_SX
| SR_UX
);
57 gprlen
= ((sr
& SR_S
) ? (sr
& SR_SX
) : (sr
& SR_UX
)) ? 64 : 32;
60 void processor_t::set_fsr(uint32_t val
)
62 fsr
= val
& ~FSR_ZERO
;
63 softfloat_roundingMode
= (fsr
& FSR_RD
) >> FSR_RD_SHIFT
;
66 void processor_t::step(size_t n
, bool noisy
)
73 uint32_t interrupts
= interrupts_pending
& ((sr
& SR_IM
) >> SR_IM_SHIFT
);
74 if((sr
& SR_ET
) && interrupts
)
76 for(int i
= 0; interrupts
; i
++, interrupts
>>= 1)
81 insn_t insn
= mmu
.load_insn(pc
);
83 reg_t npc
= pc
+sizeof(insn
);
93 if(count
++ == compare
)
94 interrupts_pending
|= 1 << TIMER_IRQ
;
105 void processor_t::take_trap(trap_t t
, bool noisy
)
107 demand(t
< NUM_TRAPS
, "internal error: bad trap number %d", int(t
));
108 demand(sr
& SR_ET
, "error mode on core %d!\ntrap %s, pc 0x%016llx",
109 id
, trap_name(t
), (unsigned long long)pc
);
111 printf("core %3d: trap %s, pc 0x%016llx\n",
112 id
, trap_name(t
), (unsigned long long)pc
);
114 set_sr((((sr
& ~SR_ET
) | SR_S
) & ~SR_PS
) | ((sr
& SR_S
) ? SR_PS
: 0));
118 badvaddr
= mmu
.get_badvaddr();
121 void processor_t::disasm(insn_t insn
, reg_t pc
)
123 printf("core %3d: 0x%016llx (0x%08x) ",id
,(unsigned long long)pc
,insn
.bits
);
125 #ifdef RISCV_HAVE_LIBOPCODES
126 disassemble_info info
;
127 INIT_DISASSEMBLE_INFO(info
, stdout
, fprintf
);
128 info
.flavour
= bfd_target_unknown_flavour
;
129 info
.arch
= bfd_arch_mips
;
130 info
.mach
= 101; // XXX bfd_mach_mips_riscv requires modified bfd.h
131 info
.endian
= BFD_ENDIAN_LITTLE
;
132 info
.buffer
= (bfd_byte
*)&insn
;
133 info
.buffer_length
= sizeof(insn
);
134 info
.buffer_vma
= pc
;
136 demand(print_insn_little_mips(pc
, &info
) == sizeof(insn
), "disasm bug!");