Build the firewall in front of an AHB5 subordinate. Refuse transfers by region, security, privilege and memory type, and answer each refusal with a clean two-cycle ERROR.
Hardware context: A firewall in front of one AHB5 subordinate. Implement an AHB5 firewall with region, security, privilege and memory-type rules.
Lesson P4.13 named the memory type and security of every transfer, but nothing acted on them. A firewall does. It sits between the bus and one subordinate and refuses what the system policy forbids.
Write module ahb5_firewall. In each address phase, decide from the address, HNONSEC and HPROT whether the transfer may pass. A transfer that may pass reaches the subordinate untouched, and its answer comes back untouched.
A refused transfer must never reach the subordinate. The firewall answers its data phase itself with the two-cycle ERROR of lesson P4.5. Meanwhile the next address phase waits on the bus. The manager in the fixture keeps the transfer behind an ERROR, so the pipeline keeps moving.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
transfers | 4 | input of each check |
Full specification
module ahb5_firewall (
input logic hclk,
input logic hresetn, // active low
// the address phase from the manager
input logic hsel,
input logic [15:0] haddr,
input logic [1:0] htrans,
input logic hwrite,
input logic [6:0] hprot,
input logic hnonsec,
input logic hready, // the bus HREADY (your hreadyout, fed back)
// to and from the subordinate behind you
output logic hsel_s,
input logic hreadyout_s,
input logic hresp_s,
input logic [31:0] hrdata_s,
// the answer the manager sees
output logic hreadyout,
output logic hresp,
output logic [31:0] hrdata
);
// your firewall
endmodule
| Region (haddr[13:12]) | May pass |
|---|---|
| any | Only if HPROT[6:2] is one of the Table 3-7 combinations. |
| 0 | Secure transfers only: HNONSEC = 0. |
| 1 | Device memory only: HPROT[3] = 0. |
| 2 | Reads always; writes only if privileged: HPROT[1] = 1. |
| 3 | Everything. |
An address phase is taken at an edge where HSEL, HTRANS NONSEQ or SEQ, and HREADY are all 1. Its data phase follows until the next edge with HREADY high. The ERROR is HRESP high for two cycles: HREADYOUT low in the first, high in the second.
The result is {done, errs, subordinate_transfers, bad, last_read, ram_sum}. errs has bit i set when transfer i ended with ERROR. bad counts ERRORs of the wrong shape.
Examples
Example 1
The Secure Region- Input
write 0x4 = 11 HPROT 0000011 Secure; write 0x8 = 22 HPROT 0000011 Non-secure; read 0x4 HPROT 0000011 Non-secure; read 0x4 HPROT 0000011 Secure The subordinate: four words per 4 KB region, 0 wait states per transfer
- Output
done = 4, errs = 'b00000110, subordinate_transfers = 2, bad = 0, last_read = 0x11, ram_sum = 0x20088
The Secure write passes. The Non-secure write and read get ERROR and never reach the RAM. The last, Secure read returns 11.
Example 2
Device Memory Only- Input
write 0x1004 = 33 HPROT 0000011 Non-secure; write 0x1008 = 44 HPROT 0001011 Secure; read 0x1004 HPROT 1111111 Non-secure; read 0x1004 HPROT 0000001 Non-secure The subordinate: four words per 4 KB region, 0 wait states per transfer
- Output
done = 4, errs = 'b00000110, subordinate_transfers = 2, bad = 0, last_read = 0x33, ram_sum = 0x200a6
Transfers with HPROT[3] set are refused, whatever their security. The two Device transfers pass.
Example 3
Not Permitted Anywhere- Input
write 0x3004 = 77 HPROT 1000011 Secure; write 0x3008 = 88 HPROT 0001011 Non-secure; read 0x3008 HPROT 0010011 Secure The subordinate: four words per 4 KB region, 0 wait states per transfer
- Output
done = 3, errs = 'b00000101, subordinate_transfers = 1, bad = 0, last_read = 0x0, ram_sum = 0x200f2
HPROT 1000011 is Shareable Device memory, which Table 3-7 does not list. It is refused even in the open region.
Constraints and Contract
- Keep the module name and the ports. hready is your own hreadyout, fed back as the bus HREADY.
- The subordinate answers OKAY with 0 to 2 wait states and never ERROR. Every transfer is a single NONSEQ word.
- Do not reach outside your ports.
Hints
Hint 1
The decision can be combinational on the address phase signals. Gate the subordinate's HSEL with it.
Hint 2
Register "this data phase is refused" at the edge where the address phase is taken. Then a second flag for the second ERROR cycle.
Hint 3
In a refused data phase, drive HREADYOUT and HRESP yourself; otherwise pass the subordinate's.
What the grader checks: Your firewall runs nine scripts of up to eight transfers across the four regions. They mix Secure, Non-secure, Device, Normal and not-permitted attributes, IDLE gaps and 0 to 2 wait states. Responses, subordinate traffic, the ERROR shape and the data are compared with a model.
9 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 1 steps and the final capstone