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

(Liviu Ionescu) #21

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.

(S) #22

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.

(S) #24

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.