MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / write

Method write

crates/virtual-machine/src/cpu/csr.rs:183–290  ·  view source on GitHub ↗
(&mut self, addr: u16, val: u64)

Source from the content-addressed store, hash-verified

181 }
182
183 pub fn write(&mut self, addr: u16, val: u64) -> Result<(), VmError> {
184 use addr::{
185 CYCLE, FCSR, FFLAGS, FRM, INSTRET, MCAUSE, MCOUNTEREN, MEDELEG, MEPC, MHARTID, MIDELEG,
186 MIE, MIP, MISA, MSCRATCH, MSTATUS, MTVAL, MTVEC, SATP, SCAUSE, SCOUNTEREN, SEPC, SIE,
187 SIP, SSCRATCH, SSTATUS, STVAL, STVEC,
188 };
189 match addr {
190 FFLAGS => {
191 self.fflags = (val & 0x1F) as u8;
192 }
193 FRM => {
194 self.frm = (val & 0x07) as u8;
195 }
196 FCSR => {
197 self.fflags = (val & 0x1F) as u8;
198 self.frm = ((val >> 5) & 0x07) as u8;
199 }
200 // Read-only counters; writes silently ignored.
201 CYCLE | INSTRET | MHARTID | MISA => {}
202
203 // sstatus write updates only the S-mode-visible bits of mstatus.
204 SSTATUS => {
205 self.mstatus = (self.mstatus & !SSTATUS_MASK) | (val & SSTATUS_MASK);
206 }
207 // sie write updates only the S-mode-visible interrupt-enable bits of mie.
208 SIE => {
209 self.mie = (self.mie & !S_IRQ_MASK) | (val & S_IRQ_MASK);
210 }
211 STVEC => {
212 self.stvec = val;
213 }
214 // SCOUNTEREN: stub, ignore writes.
215 SCOUNTEREN => {}
216 SSCRATCH => {
217 self.sscratch = val;
218 }
219 SEPC => {
220 self.sepc = val & !0x3;
221 }
222 SCAUSE => {
223 self.scause = val;
224 }
225 STVAL => {
226 self.stval = val;
227 }
228 // sip write: only SSIP (bit 1) is software-writable from S-mode.
229 SIP => {
230 self.mip = (self.mip & !(1u64 << 1)) | (val & (1u64 << 1));
231 }
232 SATP => {
233 let mode = (val >> 60) & 0xF;
234 if mode == 0 || mode == 8 {
235 self.satp = val;
236 } else {
237 // Unsupported mode: set Bare (mode=0) silently.
238 self.satp = val & !(0xFu64 << 60);
239 }
240 }

Callers 15

writebackFunction · 0.80
writeback_csrrwFunction · 0.80
writeback_csrrs_set_bitsFunction · 0.80
csr_mstatus_read_writeFunction · 0.80
csr_misa_readonlyFunction · 0.80
csr_mtvec_read_writeFunction · 0.80
csr_mepc_alignmentFunction · 0.80
csr_mie_read_writeFunction · 0.80
csr_mip_read_writeFunction · 0.80
csr_fflags_read_writeFunction · 0.80
csr_frm_read_writeFunction · 0.80

Calls

no outgoing calls

Tested by 15

writeback_csrrwFunction · 0.64
writeback_csrrs_set_bitsFunction · 0.64
csr_mstatus_read_writeFunction · 0.64
csr_misa_readonlyFunction · 0.64
csr_mtvec_read_writeFunction · 0.64
csr_mepc_alignmentFunction · 0.64
csr_mie_read_writeFunction · 0.64
csr_mip_read_writeFunction · 0.64
csr_fflags_read_writeFunction · 0.64
csr_frm_read_writeFunction · 0.64
csr_fcsr_compositeFunction · 0.64