Well, that was simple...
Rick Murray (539) 13851 posts |
I wanted to get SocketManager working with RISC OS 5 because when working with socket code, it is useful to have a way to tidy up sockets and there’s no obvious method in RISC OS to list active socket handles… …but the archive contains Justin Fletcher’s IServices module…it’s sort of like the X degrees of Kevin Bacon, trying to find older stuff that doesn’t use one of his many useful modules. Since nobody can distribute 32 bit safe versions of his modules, I’ll briefly outline the steps used in case you want to mod-your-own and/or try other stuff. This isn’t just for his modules – the same process can be used to attempt to convert any module that is not 32 bit compatible and the licence/terms/whatever don’t permit distribution of modified versions or in cases where nobody has attempted to make a conversion. Okay, here goes:
AREA |Mod$HackCode|, CODE, A32bit
DCD 0 DCD |thirtytwobitword| |thirtytwobitword| DCD 1
CMP R0, #1<<31 CMNVC R0, #1<<31 MOV PC, R14
With a bit of luck, that’ll be sufficient. But it depends greatly upon how the module was written. Compiled C may do all sorts of evil things (like non-aligned LDR), while assembler written by hand may be a lot simpler to convert. In the case of the module that I converted, there were only three things that needed attention. |
Steve Pampling (1551) 8172 posts |
There’s an amazing number of items that are that simple to convert. |
Rick Murray (539) 13851 posts |
This is arguably the most important part of the process as ARMalyser can convert the executable into something objasm can assemble and annotate it to highlight things that need attention.
|
Sprow (202) 1158 posts |
You’re not supposed to put the flags word immediately after its pointer, because then the header can’t be extended again in future. |
John Williams (567) 768 posts |
When you chaps have sorted it out amongst yourselves, please let me know with a URL download. |
Steve Pampling (1551) 8172 posts |
Erm, relevant bit of Rick’s text:
Basically Justin specifically said people were not allowed to distribute versions of his code modified to be 32 bit compliant. Essentially, unless someone produces a patching code, disassembly twiddle and recompile is the only option. |
Rick Murray (539) 13851 posts |
I’m not aware that there are any “official” guidelines regarding what to put after the header. Should we leave a few null words or something? The Wimp, for example, puts the module title directly after the header. For better or worse, as it is some sort of data… https://www.riscosopen.org/viewer/view/castle/RiscOS/Sources/Desktop/Wimp/s/Wimp01?rev=4.73#l2050 |
Steve Pampling (1551) 8172 posts |
To be honest, it’s a flags word and we appear to have one bit in use. |
Jon Abbott (1421) 2651 posts |
I believe Sprow is referring to the Module header itself and the ridiculous way in which header values are validated when a Module is loaded. If a value at offset X in the header is below the length of the Module, and it’s expected to be an offset within the Module, the parameter is presumed to be valid. The undocumented way of avoiding this, is to ensure the header is immediately followed by an instruction and not a value that may fall within the Module length. The obvious way to avoid this long term would have been to add a Module header version number when the 32bit flag was added, so the Module loader code knew what spec of header it was dealing with. |
Steve Pampling (1551) 8172 posts |
31 spare bits in the flags word… |
Jeffrey Lee (213) 6048 posts |
I’ve never really understood the “don’t put the flags word after the header” mantra either. Either it’s about (a) making sure the OS doesn’t think the flags word is part of the module header (in which case the OS can just spot that the flags word offset is pointing to +4 bytes from the current location, and therefore there can’t be any more header words), or (b) allowing a module binary to be patched – in which case if you need 4 bytes of space you can probably just move the flags word to the end of the binary, and if you need more space you’ll be in as much difficulty as with any other scheme. The problem of the kernel having to guess the length of the module header easily be solved once and for all by having a length field somewhere (top 8 bits of flags word = length in words of any extra header components? Or keep the current header length as-is and change the flags word to an “extended header block” with the length indicated in the same way) |
Rick Murray (539) 13851 posts |
Witness: https://www.riscosopen.org/viewer/view/castle/RiscOS/Sources/Kernel/s/ModHand?rev=4.11.2.13 Given the module header is data I don’t understand why Acorn did not include a word in the header to identify either the length or the type of module header, explicitly, instead of guessing things.
I’d be inclined to want to replace the first two works with a word “RMOD” for identification, then a word giving the module header version (the length can be construed from the version). However this would interfere with the ability to have a literal instruction in the Start offset to jump into the code . . . if anybody ever used this? Thus:
Is probably the way to go (plus retaining better backwards compatibility). With the length in words it gives us around 1K to play with… |
Steve Pampling (1551) 8172 posts |
In my mind it’s almost like saying don’t put anything after the header which would make the header a bit lonely :)
Yup. “Exactement” as David F might say. |
Ben Avison (25) 445 posts |
IIRC the advice not to put the flags word immediately after the offset to the flags word is because its value is likely to be very small (either 0 or 1 at present, remaining small until a lot more flag bits have been defined) and therefore liable to be confused for another offset value by dumb module header parsers, not least the human kind :-) |
Steve Pampling (1551) 8172 posts |
Seems like us human dumb header parsers expect it to be part of the header sequence. From observation modules that have the flags word immediately after the older header items seem to be more common. |