Beginner trying to set up timer IRQ in assembler: how to print CSRs in GDB?

And, if you use Eclipse, you might also reconsider the decision to use make files, Eclipse CDT managed projects do not need manually written make files.

Adding this directive made my code work! Well, I still had to undo my address shift of

slli t0, t0, 1 # shift address left by one; LSB will be 0 which is direct mode (what we want)

before it started working but that was all. I only noticed that I had to undo this shift because I saw in GDB that on an interrupt, the code jumped at the double of the address that my ISR was defined at.

In the documentation, it says that the Interrupt Vector Base will be read from bits [31:2] of mtvec. Since I have written the address of my ISR to mtvec directly, I assumed that I had to left shift it by one bit poition because otherwise the address would be read wrongly. This assumption was obviously wrong but I am not sure why.

In any case, thanks for all the help to everyone! If you care to see my complete code let me know and I will upload it somewhere.

Because the address is aligned to 64 bytes, the low order 6 bits of that address are already zero. So the hardware “steals” two of those bits for the mode setting. When it branches to your code, it puts zeros back in those positions. If you use direct mode, they are zero anyway.

I see!

In vectored mode, the LSB will be set to 1 I assume. That means the base address will be interpreted as if the LSB is set to 0 and the PC will be set to the 64-byte aligned address.

@Shugyousha , could you please publish the resulting working code with fixes?

could you please publish the resulting working code with fixes?

Sure!

It has been a while but you should be able to find everything here.

https://sillymon.ch/cgit/freedom-e-sdk/tree/software/first?h=useTimerIRQ

Note that documentation on how to compile this is sparse/non-existent.

You can also find my email address on the page below.

I’m most likely faster at responding if you send mail to the address mentioned above or my public email inbox at ~shugyousha/public-inbox@lists.sr.ht.

1 Like