RobMcK wrote: ↑Mon Nov 08, 2021 8:08 am
One way this could happen is:-
1. function with global registers calls a function which uses the standard ABI.
2. Standard ABI code saves registers and potentially does some work.
3. A function which expects the global registers is called.
I'm not following your explanation I'm afraid. In step 3, where is the "function which expects the global registers" being called
from? Obviously it can't be called from within a "function which uses the standard ABI" since typically that won't work.
If you use global register variables at all you have to partition your project into a subset of modules/functions which know about the global register variables (because they are declared in a header, for example) and a subset of modules/functions which don't. Whilst it's allowed for a function in the first set to call a function in the second set (so long as the global registers chosen are callee-saved) it is
not allowed for a function in the second set to call one in the first set.
Fortunately we have Acorn to thank for it being almost impossible to get that wrong in the case of BBC BASIC, because the first subset corresponds directly to what would be the 'language' in a BBC Micro (&8000 - &BFFF) and the second subset to what would be the MOS (&C000 - &FFFF). Functions in the language can call functions in the MOS, but functions in the MOS cannot call functions in the language.
In terms of modules in my Console Mode editions, the 'language' subset consists of
bbmain.c,
bbexec.c,
bbeval.c and
bbasmb_xxx.c (all of which know about the global register variables because they're declared in
BBC.h) whereas the 'MOS' subset consists of
bbccon.c (
bbpico.c in the case of the Pico edition) and
bbccos.c. I've again reproduced below the architecture diagram that I've published here before.
So I'm not sure whether I'm misunderstanding your explanation, or you're not understanding how the global register variables work in BBC BASIC. I'm using them for
precisely the purpose that the GNU documentation says they can be useful for. I use them on every platform on which they are supported: 32-bit and 64-bit Windows, 32-bit and 64-bit (x86) Linux, 32-bit and 64-bit Raspberry Pi, Android and the Pico.
Only on the Pico has there been the slightest indication of a problem, and only then with one specific optimisation setting (-Os). It seems to me that all the evidence points to it being a compiler/optimiser bug, and although one would hope that is uncommon, I think it's more likely in the case of a rarely-used (and unique to GCC) feature of the language.
Having a quick look at the source, I cannot see where the global registers are setup in bbpico.c.
They're not:
bbpico.c is in the MOS subset, not the language subset. The only functions it calls in the interpreter are ones that do not use the global variables.