Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Update interrupt vector table description #268

Open
DanieleParravicini-Synthara opened this issue May 23, 2024 · 19 comments
Open

[BUG] Update interrupt vector table description #268

DanieleParravicini-Synthara opened this issue May 23, 2024 · 19 comments
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@DanieleParravicini-Synthara
Copy link

DanieleParravicini-Synthara commented May 23, 2024

Bug Description

The CVE2 documentation read online at ReadTheDocs at cve2-user-manual/en/latest/internal says that CVE2 should start at [boot_addr_i + 0x80] (https://docs.openhwgroup.org/projects/cve2-user-manual/en/latest/02_user/integration.html#interfaces) but I do not find any information on the interrupt vector table.

We tried to use a vector table that was compatible with this other version of Ibex and used its documentation on ReadTheDocs.
But it does not work,

image

As you can see boot_addr_i is set to 0x80000, and the crush_dump_o.current_pc and crush_dump_o.next_pc goes to 0x80000, then to 0x80004, and then 0x800a6 and not to 0x80000+0x80 as indicated in (https://docs.openhwgroup.org/projects/cve2-user-manual/en/latest/02_user/integration.html#interfaces).

Where can I find more information on the interrupt vector table description?

If you are ok we could submit a PR to fix the simple-system firmware to reflect the change.

@MikeOpenHWGroup MikeOpenHWGroup added bug Something isn't working documentation Improvements or additions to documentation labels May 23, 2024
@DanieleParravicini-Synthara
Copy link
Author

DanieleParravicini-Synthara commented May 24, 2024

MAYBE: comparing cve2_if_stage.sv with ibex_if_stage.sv it seems that the CVE2 starts boot_addr_i and not at boot_addr_i+0x80.

looking further it seems that the old ibex has 32 irq, or 32 addresses in the IRQ vector table whereas the CVE2 seems to have 64 "IRQS": 32 dedicated to actual IRQ and other 32 for exc, right?

so we can say that IRQ[0] is actually the boot address. correct?

@DanieleParravicini-Synthara
Copy link
Author

DanieleParravicini-Synthara commented Jun 5, 2024

If you are ok with that I could create a PR that updates the documentation

@davideschiavone
Copy link

yes that would be very welcome :)

@DanieleParravicini-Synthara
Copy link
Author

Noice, but do you think that the intuition is correct?

MAYBE: comparing cve2_if_stage.sv with ibex_if_stage.sv it seems that the CVE2 starts boot_addr_i and not at boot_addr_i+0x80.

looking further it seems that the old ibex has 32 irq, or 32 addresses in the IRQ vector table whereas the CVE2 seems to have 64 "IRQS": 32 dedicated to actual IRQ and other 32 for exc, right?

so we can say that IRQ[0] is actually the boot address. correct?

@davideschiavone
Copy link

yes it has been done here: be70b26

@DanieleParravicini-Synthara
Copy link
Author

so combining page 43 of Volume 2, Privileged Specification version 20240411 and [cve2 repo e.g. cve2_pkg, cve2_controller]:(

typedef enum logic [6:0] {
):

  • IRQ0 is reserved
  • IRQ3 is software IRQ
  • IRQ7 is for timer
  • IRQ11 is for machine external interrupts
  • IRQ>16 and above are considered customs and in the case of CVE2:
  • IRQ16-IRQ31 are used for 16 irq_fast
  • IRQ32 is non maskable IRQ

so the vector interrupt table is as follows ( the addresses are indicated as word offset from the mtvec or boot_addr):

offset description
0 boot
1-2 reserved
3 IRQ
4-6 reserved
7 irq timer
8 - 10 reserved
11 irq external
12-15 reserved
16-31 16 fast local interrupt
32 non maskable interrupt

so the vector table starts at boot_addr and arrives till 0x7C (included)

@DanieleParravicini-Synthara
Copy link
Author

can you please confirm?

@DanieleParravicini-Synthara
Copy link
Author

a wait, the exception are also "multiplexed" on this vector table, right?

@DanieleParravicini-Synthara
Copy link
Author

I am not so sure because I can see some overlapping in the exc_cause_e:

  • EXC_CAUSE_BREAKPOINT = {1'b0, 6'd03} and EXC_CAUSE_IRQ_SOFTWARE_M = {1'b1, 6'd03},
  • EXC_CAUSE_STORE_ACCESS_FAULT = {1'b0, 6'd07} and EXC_CAUSE_IRQ_TIMER_M = {1'b1, 6'd07},
  • EXC_CAUSE_ECALL_MMODE = {1'b0, 6'd11} and EXC_CAUSE_IRQ_EXTERNAL_M = {1'b1, 6'd11},

@davideschiavone
Copy link

interrupts are not related to the boot address, when an interrupt occurs you jump to the address pointed by the mtvec CSR

https://github.com/openhwgroup/cve2/blob/main/rtl/cve2_if_stage.sv#L124C23-L124C29

@DanieleParravicini-Synthara
Copy link
Author

but mtvec is set to boot_addr at boot right, no?

mtvec_d = csr_mtvec_init_i ? {boot_addr_i[31:8], 6'b0, 2'b01} :

@davideschiavone
Copy link

only at reset state, so you can imagine the boot_address being the reset value of the mtvec, the reason that is not the reset value itself is that you do not want to reset a flip flop with a NON CONSTANT (as boot address is an input signal) value

@DanieleParravicini-Synthara
Copy link
Author

very right, thanks.
The vector table itself, you think I got the gist?

You have entries in the vector interrupt table that mix exceptions and interrupts?

@DanieleParravicini-Synthara
Copy link
Author

I think I made a mistake: so the vector table starts at boot_addr and arrives till 0x80 (included)

@DanieleParravicini-Synthara
Copy link
Author

DanieleParravicini-Synthara commented Jun 7, 2024

Something like this #273 ?

@davideschiavone
Copy link

#273 seems indeed correct, but you modifed the RTL of the controller - can you pls revert it back? thanks @DanieleParravicini-Synthara

@DanieleParravicini
Copy link

Sure, my bad apologies

@DanieleParravicini-Synthara
Copy link
Author

Hello @davideschiavone, I fixed a typo and added a new line of comments on cve2_controller.sv.
I think my editor config got in the way and used LF instead of CRLF, so that was the reason it seemed the entire cve2_controller.sv was touched. I reformatted the file and pushed, if you prefer I can remove it.
Maybe this will trigger some regression on CI.
Let me know

@DanieleParravicini-Synthara
Copy link
Author

DanieleParravicini-Synthara commented Jun 11, 2024

I am not sure I understand correctly, so apologies if I don't get it right.

EXC_PC_IRQ: exc_pc = { csr_mtvec_i[31:8], irq_id[5:0], 2'b00 };

is used only for IRQs.

If an exception happens it gets stored in exc_req_q and then during FLUSH,

if (exc_req_q || store_err_q || load_err_q) begin

depending on debug_mode_q

exc_pc_mux_o = debug_mode_q ? EXC_PC_DBG_EXC : EXC_PC_EXC;

exc_pc_mux_o is set to a value that then results in one of the following two:

EXC_PC_EXC: exc_pc = { csr_mtvec_i[31:8], 8'h00 };

EXC_PC_DBG_EXC: exc_pc = DmExceptionAddr;

This reflects The RISC-V Instruction Set Manual: Volume II: Priviledged Architecture :
When MODE=Vectored, all synchronous exceptions into machine mode cause the pc to be set
to the address in the BASE field, whereas interrupts cause the pc to be set to the address in the
BASE field plus four times the interrupt cause number

So, #273 is wrong and

should be exception handler. Correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants