From dbc48c98f8a0c63045294e0205327bdb63d70f58 Mon Sep 17 00:00:00 2001
From: Stewart Brodie <sbrodie@gitlab.riscosopen.org>
Date: Tue, 21 Nov 2000 15:19:54 +0000
Subject: [PATCH] 32-bit kernels will refuse to initialise non 32-bit modules.

Detail:
  The kernel will examine all modules that it is requested to initialise
    and will refuse to initialise any module without a module flags word
    entry in its module header or with bit 0 the first flags word being
    clear (bit 0 being ModuleFlag_32bit)
  Error message added to all the messages files.
  New error block added to message counting block.  The Non-32-bit module
    message is not a cached error message, though.
Admin:
  Tested in 32-bit Lazarus build.

Version 5.38. Tagged as 'Kernel-5_38'
---
 Resources/UK/Messages         |  1 +
 Resources/UK/Morris4/Messages |  1 +
 Resources/UK/Omega/Messages   |  1 +
 Resources/UK/Ursula/Messages  |  1 +
 VersionASM                    | 18 +++++++++++-------
 VersionNum                    | 23 +++++++++++++----------
 s/ModHand                     | 32 +++++++++++++++++++++++++-------
 s/MsgCode                     |  1 +
 8 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/Resources/UK/Messages b/Resources/UK/Messages
index 4aab4765..859543a1 100644
--- a/Resources/UK/Messages
+++ b/Resources/UK/Messages
@@ -77,6 +77,7 @@ ChunkNotRM:Podule chunk is not a relocatable module
 ModulePostfix:'%%' in module title
 NotMod:This is not a relocatable module
 BadRMHeaderField:Illegal header field in module
+RMNot32bit:Module is not 32-bit compatible
 IncarnationNotFound:Incarnation not found
 RMNotFoundInROM:Module is not in ROM
 NumbTooBig:Number too big
diff --git a/Resources/UK/Morris4/Messages b/Resources/UK/Morris4/Messages
index d02f3ef1..4f2c2ceb 100644
--- a/Resources/UK/Morris4/Messages
+++ b/Resources/UK/Morris4/Messages
@@ -77,6 +77,7 @@ ChunkNotRM:Podule chunk is not a relocatable module
 ModulePostfix:'%%' in module title
 NotMod:This is not a relocatable module
 BadRMHeaderField:Illegal header field in module
+RMNot32bit:Module is not 32-bit compatible
 IncarnationNotFound:Incarnation not found
 RMNotFoundInROM:Module is not in ROM
 NumbTooBig:Number too big
diff --git a/Resources/UK/Omega/Messages b/Resources/UK/Omega/Messages
index 7cc1e3cc..626f4c86 100644
--- a/Resources/UK/Omega/Messages
+++ b/Resources/UK/Omega/Messages
@@ -77,6 +77,7 @@ ChunkNotRM:Podule chunk is not a relocatable module
 ModulePostfix:'%%' in module title
 NotMod:This is not a relocatable module
 BadRMHeaderField:Illegal header field in module
+RMNot32bit:Module is not 32-bit compatible
 IncarnationNotFound:Incarnation not found
 RMNotFoundInROM:Module is not in ROM
 NumbTooBig:Number too big
diff --git a/Resources/UK/Ursula/Messages b/Resources/UK/Ursula/Messages
index d02f3ef1..4f2c2ceb 100644
--- a/Resources/UK/Ursula/Messages
+++ b/Resources/UK/Ursula/Messages
@@ -77,6 +77,7 @@ ChunkNotRM:Podule chunk is not a relocatable module
 ModulePostfix:'%%' in module title
 NotMod:This is not a relocatable module
 BadRMHeaderField:Illegal header field in module
+RMNot32bit:Module is not 32-bit compatible
 IncarnationNotFound:Incarnation not found
 RMNotFoundInROM:Module is not in ROM
 NumbTooBig:Number too big
diff --git a/VersionASM b/VersionASM
index c3964bf9..2757380e 100644
--- a/VersionASM
+++ b/VersionASM
@@ -9,12 +9,16 @@
                         GBLS    Module_ApplicationDate2
                         GBLS    Module_ApplicationDate4
                         GBLS    Module_HelpVersion
-Module_MajorVersion     SETS    "5.37"
-Module_Version          SETA    537
+                        GBLS    Module_ComponentName
+                        GBLS    Module_ComponentPath
+Module_MajorVersion     SETS    "5.38"
+Module_Version          SETA    538
 Module_MinorVersion     SETS    ""
-Module_Date             SETS    "17 Oct 2000"
-Module_ApplicationDate2 SETS    "17-Oct-00"
-Module_ApplicationDate4 SETS    "17-Oct-2000"
-Module_FullVersion      SETS    "5.37"
-Module_HelpVersion      SETS    "5.37 (17 Oct 2000)"
+Module_Date             SETS    "21 Nov 2000"
+Module_ApplicationDate2 SETS    "21-Nov-00"
+Module_ApplicationDate4 SETS    "21-Nov-2000"
+Module_ComponentName    SETS    "Kernel"
+Module_ComponentPath    SETS    "RiscOS/Sources/Kernel"
+Module_FullVersion      SETS    "5.38"
+Module_HelpVersion      SETS    "5.38 (21 Nov 2000)"
                         END
