<?xml version="1.0"?>
<!DOCTYPE riscos-prm PUBLIC "-//Gerph//DTD PRM documentation 1.03//EN"
                            "http://gerph.org/dtd/103/prm.dtd">

<riscos-prm>
<chapter title="Modules (supplement for Pyromaniac)">
<section title="Introduction and Overview">

<p>
    This chapter documents the changes to the module format for RISC OS Pyromaniac.
</p>
</section>

<section title="Technical Details">

<subsection title="Module header format">

<p>The module indicates to the system if and where it wishes to be called
by a module header. This contains offsets from the start of the module to
code and information within the body of the module:</p>

<p><offset-table head-name="Contains" head-value="Function">
<offset number="00" name="Offset to code"><reference type="entry"
name="Module_Start" href='?' /></offset>
<offset number="04" name="Offset to code"><reference type="entry"
name="Module_Initialise" href='?' /></offset>
<offset number="08" name="Offset to code"><reference type="entry"
name="Module_Finalise" href='?' /></offset>
<offset number="0C" name="Offset to code"><reference type="entry"
name="Module_ServiceHandler" href='?' /></offset>
<offset number="10" name="Offset to string"><reference type="entry"
name="Module_TitleString" href='?' /></offset>
<offset number="14" name="Offset to string"><reference type="entry"
name="Module_HelpString" href='?' /></offset>
<offset number="18" name="Offset to table"><reference type="entry"
name="Module_CommandTable" href='?'/></offset>
<offset number="1C" name="Number">SWI chunk base number (optional)</offset>
<offset number="20" name="Offset to code">SWI handler code (optional)
</offset>
<offset number="24" name="Offset to table">SWI decoding table (optional)
</offset>
<offset number="28" name="Offset to code">SWI decoding code (optional)
</offset>
<offset number="2C" name="Offset to string">Message file pathname (optional)
</offset>
<offset number="30" name="Offset to module feature table"><reference type="entry"
name="Module_FeatureTable"/></offset>
</offset-table></p>

<p>The following fields have been updated:</p>

<subsubsection title="Module_Initialise">

<p>
    The flags used by the Module_Initialise entry point have been extended.
</p>

<p>
    <bitfield-table>
        <bit number="31"><p>Module is compressed and must be decompressed before it can be initialised.</p>
            <p>This flag is not supported by RISC OS Pyromaniac and modules may not be compressed.</p>
        </bit>

        <bit number="30"><p>Module flags contains alternate architecture flags.</p>
            <p>This flag is present to force older versions of the operating system to reject the module header
               as invalid. This prevents modules which contain architecture incompatible implementations from
               loading on older systems.</p>
       </bit>
    </bitfield-table>
</p>

</subsubsection>

<subsubsection title="Module_SWIDecodingCode">
    <p>
        The SWI decoding code was deprecated in Select 3 due to changes in the way that
        decoding was performed, and as its behaviour is rarely used. Pyromaniac does not
        support this entry point and it will never be called.
    </p>
</subsubsection>

<subsubsection title="Module_FeatureTable">
    <p>The feature flags have been extended to add an architecture flag.
    See the section <reference type='entry' name='Module_FeatureTable'/>.</p>
</subsubsection>

</subsection>

</section>


<section title="Entry Points">

<entry-definition name="Module_FeatureTable"
                  number="30"
                  description="Extension feature table">

<use>
    <p>The feature table is used to provide additional information about the features of a module,
       beyond the originally defined header data. The initial word of this feature table consists
       of flags indicating the features of the module. The flags word is not faulted when unknown
       bits are present.
    </p>

    <p>
        The feature table must be present in modules which support 32 bit operation, and so all
        preceding offsets must be included and must be 0 if they are unused.
    </p>

    <p>The flags word consists of:</p>

    <p>
    <bitfield-table>
        <bit number="0"><p>Module contains 32bit safe code.</p>
            <p>This flag is required by RISC OS Pyromaniac when executing ARM code.
               It is required for 32 bit-only versions of RISC OS, and will be ignored on
               26 bit-only versions. Non-ARM 32 bit modules should not set this flag.</p>
        </bit>

        <bit number="1"><p>ROM module should be initialised early.</p>
            <p>This flag is used to sort modules which are required for early initialisation
               as part of the ROM. This bit avoids the need for specially placed modules
               in the ROM where they must happen early on. In particular this bit is used
               in RISC OS Select to initialise the Podule manager (and other extension
               modules). For non-ROM modules this has no meaning and will be ignored.</p>
            <p>It is supported and used by RISC OS Select 3 and later, and by
               RISC OS Pyromaniac.</p>
        </bit>

        <bit number="2" state="reserved"/>
        <bit number="3" state="reserved"/>
        <bit number="4-7"><p>Module implementation architecture</p>
            <p>This bit field is used to indicate the architecture the module has been implemented
               in. The use of the architecture flag allows modules which are for incompatible
               architectures to be identified. If the architecture is not ARM 32 (including ARM 26 bit),
               bit 30 of the Module_Initialise entry point should be set. This will prevent the module
               being recognised by earlier versions of RISC OS. When the architecture is not ARM 32,
               bit 0 is undefined and should be set to 0.</p>
            <p>Currently defined architectures:</p>
            <p>
                <value-table>
                    <value number='0'>ARM 32 bit (A32)</value>
                    <value number='1'>ARM 64 bit (A64)</value>
                    <value number='2'>x86 64 bit (x86-64)</value>
                    <value number='3-14'>Reserved</value>
                    <value number='15'>Python (RISC OS Pyromaniac)</value>
                </value-table>
            </p>
            <p>This architecture flags are recognised by RISC OS Pyromaniac after 0.22.
               Only A32 and Pyromaniac architectures are supported by RISC OS Pyromaniac.</p>
            <p>No other RISC OS versions currently recognise this flag.</p>
        </bit>
        <bit number="8-31" state="reserved"/>
    </bitfield-table>
    </p>

    <p>If a module is deemed to be unsuitable for execution, either because it contains 26 bit code,
       or is for a different architecture, it will not be initialised by the system. Such modules will
       enumerate the modules through OS_Module 19 and 20 with a status of -2, indicating that they are
       unsuitable.
   </p>

   <p>
       Future versions of the feature table may include a subsequent extension block. The presence of
       such a block indicated in the flags word.
   </p>
</use>

<related>
    <reference type="swi" name="OS_Module" reason="19" href="?"/>
    <reference type="swi" name="OS_Module" reason="20" href="?"/>
</related>

</entry-definition>
</section>

</chapter>


<!-- MetaData -->
<meta>
 <maintainer>
  <email name="Gerph" address="gerph@gerph.org" />
 </maintainer>
 <disclaimer>
    <p>
        &copy; Gerph, 2022.
    </p>
 </disclaimer>

 <history>
  <revision number="1" author="Gerph" date="04 Nov 2021" title="Initial version">
    <change>Created</change>
  </revision>
  <revision number="2" author="Gerph" date="23 Dec 2022" title="Minor fix">
    <change>Fix for link to the feature table.</change>
  </revision>
 </history>

</meta>
</riscos-prm>
