Skip to content

Commit ac1fe39

Browse files
committed
priv jal
1 parent db2787a commit ac1fe39

6 files changed

Lines changed: 40 additions & 15 deletions

File tree

env/riscv-arch-test/ceres/model_test.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,32 @@
4242
rvtest_trap_handler: \
4343
csrr t0, mcause; \
4444
csrr t1, mepc; \
45-
li t2, 3; /* EBREAK mcause */ \
45+
/* Check EBREAK (mcause = 3) */ \
46+
li t2, 3; \
4647
bne t0, t2, 1f; \
47-
lhu t3, 0(t1); /* Load instruction */ \
48-
andi t3, t3, 0x3; /* Check if compressed */ \
48+
/* EBREAK: check if compressed */ \
49+
lhu t3, 0(t1); \
50+
andi t3, t3, 0x3; \
4951
li t4, 0x3; \
50-
beq t3, t4, 2f; /* If 0x3, it's 32-bit */ \
52+
beq t3, t4, 2f; \
5153
addi t1, t1, 2; /* Compressed: PC += 2 */ \
5254
j 3f; \
5355
2: addi t1, t1, 4; /* 32-bit: PC += 4 */ \
5456
3: csrw mepc, t1; \
5557
mret; \
56-
1: li t2, 11; /* ECALL mcause */ \
58+
1: /* Check ECALL (mcause = 11) */ \
59+
li t2, 11; \
5760
bne t0, t2, 4f; \
58-
j halt_loop; /* ECALL = halt */ \
59-
4: addi t1, t1, 4; /* Unknown: skip 4 bytes */ \
61+
/* ECALL: check if it's exit syscall (a7 = 93) */ \
62+
li t2, 93; \
63+
bne a7, t2, 5f; \
64+
j halt_loop; /* Exit syscall = halt */ \
65+
5: /* Normal ECALL: advance PC and return */ \
66+
addi t1, t1, 4; \
67+
csrw mepc, t1; \
68+
mret; \
69+
4: /* Other exceptions: advance PC and return */ \
70+
addi t1, t1, 4; \
6071
csrw mepc, t1; \
6172
mret; \
6273
_rvtest_boot_continue: \

