SWI flag preservation
Jon Abbott (1421) 2651 posts |
I’ve somewhat ignored this issue in ADFFS to date, but need to now make a start on it. I’m going to start on the assumption that all SWI’s preserved the N, Z and C flags up to RO5, so need to know exceptions to this rule. From a scan of the RO3 PRM’s, I know about the ones below, are there any others? OS_Byte 138 – alters C All SWI’s – alter V |
Steve Revill (20) 1361 posts |
When you say “up to RO5”, I’m assuming you’re already aware of this:
|
Jon Abbott (1421) 2651 posts |
Sorry, I should have explained that when ADFFS’ JIT is providing a RISCOS 3.X or 4.X environment to an app, it needs to preserve flags across SWI’s to match previous behaviour.
I never quite understood the reasoning behind this as you have to go out of your way to alter SPSR in SWI dispatch – flags are preserved by default if you exit via MOVS PC, R14 or LDMFD R13!, {PC}^ |
Rick Murray (539) 13840 posts |
I should add briefly that these instructions are for system level code. They are “unpredictable” in user mode code. Yes, I had always thought that there was some sort of complicated technical reason for not preserving flags – indeed the Iyonix 32 bit technical information says “Requiring flag preservation would impose an unacceptable burden on SWI dispatch.”. However, having looked into it a lot more deeply than I did maybe a decade ago, I cannot see anything obvious that would require an entire API change, except perhaps that there is some sort of peculiarity in how RISC OS deals with SWIs. Quoting from the ARM System Developer’s Guide (p391):
This is their mini “SLOS” operating system example aimed at the ARM7TDMI (in 32 bit mode). I must admit to being surprised at seeing multiple load/store on a single register, though for the purposes of example, maybe 1 My preference is upper case register names and instructions, lower case labels, and whitespace like spaces between parameters and the like. 2 “sp” is used at the beginning, setting up the stack positions (p386) and setting up the process control block (p387). From then on, “r13” is used, except this one time in the SWI dispatch. |
Rick Murray (539) 13840 posts |
Interestingly, the actual build code is slightly different to that given in the book:
Does the same thing, but is written more consistently; and more commentary. |