Compare commits
5
Commits
31aceb7136
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6796c62e27 | ||
|
|
3a9295628d | ||
|
|
76348f8bbf | ||
|
|
c53b63108c | ||
|
|
6780f10461 |
Binary file not shown.
|
After Width: | Height: | Size: 51 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 71 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 75 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 170 KiB |
Binary file not shown.
@@ -585,6 +585,136 @@ module cpu_tb_top;
|
|||||||
};
|
};
|
||||||
run_directed("duplicate_store_beq_test", prog);
|
run_directed("duplicate_store_beq_test", prog);
|
||||||
|
|
||||||
|
// test derived from bug hunt SEED=3333
|
||||||
|
// incorrect sw addr
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADD), .rd(2), .rs1(5), .rs2(3)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(18), .rs1(1), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(15), .rs1(1), .rs2(3)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(12), .imm(1703)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(4), .rs1(12), .rs2(0)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(6), .rs1(28), .rs2(7)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(6), .rs1(1), .rs2(6)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(10), .rs2(4), .imm(1524)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(7), .imm(1309)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(6), .rs1(4), .rs2(7)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(4), .rs2(1), .imm(8)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(9), .rs2(6), .imm(36)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(24), .rs1(0), .rs2(13)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(7), .imm(2039)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(4), .rs1(5), .rs2(6)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(6), .rs1(22), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(6), .rs1(12), .rs2(4)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(6), .rs2(6), .imm(64)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(6), .rs2(3), .imm(496)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(11), .rs2(3), .imm(108)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(10), .rs1(0), .rs2(29)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(5), .rs1(9), .rs2(5)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(10), .rs1(4), .rs2(17)),
|
||||||
|
asm_instr(.op(OP_SUB), .rd(27), .rs1(0), .rs2(5)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(14), .rs2(1), .imm(48)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(19), .rs2(7), .imm(76)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(3), .rs1(2), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(7), .rs1(0), .imm(828)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(3), .rs1(3), .rs2(23)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(0), .rs1(3), .rs2(15)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(6), .rs1(4), .imm(997)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(14), .rs1(2), .imm(-1297)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(5), .rs2(7), .imm(56)),
|
||||||
|
asm_instr(.op(OP_SUB), .rd(0), .rs1(7), .rs2(0)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(5), .rs1(6), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(4), .rs1(15), .rs2(1)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(4), .rs1(0), .imm(1576)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(9), .rs1(7), .rs2(7)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(4), .rs1(1), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(9), .rs1(7), .rs2(1)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(6), .rs1(6), .rs2(7)),
|
||||||
|
asm_instr(.op(OP_SUB), .rd(7), .rs1(6), .rs2(28)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(5), .rs1(24), .rs2(6)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(4), .rs1(4), .imm(765)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(2), .rs1(3), .rs2(4)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(6), .rs2(4), .imm(12)),
|
||||||
|
asm_instr(.op(OP_SUB), .rd(23), .rs1(0), .rs2(12)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(2), .rs1(4), .rs2(24)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(1), .rs2(3), .imm(213)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("incorrect_store_bug", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(2039)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(1), .rs2(0), .imm(213)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sw_addr_carry_bit8_orig", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(252)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(1), .rs2(1), .imm(8)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sw_addr_carry_bit8_aligned", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(100)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(1), .rs2(1), .imm(8)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sw_addr_no_carry_control", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(255)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(1), .imm(1)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(2), .imm(0)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("alu_carry_bit8", prog);
|
||||||
|
|
||||||
|
// test derived from bug hunt SEED=4444
|
||||||
|
// hault prior to last sw
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_SLL), .rd(4), .rs1(1), .rs2(5)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(0), .rs1(21), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(31), .rs1(5), .rs2(7)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(7), .rs1(5), .imm(2032)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(7), .rs2(3), .imm(8)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(31), .rs2(9), .imm(1644)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(8), .rs2(26), .imm(8)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(5), .rs2(3), .imm(4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("hault_prior_to_sw", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(0)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(2), .rs1(0), .imm(0)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(2), .rs2(0), .imm(8)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("lw_use_beq", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(0)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(2), .rs1(0), .imm(0)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(0), .rs1(0), .imm(0)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(2), .rs2(0), .imm(8)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("lw_nop_beq_control", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(5)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(0)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(2), .rs1(0), .imm(0)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(3), .rs1(2), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(3), .imm(4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("lw_use_alu", prog);
|
||||||
// CHIP-LEVEL DIRECTED TESTS
|
// CHIP-LEVEL DIRECTED TESTS
|
||||||
run_reset_while_running();
|
run_reset_while_running();
|
||||||
run_external_halt();
|
run_external_halt();
|
||||||
|
|||||||
+258
-14
@@ -19,10 +19,10 @@ instructions and disappear from rendered Markdown.
|
|||||||
|
|
||||||
### Revision history
|
### Revision history
|
||||||
|
|
||||||
| Revision | Date | Changes |
|
| Revision | Date | Changes |
|
||||||
| -------- | ---------- | ----------------------------------------------------------------------- |
|
| -------- | ---------- | ------------------------------------------- |
|
||||||
| Initial | 2026-09-26 | Initial planned tests |
|
| Initial | 2026-09-26 | Initial planned tests |
|
||||||
| Final | 2026-09-29 | <!-- Tests or constraints added after debugging and coverage review --> |
|
| Final | 2026-09-29 | Added tests, completed coverage, found bugs |
|
||||||
|
|
||||||
## 1. Functional tests
|
## 1. Functional tests
|
||||||
|
|
||||||
@@ -1295,10 +1295,10 @@ evidence from a temporary violation proving that the assertion can fire.
|
|||||||
|
|
||||||
### Assertion summary
|
### Assertion summary
|
||||||
|
|
||||||
| Assertion ID/name | Behavior checked | When it is sampled/disabled | Activating test |
|
| Assertion ID/name | Behavior checked | When it is sampled/disabled | Activating test |
|
||||||
| ------------------------- | ------------------- | --------------------------- | --------------- |
|
| ---------------------------- | ------------------- | --------------------------- | --------------- |
|
||||||
| 3.1 / `X0_REMAINS_0` | x0 = 0 | posedge clk | lw_x0 |
|
| 3.1 / `X0_REMAINS_0` | x0 = 0 | posedge clk | lw_x0 |
|
||||||
| 3.2 / `NO_RW_CONCURRENCY` | !(w_en_i && r_en_i) | posedge clk | |
|
| 3.2 / `STABLE_WHEN_DISABLED` | !(w_en_i && r_en_i) | posedge clk | |
|
||||||
|
|
||||||
### 3.1 — `X0_REMAINS_0`
|
### 3.1 — `X0_REMAINS_0`
|
||||||
|
|
||||||
@@ -1312,6 +1312,7 @@ X0_REMAINS_0:
|
|||||||
```
|
```
|
||||||
|
|
||||||
**Evidence that it detects a violation:** <!-- Temporary change, failing log/waveform, and confirmation after reverting it. -->
|
**Evidence that it detects a violation:** <!-- Temporary change, failing log/waveform, and confirmation after reverting it. -->
|
||||||
|
![[Pasted image 20261007192000.png]]
|
||||||
|
|
||||||
### 3.2 — `STABLE_WHEN_DISABLED`
|
### 3.2 — `STABLE_WHEN_DISABLED`
|
||||||
|
|
||||||
@@ -1327,15 +1328,17 @@ STABLE_WHEN_DISABLED :
|
|||||||
```
|
```
|
||||||
|
|
||||||
**Evidence that it detects a violation:**
|
**Evidence that it detects a violation:**
|
||||||
|
![[Pasted image 20261007192402.png]]
|
||||||
|
|
||||||
## 4. Encrypted CPU Bug Hunt
|
## 4. Encrypted CPU Bug Hunt
|
||||||
### Random discovery
|
### Random discovery
|
||||||
|
##### 4.1 Bug 1 - Duplicate Store
|
||||||
|
|
||||||
| Field | Evidence |
|
| Field | Evidence |
|
||||||
| ------------------------ | ------------------------------------------------------------------------------ |
|
| ------------------------ | ------------------------------------------------------------------------------ |
|
||||||
| Discovery command | `make bug_hunt SEED=random` |
|
| Discovery command | `make bug_hunt SEED=random` |
|
||||||
| Numeric `SVSEED` | 2222 |
|
| Numeric `SVSEED` | 2222 |
|
||||||
| Failing iteration | 0 |
|
| Failing iteration | CPU 0 - random gen 17 |
|
||||||
| First failure message | unexpected store to dmem[0x0fb] = 0x00000000 with no predicted store remaining |
|
| First failure message | unexpected store to dmem[0x0fb] = 0x00000000 with no predicted store remaining |
|
||||||
| Reproduction command | `make bug_hunt SEED=2222` |
|
| Reproduction command | `make bug_hunt SEED=2222` |
|
||||||
| Reproduces consistently? | Yes |
|
| Reproduces consistently? | Yes |
|
||||||
@@ -1371,11 +1374,13 @@ run_directed("duplicate_store_beq", prog);
|
|||||||
|
|
||||||
### Expected vs. actual
|
### Expected vs. actual
|
||||||
|
|
||||||
| Instruction / event | Expected | Actual | Cycle/time |
|
| Instruction / event | Expected | Actual | Cycle/time |
|
||||||
| ------------------- | ---------- | ------------------------- | ---------- |
|
| ------------------------------------------------------------ | ----------------------------------- | ------------------------------------------------------- | ---------- |
|
||||||
| sw x1, 1004(x1) | 0x00000000 | 0x00000000 (stored twice) | |
|
| `sw x1, 1004(x1)` (seed 2222) | one write: dmem[0x0fb] = 0x00000000 | two writes to dmem[0x0fb]; second flagged as unexpected | |
|
||||||
|
| `sw x1, 8(x1)`, x1 = 100 (`sw_addr_no_carry_control`) | one write: dmem[0x01b] = 0x00000064 | two writes to dmem[0x01b]; second flagged as unexpected | 133815 ns |
|
||||||
|
| `sw x2, 540(x4)` as first instruction (`random_gen_7_len_4`) | one write: dmem[0x087] = 0x00000000 | two writes to dmem[0x087]; second flagged as unexpected | 520395 ns |
|
||||||
|
|
||||||
**First architectural divergence:** duplicate SW when one is expected after a branch is taken
|
**First architectural divergence:** the first `sw` is written to data memory twice. The scoreboard predicts one store, so the second write is reported as an unexpected store with no predicted store remaining. A branch is not required, since a lone `sw` duplicates too.
|
||||||
<!-- State the first register, memory, or control-flow result that becomes incorrect. -->
|
<!-- State the first register, memory, or control-flow result that becomes incorrect. -->
|
||||||
|
|
||||||
### Minimization
|
### Minimization
|
||||||
@@ -1399,7 +1404,7 @@ Include a screenshot showing the offending instruction and the first incorrect a
|
|||||||
|
|
||||||
### Conclusion
|
### Conclusion
|
||||||
|
|
||||||
**Trigger:** sw + beq
|
**Trigger:** any `sw`
|
||||||
|
|
||||||
<!-- Smallest condition that causes the failure. -->
|
<!-- Smallest condition that causes the failure. -->
|
||||||
|
|
||||||
@@ -1415,5 +1420,244 @@ Include a screenshot showing the offending instruction and the first incorrect a
|
|||||||
|
|
||||||
<!-- One precise sentence. Do not speculate about hidden RTL. -->
|
<!-- One precise sentence. Do not speculate about hidden RTL. -->
|
||||||
|
|
||||||
|
##### 4.2 Bug 2 - Incorrect Store Addr
|
||||||
|
|
||||||
|
| Field | Evidence |
|
||||||
|
| ------------------------ | -------------------------------------------------------------------------- |
|
||||||
|
| Discovery command | `make bug_hunt SEED=random` |
|
||||||
|
| Numeric `SVSEED` | 3333 |
|
||||||
|
| Failing iteration | CPU 0 - random gen 5 |
|
||||||
|
| First failure message | store #2 wrote dmem[0x17d] = 0x00000000, expected dmem[0x233] = 0x00000000 |
|
||||||
|
| Reproduction command | `make bug_hunt SEED=3333` |
|
||||||
|
| Reproduces consistently? | Yes |
|
||||||
|
|
||||||
|
**Original failing program:**
|
||||||
|
|
||||||
|
```systemverilog
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADD), .rd(2), .rs1(5), .rs2(3)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(18), .rs1(1), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(15), .rs1(1), .rs2(3)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(12), .imm(1703)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(4), .rs1(12), .rs2(0)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(6), .rs1(28), .rs2(7)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(6), .rs1(1), .rs2(6)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(10), .rs2(4), .imm(1524)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(7), .imm(1309)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(6), .rs1(4), .rs2(7)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(4), .rs2(1), .imm(8)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(9), .rs2(6), .imm(36)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(24), .rs1(0), .rs2(13)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(7), .imm(2039)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(4), .rs1(5), .rs2(6)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(6), .rs1(22), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(6), .rs1(12), .rs2(4)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(6), .rs2(6), .imm(64)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(6), .rs2(3), .imm(496)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(11), .rs2(3), .imm(108)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(10), .rs1(0), .rs2(29)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(5), .rs1(9), .rs2(5)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(10), .rs1(4), .rs2(17)),
|
||||||
|
asm_instr(.op(OP_SUB), .rd(27), .rs1(0), .rs2(5)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(14), .rs2(1), .imm(48)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(19), .rs2(7), .imm(76)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(3), .rs1(2), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(7), .rs1(0), .imm(828)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(3), .rs1(3), .rs2(23)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(0), .rs1(3), .rs2(15)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(6), .rs1(4), .imm(997)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(14), .rs1(2), .imm(-1297)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(5), .rs2(7), .imm(56)),
|
||||||
|
asm_instr(.op(OP_SUB), .rd(0), .rs1(7), .rs2(0)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(5), .rs1(6), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(4), .rs1(15), .rs2(1)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(4), .rs1(0), .imm(1576)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(9), .rs1(7), .rs2(7)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(4), .rs1(1), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(9), .rs1(7), .rs2(1)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(6), .rs1(6), .rs2(7)),
|
||||||
|
asm_instr(.op(OP_SUB), .rd(7), .rs1(6), .rs2(28)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(5), .rs1(24), .rs2(6)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(4), .rs1(4), .imm(765)),
|
||||||
|
asm_instr(.op(OP_SRL), .rd(2), .rs1(3), .rs2(4)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(6), .rs2(4), .imm(12)),
|
||||||
|
asm_instr(.op(OP_SUB), .rd(23), .rs1(0), .rs2(12)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(2), .rs1(4), .rs2(24)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(1), .rs2(3), .imm(213)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("incorrect_store_bug", prog);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Expected vs. actual
|
||||||
|
|
||||||
|
| Instruction / event | Expected | Actual | Cycle/time |
|
||||||
|
| ------------------------------------------- | --------------------------------- | --------------------------------- | ---------- |
|
||||||
|
| `sw x3, 213(x1)`, x1 = 2039 (seed 3333) | store to dmem[0x233] = 0x00000000 | store to dmem[0x1f3] = 0x00000000 | 434845 ns |
|
||||||
|
| `sw x0, 213(x1)`, x1 = 2039 (minimized) | store to dmem[0x233] = 0x00000000 | store to dmem[0x1f3] = 0x00000000 | 131065 ns |
|
||||||
|
| `sw x1, 8(x1)`, x1 = 252 (aligned) | store to dmem[0x041] = 0x000000fc | store to dmem[0x001] = 0x000000fc | 132435 ns |
|
||||||
|
| `sw x1, 8(x1)`, x1 = 100 (no-carry control) | store to dmem[0x01b] = 0x00000064 | store to dmem[0x01b] = 0x00000064 | 133815 ns |
|
||||||
|
|
||||||
|
**First architectural divergence:** the final `sw x3, 213(x1)` writes dmem[0x1f3] instead of dmem[0x233] (x1 = 2039, so the address is 2039 + 213 = 0x8CC, word 0x233). The first error in the log (store #2 wrote dmem[0x17d]) is the duplicate-store bug shifting the store stream, not this bug.
|
||||||
|
<!-- State the first register, memory, or control-flow result that becomes incorrect. -->
|
||||||
|
|
||||||
|
### Minimization
|
||||||
|
|
||||||
|
**Minimized reproducer:**
|
||||||
|
|
||||||
|
```systemverilog
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(2039)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(1), .rs2(0), .imm(213)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sw_addr_carry_bit8_orig", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(252)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(1), .rs2(1), .imm(8)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sw_addr_carry_bit8_aligned", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(100)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(1), .rs2(1), .imm(8)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("sw_addr_no_carry_control", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(255)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(2), .rs1(1), .imm(1)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(2), .imm(0)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("alu_carry_bit8", prog);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Waveform evidence
|
||||||
|
|
||||||
|
Include a screenshot showing the offending instruction and the first incorrect architectural result.
|
||||||
|
![[Pasted image 20261007184043.png]]
|
||||||
|
|
||||||
|
### Conclusion
|
||||||
|
|
||||||
|
**Trigger:** imm in sw causes some type of bit mismatch, the addresses are all off by 0x100 bytes
|
||||||
|
|
||||||
|
<!-- Smallest condition that causes the failure. -->
|
||||||
|
|
||||||
|
**Expected behavior:** addr is computed correctly
|
||||||
|
|
||||||
|
<!-- ISA-correct behavior. -->
|
||||||
|
|
||||||
|
**Observed behavior:** store goes to sum without the carry from bit 7 to bit 8
|
||||||
|
|
||||||
|
<!-- What the encrypted CPU does instead. -->
|
||||||
|
|
||||||
|
**Behavioral characterization:** the ALU is computing the correct address, but somewhere the bit carry when using the store address is lost
|
||||||
|
|
||||||
|
<!-- One precise sentence. Do not speculate about hidden RTL. -->
|
||||||
|
|
||||||
|
##### 4.3 Bug 3 - Stale Branch Operand
|
||||||
|
|
||||||
|
| Field | Evidence |
|
||||||
|
| ------------------------ | ----------------------------------------------------- |
|
||||||
|
| Discovery command | `make bug_hunt SEED=random` |
|
||||||
|
| Numeric `SVSEED` | 4444 |
|
||||||
|
| Failing iteration | CPU 0 - random gen 39 |
|
||||||
|
| First failure message | CPU halted with 1 predicted store(s) still unobserved |
|
||||||
|
| Reproduction command | `make bug_hunt SEED=4444` |
|
||||||
|
| Reproduces consistently? | Yes |
|
||||||
|
|
||||||
|
**Original failing program:**
|
||||||
|
|
||||||
|
```systemverilog
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_SLL), .rd(4), .rs1(1), .rs2(5)),
|
||||||
|
asm_instr(.op(OP_SLL), .rd(0), .rs1(21), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(31), .rs1(5), .rs2(7)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(7), .rs1(5), .imm(2032)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(7), .rs2(3), .imm(8)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(31), .rs2(9), .imm(1644)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(8), .rs2(26), .imm(8)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(5), .rs2(3), .imm(4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("halt_prior_to_sw", prog);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Expected vs. actual
|
||||||
|
|
||||||
|
| Instruction / event | Expected | Actual | Cycle/time |
|
||||||
|
| ---------------------------------------------------------- | --------------------------------------------------------- | ----------------------------------------------------------------- | ---------- |
|
||||||
|
| `beq x7, x3, 8` after `lw x7, 2032(x5)` (seed 4444) | not taken; `sw x9, 1644(x31)` writes dmem[0x19b] | branch taken; no write to dmem[0x19b] | 1903595 ns |
|
||||||
|
| `lw x2, 0(x0)` then `beq x2, x0, 8`, x2 = 1 (`lw_use_beq`) | not taken; `sw x1, 4(x0)` writes dmem[0x001] = 0x00000001 | branch taken; dmem[0x001] = 0x000000fc after halt (never written) | 138225 ns |
|
||||||
|
| same with a nop between (`lw_nop_beq_control`) | `sw x1, 4(x0)` writes dmem[0x001] = 0x00000001 | dmem[0x001] = 0x00000001 written | 139705 ns |
|
||||||
|
| `lw x2, 0(x0)` then `add x3, x2, x2` (`lw_use_alu`) | stored value 0x0000000a | stored value 0x0000000a | 141185 ns |
|
||||||
|
|
||||||
|
**First architectural divergence:** the `beq` that follows the `lw` is taken, so the `sw` after it is skipped. The CPU then reaches `ebreak` and the scoreboard reports a predicted store that was never observed.
|
||||||
|
<!-- State the first register, memory, or control-flow result that becomes incorrect. -->
|
||||||
|
|
||||||
|
### Minimization
|
||||||
|
|
||||||
|
**Minimized reproducer:**
|
||||||
|
|
||||||
|
```systemverilog
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(0)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(2), .rs1(0), .imm(0)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(2), .rs2(0), .imm(8)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("lw_use_beq", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(1)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(0)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(2), .rs1(0), .imm(0)),
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(0), .rs1(0), .imm(0)),
|
||||||
|
asm_instr(.op(OP_BEQ), .rs1(2), .rs2(0), .imm(8)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("lw_nop_beq_control", prog);
|
||||||
|
|
||||||
|
prog = '{
|
||||||
|
asm_instr(.op(OP_ADDI), .rd(1), .rs1(0), .imm(5)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(1), .imm(0)),
|
||||||
|
asm_instr(.op(OP_LW), .rd(2), .rs1(0), .imm(0)),
|
||||||
|
asm_instr(.op(OP_ADD), .rd(3), .rs1(2), .rs2(2)),
|
||||||
|
asm_instr(.op(OP_SW), .rs1(0), .rs2(3), .imm(4)),
|
||||||
|
EBREAK_WORD
|
||||||
|
};
|
||||||
|
run_directed("lw_use_alu", prog);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Waveform evidence
|
||||||
|
|
||||||
|
Include a screenshot showing the offending instruction and the first incorrect architectural result.
|
||||||
|
![[Pasted image 20261007190107.png]]
|
||||||
|
|
||||||
|
### Conclusion
|
||||||
|
|
||||||
|
**Trigger:** lw followed by beq that uses the same register as a source
|
||||||
|
|
||||||
|
<!-- Smallest condition that causes the failure. -->
|
||||||
|
|
||||||
|
**Expected behavior:** branch isn’t taken in this case, and sw executes
|
||||||
|
|
||||||
|
<!-- ISA-correct behavior. -->
|
||||||
|
|
||||||
|
**Observed behavior:** branch is taken, and the CPU early halts
|
||||||
|
|
||||||
|
<!-- What the encrypted CPU does instead. -->
|
||||||
|
|
||||||
|
**Behavioral characterization:** branch reads the register prior to the completion of the lw
|
||||||
|
|
||||||
|
<!-- One precise sentence. Do not speculate about hidden RTL. -->
|
||||||
|
|
||||||
### 5. Code coverage >98% for cpu_tb_top
|
### 5. Code coverage >98% for cpu_tb_top
|
||||||
![[Pasted image 20261006143238.png]]
|
![[Pasted image 20261006143238.png]]
|
||||||
Reference in New Issue
Block a user