diff --git a/VersionNum b/VersionNum
index 59111012..87d7c241 100644
--- a/VersionNum
+++ b/VersionNum
@@ -1,19 +1,22 @@
-/* (5.37)
+/* (5.38)
  *
  * This file is automatically maintained by srccommit, do not edit manually.
  *
  */
-#define Module_MajorVersion_CMHG        5.37
+#define Module_MajorVersion_CMHG        5.38
 #define Module_MinorVersion_CMHG        
-#define Module_Date_CMHG                17 Oct 2000
+#define Module_Date_CMHG                21 Nov 2000
 
-#define Module_MajorVersion             "5.37"
-#define Module_Version                  537
+#define Module_MajorVersion             "5.38"
+#define Module_Version                  538
 #define Module_MinorVersion             ""
-#define Module_Date                     "17 Oct 2000"
+#define Module_Date                     "21 Nov 2000"
 
-#define Module_ApplicationDate2         "17-Oct-00"
-#define Module_ApplicationDate4         "17-Oct-2000"
+#define Module_ApplicationDate2         "21-Nov-00"
+#define Module_ApplicationDate4         "21-Nov-2000"
 
-#define Module_FullVersion              "5.37"
-#define Module_HelpVersion              "5.37 (17 Oct 2000)"
+#define Module_ComponentName            "Kernel"
+#define Module_ComponentPath            "RiscOS/Sources/Kernel"
+
+#define Module_FullVersion              "5.38"
+#define Module_HelpVersion              "5.38 (21 Nov 2000)"
diff --git a/s/ModHand b/s/ModHand
index db467f34..7aafb82d 100644
--- a/s/ModHand
+++ b/s/ModHand
@@ -2127,7 +2127,8 @@ CallInit         ROUT
 ;              "    size    in R2
 
 CheckHeader ROUT
-        Push   "R3, lr"
+        Push   "R0, R3, lr"
+        ADR     R0, ErrorBlock_BadRMHeaderField
         LDR     R3, [R1, #Module_HC_Table]
         BL      %FT11
         LDR     R3, [R1, #Module_HelpStr]
@@ -2142,25 +2143,42 @@ CheckHeader ROUT
         LDR     R3, [R1, #Module_Init]
         TST     R3, #&80000000
         BLEQ    %FT10                           ; only check init offset if an unsqueezed module
+      [ No26bitCode                             ; insist that modules declare themselves 32-bit safe
+        ADR     R0, ErrorBlock_RMNot32bit
+        LDR     R3, [R1, #Module_SWIChunk]
+        BIC     R3, R3, #Auto_Error_SWI_bit
+        TST     R3, #Module_SWIChunkSize-1
+        TSTEQ   R3, #&FF000000
+        BNE     %FT99                           ; naff SWI chunk number
+        TEQ     R3, #0
+        LDRNE   R3, [R1, #Module_SWIEntry]      ; check for SWI entry point like CheckForSWIEntries
+        BLNE    %FT10
+        LDR     R3, [R1, #Module_MsgFile]       ; Other places appear to require this to be word-aligned
+        BL      %FT10
+        CMP     R3, R2
+        LDRLO   R3, [R1, #Module_FlagTable]
+        BL      %FT10
+        LDR     R3, [R1, R3]                    ; Retrieve first word of module flags
+        TST     R3, #ModuleFlag_32bit           ; NE if 32-bit compatible
+        BEQ     %FT99
+      ]
         CLRV
-        Pull   "R3, PC"
+        Pull   "R0, R3, PC"
 
 10      TST     R3, #3
         BNE     %FT99
 11      CMP     R3, R2
         MOVLO   PC, lr
 99
-        Pull   "R3, lr"
-        ADR     R0, ErrorBlock_BadRMHeaderField
+        LDMIB   SP!, {R3, LR}                   ; NOTE: sp still points at stacked LR!
       [ International
-        Push    "lr"
         BL      TranslateError
-        Pull    "lr"
       |
         SETV
       ]
-        MOV     PC, lr
+        Pull    "PC"
         MakeErrorBlock BadRMHeaderField
+        MakeErrorBlock RMNot32bit
 
 ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ; Enter with module node pointer in R9
diff --git a/s/MsgCode b/s/MsgCode
index 0e14087c..695592e9 100644
--- a/s/MsgCode
+++ b/s/MsgCode
@@ -109,6 +109,7 @@ TranslateError_UseR4
    ; This block MUST not be empty
 CommonErrorAddresses
     [ countmsgusage
+        &       ErrorBlock_RMNot32bit
         &       ErrorBlock_RCExc
         &       ErrorBlock_RCNegative
         &       ErrorBlock_BadString
-- 
GitLab