A linker left two tables in Boot ROM: regions to copy and regions to clear. Write the start-up code that walks both and then calls main.
Hardware context: Start-up code in Boot ROM on a small processor model, checked against the real ap_rv32. Bare-metal firmware start-up
A larger program has several regions of initialized data and several regions that must start at 0. Its linker script writes them into two tables in Boot ROM.
Write the start-up code, from address 0, as rows of instructions. It sets the stack pointer and the trap vector, walks both tables, calls main, and stops if main returns.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
trial | 8 | input of each check |
Full specification
| Table | One entry | The table ends |
|---|---|---|
| Copy table, at COPY_TABLE | three words: the load address, the first run address, the end address | at an entry whose end address is 0 |
| Zero table, at ZERO_TABLE | two words: the first address, the end address | at an entry whose end address is 0 |
| Item | Value |
|---|---|
| sp, which is x2 | STACK_TOP |
| mtvec | TRAP |
| Every word of every region of the copy table | the word at the same place of its load image |
| Every word of every region of the zero table | 0 |
| Every other word of SRAM | untouched |
Call main with "jal x1, MAIN". If main returns, the code must stay in a loop of one jump to itself.
| Form | Meaning |
|---|---|
| i(LUI, a, 0, c) | x[a] = c shifted left by 12. c has at most 20 bits. |
| i(ADDI, a, b, c) | x[a] = x[b] + c. c is from -2048 to 2047. |
| i(LW, a, b, c) and i(SW, a, b, c) | load x[a] from, or store x[a] to, the address x[b] + c |
| i(BEQ, a, b, c), BNE, BLT, BGE | compare x[a] with x[b]; if true, go to address c |
| i(JAL, a, 0, c) | x[a] = the address of the next row; go to address c |
| i(JALR, a, b, c) | x[a] = the address of the next row; go to x[b] + c |
| i(CSRW, a, 0, MTVEC) | mtvec = x[a] |
Examples
Example 1
One Region to Copy and One to Clear- Input
Parameter set 1; one region to copy and one to clear
- Output
stops_after_main = 1, no_exception = 1, main_called_once = 1, sp = 1, mtvec = 1, copied = 1, cleared = 1, rest_untouched = 1
One region of two words is copied and one of two words is cleared.
Example 2
Two Regions in Each Table- Input
Parameter set 2; two regions in each table
- Output
stops_after_main = 1, no_exception = 1, main_called_once = 1, sp = 1, mtvec = 1, copied = 1, cleared = 1, rest_untouched = 1
Two entries in each table. The second parameter set moves the tables, main, the handler and the stack.
Example 3
Two Empty Tables- Input
Parameter set 1; two empty tables
- Output
stops_after_main = 1, no_exception = 1, main_called_once = 1, sp = 1, mtvec = 1, copied = 1, cleared = 1, rest_untouched = 1
Both tables hold only their closing entry. Nothing is copied or cleared, and main is still called once.
Constraints and Contract
- Keep module my_startup, its five parameters and the declarations below the task. Change only the rows of the_program.
- Use the parameters for every address. The bench builds the module twice, with different values. At most 128 rows.
Hints
Hint 1
Write the walk of one table first. Read an entry, test its end address for 0, handle the region, and step to the next entry.
Hint 2
Test for an empty region before the first word, not after it.
Hint 3
STACK_TOP is a multiple of 4096, so one lui gives it. The other parameters are below 2048.
What the grader checks: Each trial fills SRAM with words that are not 0 and builds both tables. It looks at the whole SRAM, sp and mtvec at the moment main starts. Trials cover empty tables, empty regions, long regions and regions at the top of SRAM, with two sets of parameters. Timing is not checked.
14 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path