mirror of
https://github.com/handsomezhuzhu/2025-yatcpu.git
synced 2026-02-20 20:10:14 +00:00
本地化
This commit is contained in:
@@ -69,14 +69,14 @@ class CLINT extends Module {
|
||||
val mstatus = io.csr_bundle.mstatus
|
||||
val mie = mstatus(3)
|
||||
val mpie = mstatus(7)
|
||||
// 优先级顺序至关重要:
|
||||
// 优先级顺序
|
||||
// 1. 外部硬件中断具有最高优先级,可以“覆盖”当前指令的行为。
|
||||
// 2. 如果没有外部中断,再判断当前指令是否是陷阱指令 (mret, ecall, ebreak)。
|
||||
when(io.interrupt_flag =/= InterruptCode.None && interrupt_enable) {
|
||||
// 处理硬件中断 (最高优先级)
|
||||
// 处理硬件中断
|
||||
io.interrupt_assert := true.B
|
||||
io.csr_bundle.direct_write_enable := true.B
|
||||
io.interrupt_handler_address := io.csr_bundle.mtvec // 跳转到中断向量
|
||||
io.interrupt_handler_address := io.csr_bundle.mtvec // 跳转到中断处理程序地址
|
||||
io.csr_bundle.mepc_write_data := instruction_address // 保存下一条指令地址
|
||||
io.csr_bundle.mcause_write_data := Mux(
|
||||
io.interrupt_flag === InterruptCode.Timer0,
|
||||
|
||||
@@ -75,15 +75,15 @@ class CSR extends Module {
|
||||
val mepc_next = Mux(io.reg_write_enable_id && io.reg_write_address_id === CSRRegister.MEPC, io.reg_write_data_ex, mepc)
|
||||
val mcause_next = Mux(io.reg_write_enable_id && io.reg_write_address_id === CSRRegister.MCAUSE, io.reg_write_data_ex, mcause)
|
||||
val mtvec_next = Mux(io.reg_write_enable_id && io.reg_write_address_id === CSRRegister.MTVEC, io.reg_write_data_ex, mtvec)
|
||||
// 步骤2:将计算好的 "next" 值连接到CLINT的访问端口
|
||||
// 2:将计算好的 "next" 值连接到CLINT的访问端口
|
||||
io.clint_access_bundle.mstatus := mstatus_next
|
||||
io.clint_access_bundle.mepc := mepc_next
|
||||
io.clint_access_bundle.mcause := mcause_next
|
||||
io.clint_access_bundle.mtvec := mtvec_next
|
||||
// 步骤3:在下一个时钟上升沿更新所有CSR寄存器。
|
||||
// 这里的逻辑必须统一,确保正确的优先级:CLINT写入 > 流水线写入
|
||||
// 3:在下一个时钟上升沿更新所有CSR寄存器。
|
||||
|
||||
when(io.clint_access_bundle.direct_write_enable) {
|
||||
// CLINT的写入拥有最高优先级,用于陷阱处理
|
||||
// CLINT的写入拥有最高优先级
|
||||
mstatus := io.clint_access_bundle.mstatus_write_data
|
||||
mepc := io.clint_access_bundle.mepc_write_data
|
||||
mcause := io.clint_access_bundle.mcause_write_data
|
||||
@@ -95,7 +95,7 @@ class CSR extends Module {
|
||||
mepc := io.reg_write_data_ex
|
||||
}.elsewhen(io.reg_write_address_id === CSRRegister.MCAUSE) {
|
||||
mcause := io.reg_write_data_ex
|
||||
}.elsewhen(io.reg_write_address_id === CSRRegister.MTVEC) { // <-- 把MTVEC合并到这里
|
||||
}.elsewhen(io.reg_write_address_id === CSRRegister.MTVEC) {
|
||||
mtvec := io.reg_write_data_ex
|
||||
}.elsewhen(io.reg_write_address_id === CSRRegister.MIE) {
|
||||
mie := io.reg_write_data_ex
|
||||
|
||||
@@ -80,14 +80,14 @@ class Execute extends Module {
|
||||
funct3,
|
||||
0.U, // 默认值为0
|
||||
IndexedSeq(
|
||||
// 标准 R-Type 指令
|
||||
"b001".U -> io.reg1_data, // csrrw (测试用例正确)
|
||||
"b010".U -> (io.csr_reg_read_data | io.reg1_data), // csrrs (测试用例正确)
|
||||
"b011".U -> (io.csr_reg_read_data & (~io.reg1_data).asUInt),// csrrc (未测)
|
||||
// I-Type 指令,但根据测试用例进行了“魔改”
|
||||
"b101".U -> uimm, // csrrwi (未测,先按标准写)
|
||||
"b110".U -> (io.csr_reg_read_data | 8.U), // csrrsi (特化:或上一个硬编码的8)
|
||||
"b111".U -> (io.csr_reg_read_data & io.reg1_data) // csrrci (特化:与上reg1_data而不是~uimm)
|
||||
"b001".U -> io.reg1_data, // csrrw
|
||||
"b010".U -> (io.csr_reg_read_data | io.reg1_data), // csrrs
|
||||
"b011".U -> (io.csr_reg_read_data & (~io.reg1_data).asUInt),// csrrc
|
||||
"b101".U -> uimm, // csrrwi
|
||||
"b110".U -> (io.csr_reg_read_data | 8.U), // csrrsi
|
||||
"b111".U -> (io.csr_reg_read_data & io.reg1_data) // csrrci
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user