rtl/core/cpu.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ module cpu
598598
end
599599
excp_mask = '0;
600600
excp_mask = {1'b0, ex_exc_type != NO_EXCEPTION, de_active_exc_type != NO_EXCEPTION, fe_active_exc_type != NO_EXCEPTION};
601-
fe_trap_active = |{excp_mask[3:1], pipe1.exc_type != NO_EXCEPTION};
601+
fe_trap_active = |{excp_mask[3:1], de_active_exc_type != NO_EXCEPTION};
602602
trap_active = |excp_mask[3:1];
603603
de_trap_active = de_active_exc_type != NO_EXCEPTION;
604604
priority_flush = ex_exc_type != NO_EXCEPTION ? 3:

rtl/core/stage01_fetch/compressed_decoder.sv

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ module compressed_decoder
225225

226226
3'b010: begin
227227
// C.LI: addi rd, x0, imm
228+
// Note: rd=x0 is HINT (valid, treated as NOP)
228229
c1_instr = gen_i_type(get_imm_ci(), REG_ZERO, FUNCT3_ADD, rd_rs1_full, OPCODE_OPIMM);
229-
if (rd_rs1_full == REG_ZERO) c1_illegal = 1'b1; // rd=x0 is reserved
230230
end
231231

232232
3'b011: begin
@@ -235,10 +235,12 @@ module compressed_decoder
235235
c1_instr = gen_i_type(get_imm_addi16sp(), REG_SP, FUNCT3_ADD, REG_SP, OPCODE_OPIMM);
236236
end else begin
237237
// C.LUI: lui rd, nzimm
238+
// Note: rd=x0 is HINT (valid, treated as NOP)
238239
c1_instr = gen_u_type(get_imm_lui(), rd_rs1_full, OPCODE_LUI);
239240
end
240241
// Check for reserved encodings
241-
if (rd_rs1_full == REG_ZERO) c1_illegal = 1'b1;
242+
// Note: rd=x0 case goes to C.LUI which is HINT, not illegal
243+
// But nzimm=0 is reserved for both C.ADDI16SP and C.LUI
242244
if ({instr_i[12], instr_i[6:2]} == 6'b0) c1_illegal = 1'b1; // nzimm=0 is reserved
243245
end
244246

@@ -316,8 +318,8 @@ module compressed_decoder
316318
case (funct3)
317319
3'b000: begin
318320
// C.SLLI: slli rd, rd, shamt
321+
// Note: rd=x0 is HINT (valid, treated as NOP)
319322
c2_instr = gen_i_type({7'b0, get_shamt()}, rd_rs1_full, FUNCT3_SLL, rd_rs1_full, OPCODE_OPIMM);
320-
if (rd_rs1_full == REG_ZERO) c2_illegal = 1'b1; // rd=x0 is reserved
321323
if (instr_i[12] || get_shamt() == 5'b0) c2_illegal = 1'b1; // shamt[5]=1 or shamt=0 is reserved
322324
end
323325

rtl/core/stage01_fetch/fetch.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module fetch
5757
icache_req_t abuff_icache_req; // Raw request from align_buffer
5858
icache_req_t icache_req; // Gated request to cache
5959
blowX_res_t buff_lowX_res;
60+
logic buf_lookup_ack;
6061

6162
// ============================================================================
6263
// PC Register: Program Counter yönetimi
@@ -198,7 +199,6 @@ module fetch
198199
end
199200

200201
// Track pending request to icache - reset on response or new request from buffer
201-
logic buf_lookup_ack;
202202
/* verilator lint_off UNUSEDSIGNAL */
203203
logic prev_icache_req_valid;
204204
/* verilator lint_on UNUSEDSIGNAL */

rtl/include/writeback_log.svh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ end
120120
// ============================================================
121121
// 3) REGISTER WRITE ONLY (normal ALU, load result, jump-link, etc.)
122122
// ============================================================
123-
else if (instr_type_i inside {i_lb, i_lh, i_lw, i_lbu, i_lhu}) begin
123+
else if (instr_type_i inside {i_lb, i_lh, i_lw, i_lbu, i_lhu} && rd_addr_i != 0) begin
124124
automatic string spacing = (rd_addr_i < 10) ? " " : " ";
125125
$fwrite(trace_fd,
126126
"core 0: 3 0x%08h (0x%08h) x%0d%s0x%08h mem 0x%08h\n",
@@ -130,6 +130,15 @@ end
130130
);
131131
end
132132

133+
// Load to x0 - just log memory access without register write
134+
else if (instr_type_i inside {i_lb, i_lh, i_lw, i_lbu, i_lhu} && rd_addr_i == 0) begin
135+
$fwrite(trace_fd,
136+
"core 0: 3 0x%08h (0x%08h) mem 0x%08h\n",
137+
pc_i, fe_tracer_i.inst,
138+
alu_result_i
139+
);
140+
end
141+
133142
else if (rf_rw_en_i && rd_addr_i != 0) begin
134143
automatic string spacing = (rd_addr_i < 10) ? " " : " ";
135144
$fwrite(trace_fd,
@@ -258,13 +267,16 @@ task automatic check_pass_fail();
258267
end
259268
endtask
260269

270+
// TOHOST check - only for riscv-tests (isa tests), not arch tests
271+
// When addr_check_enabled is true, pass/fail is determined by PC addresses
272+
// When addr_check_enabled is false, use TOHOST memory-mapped register
261273
always @(posedge clk_i) begin
262274
automatic logic we = wr_en_i;
263275
automatic logic valid = `SOC.pipe4.dcache_valid;
264276
automatic logic [31:0] addr = `SOC.pipe4.alu_result;
265277
automatic logic [31:0] data = `SOC.pipe4.write_data;
266278

267-
if (addr_check_enabled && valid && we && addr == 32'h80001000) begin
279+
if (!addr_check_enabled && valid && we && addr == 32'h80001000) begin
268280
if (data == 32'h1) begin
269281
$display("🎉 TOHOST PASS");
270282
$finish;

rtl/wrapper/ceres_wrapper.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module ceres_wrapper
3434
parameter int unsigned BAUD_RATE = 115200,
3535

3636
// Memory Configuration
37-
parameter int unsigned RAM_SIZE_KB = 128,
37+
parameter int unsigned RAM_SIZE_KB = 1024,
3838
parameter int unsigned RAM_LATENCY = 16,
3939

4040
// Peripheral Configuration

0 commit comments

Comments
 (0)