ARM2/3 compatibility in CLib
Jeffrey Lee (213) 6048 posts |
I’ve just discovered that the 26bit builds of CLib (e.g. as supplied on the recent tools CD) aren’t ARM2/3 compatible. It looks like they’ve been built with No32bitCode set to false, causing some of the macros (e.g. WritePSRc) to try and use MSR/MRS. This either means one of two things:
While looking at the disassembly it looks like there are a few cases where TEQ pc,pc is used to check whether the CPU is running in 26bit or 32bit mode, and then TEQP/MSR is used as appropriate. So if ARM2/3 support has been dropped (which I suspect it hasn’t) then it looks like there’s some opportunity to tidy the 26bit build a bit. |
Ben Avison (25) 445 posts |
True, there’s definitely an issue there. The root of the problem is that the macros in Hdr:Machine.GenericXX were only 32-bitted with ROM builds in mind – they can either use all TEQP style sequences, or all MRS style sequences. There is no support for producing target code that is required to operate on anything from an ARM2 to a Cortex-A9, as in disc builds – i.e. where No26bitCode and No32bitCode are both false. As a first step, it’s probably worth putting an assert in each of those macros to ensure that there are no other cases of them being invoked in disc builds. If that shows up a significant number of instances, it may be worth writing variants of the affected macros that choose either TEQP or MRS at runtime. The shared C library is actually a bit of a special case. Because, when running on a 26-bit OS, it has to support both APCS-R and APCS-32 clients, then to avoid having to include two versions of every routine, this module is built APCS-R, even where the rest of the disc build is built APCS-32 (this is achieved by use of the SCL_APCS=“-APCS 3/26bit” switch on the makefile command line). This means that there have to be separate binaries of CLib for RISC OS 3-4 and RISC OS 5. Consequently, for the special case of CLib, I think it might make sense to have a special local version of macros like WritePSRc that switch on the basis of {CONFIG} rather than No32bitCode. |