-
Notifications
You must be signed in to change notification settings - Fork 17
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
VBCC: Test the ISR feature and write a timer interrupt/ISR test for VBCC #77
Comments
Here is the correct C syntax for an ISR:
So the EDIT in October 2020: Using register banks in ISRs is in the meantime absolutely forbidden. |
In commit 56d0596 I updated the documentation about this feature. |
It seems we need more work on this feature. Assuming the goal is to be able to write an ISR in C (rather than in assembly), I tried the following:
So this is intended to be a bare-minimum ISR that simply increments a global counter. After compiling with the
The problem here is that this destroys the I'm not sure how to proceed, maybe we should have another meeting ? |
@MJoergen You're right: The compiler needs to make sure that it only uses the registers Also my gut feeling is, that when we or Volker touch the compiler backend, we might want to get rid of the necessity to do a So I propose the following new semantics for the compiler:
What are your thoughts? As soon as we all agree, we could approach Volker. regarding (**): If the compiler backend would be extremely smart, it would use up to 16 register banks inside an ISR and only when reaching bank 15 and needing more registers would use the stack. But I guess that this would lead to a very complex logic, so I instead phrased this simple rule and said "never uses register bank switching" in an ISR. |
First of all, when I wrote I like your proposal about not using register bank switching in an ISR. This also encourages the programmer to keep the ISR short, since anything complicated will use the stack, which is (somewhat) slower. However, we should be clear that it the programmer uses e.g. multiplication, that will result in subroutine calls inside the C library, which use register bank switching. I initially had the idea that we could in fact use |
You are right. This is why we need to do @MJoergen We also need to make sure to block ISRs inside the arithmetic functions to avoid undefined states of e.g. EAE when the main program is in the middle of a multiplication and then the ISR also wants do do that. Our agreed upon solution was, that we PAUSE/RESUME aka BLOCK/UNBLOCK the hardware interrupts as we defined it here under "Solution for V1.7": #138 (comment) And: Please do not forget to implement and test this BLOCK/UNBLOCK as defined here: #138 (comment) BTW: I assume that the list mentioned there needs to be enhanced be SHL32/SHR32? About the compiler: |
@sy2002 @bernd-ulmann : I just thought of something: When in an ISR, we need to save Would it be a possibility for the CPU to save all the registers |
I like the idea of eight shadow registers instead of three (a power of two is way nicer than that strange 3 :-) ). Let me think about it for a moment... |
Yes, that is really nice. I have changed the emulator accordingly. There are now eight shadow registers which are loaded with R8..R15 in the case of an interrupt and can be accessed by the EXC-instructions. At RTI the contents of these registers are copied back to R8..R15. :-) I also updated the programming card accordingly (there are no details on the shadow registers in the introductory slides). |
OK I will update the CPU |
@sy2002 : Maybe we should inform Volker about this change? The way I see it, with these new changes, an ISR can use all registers R0-R12, and not just R0-R7. Actually, is this not what the C compiler already does? So the only change needed in the C compiler is to add the |
@MJoergen Good point, I will update my email. |
Status:
|
Volker replied by mail and questioned our design. I think perhaps it is time to sit down and re-evaluate. The reason is that with the current compiler interrupt handling does seem to work as it is. For instance, the following small test program:
results in the following assembly code (when compiled with -O3):
Notice how the register This program works in hardware too already, provided the main loop does not use the registers So I'm basically asking, do we really need any interrupt-related changes to the compiler? The one big thing we talked about was to reserve a few register banks for the ISR, using Anyway, these are just my thoughts. |
We have two distinct topics here, because I asked Volker to do two things:
1)The reason why your above-mentioned Having register bank switching on for "normal" (non-interrupt) functions makes a lot of sense. This is why the standard C library is compiled using these options and also This is why I originally thought it might make sense that Right now, the best practice document is telling the programmer to do so (to always add I am absolutely fine not to ask Volker to change this very behaviour and the programmer "stays responsible" for deciding, if he wants to use register banks and if he does to add BTW (OFF TOPIC): While writing this text, I wonder, if the bugs I described in #87 (comment) might be related to the fact that I used the very make file in 2)The
Do I remember right that this was the reason we came up with the |
Re 2) Yes, that is correct. I still think this is a very special use case, and not something that a casual user writing an ISR in C would need. I mean, the C compiler will not by itself generate code that uses the register banks as random access memory. This use case is more relevant when writing programs directly in assembly, in which case the ISR would be written in assembly too, and then the programmer is free to add the Re 1) I feel we need some more experience with interrupt routines written in C to understand what is needed (or often used). |
re 1) As we documented in the best practices, that you should always use re 2)
You are right. I did not consider this. If you stick to a C-only environment, then this edge-case cannot happen at all. And for the assembler programmers, we have documented the best practice to use Bottom Line:I will email Volker that he is right and we can leave VBCC as it is. |
IMPORTANT: As of time of writing, this only works on branch
dev-vbcc-vasm-fix
VBCC supports ISRs: Test the ISR feature and write a timer interrupt/ISR test for VBCC and put it to
c/test_programs/timer_isr.c
There seems to be a special ISR "tag" or something that you can use in C programs as you an see here:
As soon as Volker anwers us how to use it: We should:
doc/best_practices
and explain this feature.Would be cool, if we would be able to add this still to V1.6, because V1.6 was the version where we introduced interrupts. It would make the release more well-rounded
The text was updated successfully, but these errors were encountered: