From d59167833a03ee236ac616031e92e54688a16433 Mon Sep 17 00:00:00 2001
From: Kevin Bracey <kbracey@gitlab.riscosopen.org>
Date: Sun, 2 Mar 2003 23:30:47 +0000
Subject: [PATCH] OSDelink/RelinkApp now work on the list in opposite orders so
 that the order of vector claims doesn't get toggled.

Fix for *FX5 not working due to a TST having been swapped for CMP.
Checkprotectionlink option added to HAL version so CMOS lock is
implemented.
Updated HAL docs.

Version 5.35, 4.79.2.58. Tagged as 'Kernel-5_35-4_79_2_58'
---
 Docs/HAL/HAL_API |  2 ++
 Version          |  2 +-
 VersionASM       | 10 +++++-----
 VersionNum       | 14 +++++++-------
 hdr/Options      | 15 +++++++--------
 s/ArthurSWIs     | 22 ++++++++++++++++++++++
 s/NewReset       | 35 ++++++++++++++++++-----------------
 s/PMF/oseven     |  9 +++++----
 8 files changed, 67 insertions(+), 42 deletions(-)

diff --git a/Docs/HAL/HAL_API b/Docs/HAL/HAL_API
index 780c1cf..77b577a 100644
--- a/Docs/HAL/HAL_API
+++ b/Docs/HAL/HAL_API
@@ -998,6 +998,8 @@ This call must not be made after RISCOS_Start.
         bit 1: CMOS reset inhibited (eg protection link on Risc PC)
         bit 2: perform a CMOS reset (if bit 1 clear and bit 0 set - eg front panel
                                      button held down on an NC)
+        bit 3: there is no CMOS (the Kernel must use a RAM cache)
+        bit 4: the RAM has already been cleared to zero
 
 On entry:
   SVC32 mode
diff --git a/Version b/Version
index d14c511..d34974e 100644
--- a/Version
+++ b/Version
@@ -16,7 +16,7 @@ Date    SETS    Module_Date      ; version for STB/NC OS
         |
 Version SETA    502
 VString SETS    "5.02"
-Date    SETS    "21 Feb 2003"    ; version for RISC OS on desktop computers
+Date    SETS    "28 Feb 2003"    ; version for RISC OS on desktop computers
         ]
 
         END
diff --git a/VersionASM b/VersionASM
index 86ff7c2..532cd46 100644
--- a/VersionASM
+++ b/VersionASM
@@ -13,11 +13,11 @@
                         GBLS    Module_ComponentPath
 Module_MajorVersion     SETS    "5.35"
 Module_Version          SETA    535
-Module_MinorVersion     SETS    "4.79.2.57"
-Module_Date             SETS    "28 Feb 2003"
-Module_ApplicationDate  SETS    "28-Feb-03"
+Module_MinorVersion     SETS    "4.79.2.58"
+Module_Date             SETS    "02 Mar 2003"
+Module_ApplicationDate  SETS    "02-Mar-03"
 Module_ComponentName    SETS    "Kernel"
 Module_ComponentPath    SETS    "RiscOS/Sources/Kernel"
-Module_FullVersion      SETS    "5.35 (4.79.2.57)"
-Module_HelpVersion      SETS    "5.35 (28 Feb 2003) 4.79.2.57"
+Module_FullVersion      SETS    "5.35 (4.79.2.58)"
+Module_HelpVersion      SETS    "5.35 (02 Mar 2003) 4.79.2.58"
                         END
diff --git a/VersionNum b/VersionNum
index 9d1b4c7..7d61292 100644
--- a/VersionNum
+++ b/VersionNum
@@ -5,19 +5,19 @@
  *
  */
 #define Module_MajorVersion_CMHG        5.35
-#define Module_MinorVersion_CMHG        4.79.2.57
-#define Module_Date_CMHG                28 Feb 2003
+#define Module_MinorVersion_CMHG        4.79.2.58
+#define Module_Date_CMHG                02 Mar 2003
 
 #define Module_MajorVersion             "5.35"
 #define Module_Version                  535
-#define Module_MinorVersion             "4.79.2.57"
-#define Module_Date                     "28 Feb 2003"
+#define Module_MinorVersion             "4.79.2.58"
+#define Module_Date                     "02 Mar 2003"
 
-#define Module_ApplicationDate          "28-Feb-03"
+#define Module_ApplicationDate          "02-Mar-03"
 
 #define Module_ComponentName            "Kernel"
 #define Module_ComponentPath            "RiscOS/Sources/Kernel"
 
-#define Module_FullVersion              "5.35 (4.79.2.57)"
-#define Module_HelpVersion              "5.35 (28 Feb 2003) 4.79.2.57"
+#define Module_FullVersion              "5.35 (4.79.2.58)"
+#define Module_HelpVersion              "5.35 (02 Mar 2003) 4.79.2.58"
 #define Module_LibraryVersionInfo       "5:35"
diff --git a/hdr/Options b/hdr/Options
index ba223e9..2f28615 100644
--- a/hdr/Options
+++ b/hdr/Options
@@ -134,7 +134,7 @@ ChecksumCMOS    SETL   {TRUE}
                 GBLL    SqueezeMods     ; whether squeezed modules are allowed
 SqueezeMods     SETL    {TRUE}
 
-                GBLL    International   ; whether text and error messages come from  messaeges file.
+                GBLL    International   ; whether text and error messages come from  messages file.
 International   SETL    {TRUE}
 
                 GBLL    CacheCommonErrors       ; whether common internationalised errors are cached in sysheap
@@ -318,6 +318,9 @@ DebugHALTX      SETL    {FALSE}
 
                 GBLL    DebugHeaps              ; initialise claimed and freed blocks
 DebugHeaps      SETL    {FALSE}                 ; (may slow things down unacceptably)
+              [ DebugHeaps
+                ! 0, "*** WARNING *** Heap debugging assembled in"
+              ]
 
 ; ChangeDynamicArea and related options
 
@@ -343,12 +346,8 @@ FixCallBacks    SETL    {TRUE}                  ; also addresses some atomicity
                 GBLL    InterlacedPointer
 InterlacedPointer SETL {TRUE} :LAND: STB                ; enable code to do proper interlaced pointer
 
-                GBLL    ValidateCMOS            ; Apply special CMOS-corruption detection code, and do minimal default settings.
-ValidateCMOS    SETL    {TRUE}
-
-              [ DebugHeaps
-                ! 0, "*** WARNING *** Heap debugging assembled in"
-              ]
+                GBLL    ValidateCMOS            ; Apply special CMOS-corruption detection code,
+ValidateCMOS    SETL    {TRUE}                  ; and do minimal default settings.
 
                 GBLS    GetMessages
               [ International
@@ -364,7 +363,7 @@ DebugForcedReset SETL   {FALSE}
 ConfiguredLang  SETA    11                      ; default configured language
 
                 GBLA    FirstUnpluggableModule
-FirstUnpluggableModule SETA 8                   ; Podule, FileSwitch, ResourceFS, Messages, MessageTrans,
+FirstUnpluggableModule  SETA 8                  ; Podule, FileSwitch, ResourceFS, Messages, MessageTrans,
                                                 ; TerritoryManager, UKTerritory
 
  [ DebugForcedReset
diff --git a/s/ArthurSWIs b/s/ArthurSWIs
index f194a49..c7a8389 100644
--- a/s/ArthurSWIs
+++ b/s/ArthurSWIs
@@ -693,6 +693,27 @@ Application_Delink ROUT
 ; Returns V set if can't relink all
 
 Application_Relink ROUT
+ [ {TRUE}
+; Run through the buffer BACKWARDS to ensure that the vectors are
+; reinstalled in the same order.
+      Push   "R0-R3, lr"
+      MOV     R3, R0            ; R3 -> start of buffer
+      MOV     R10, R0
+01    LDR     R0, [R10], #12    ; search forwards to find terminator
+      CMP     R0, #-1
+      BNE     %BT01
+      SUB     R10, R10, #12     ; R10 -> terminator
+02    CMP     R10, R3           ; loop backwards until we get to start
+      Pull   "R0-R3, lr", EQ
+      ExitSWIHandler EQ
+
+      LDMDB   R10!, {R0-R2}
+      SWI     XOS_AddToVector
+      BVC     %BT02
+      STR     R0, [stack]
+      Pull   "R0-R3, lr"
+      B      SLVK_SetV
+ |
       Push   "R0-R2, lr"
       MOV     R10, R0
 02    LDR     R0, [R10], #4
@@ -706,6 +727,7 @@ Application_Relink ROUT
       STR     R0, [stack]
       Pull   "R0-R2, lr"
       B      SLVK_SetV
+ ]
 
 ;********************************************************************
 ; Now the stuff that issues service calls; also deals with the MOS
diff --git a/s/NewReset b/s/NewReset
index 639e6d3..ad25c35 100644
--- a/s/NewReset
+++ b/s/NewReset
@@ -784,7 +784,7 @@ checkboot
  ]
 
 
-; IF power-on bit set in IOC AND R/T/Del/Copy pressed THEN reset CMOS RAM
+; IF power-on bit set AND R/T/Del/Copy pressed THEN reset CMOS RAM
 ; note that memory cleared if POR, so key info has had plenty of time!
  [ HAL
         MOV     R0, #HAL_StartFlags
@@ -792,9 +792,11 @@ checkboot
         TST     R1, #OSStartFlag_NoCMOS ; If no CMOS, reset for sensible cache
         BNE     cmos_reset
         TST     R1, #OSStartFlag_POR
-        BEQ     no_cmos_reset
+        BEQ     no_cmos_reset           ; not a power on reset
+      [ CheckProtectionLink
         TST     R1, #OSStartFlag_NoCMOSReset
         BNE     no_cmos_reset
+      ]
         TST     R1, #OSStartFlag_CMOSReset
         BNE     cmos_reset
  |
@@ -803,12 +805,11 @@ checkboot
         ANDS    R1, R1, #por_bit
         BEQ     no_cmos_reset
 
- [ CheckProtectionLink
+      [ CheckProtectionLink
         LDR     r0, =IOMD_MonitorType
 
-; on Issue A's the protection bit is only weakly pulled up,
-; so force it high, then read it back
-
+        ; on Issue A's the protection bit is only weakly pulled up,
+        ; so force it high, then read it back
         LDRB    r1, [r0]
         ORR     r1, r1, #IOMD_ProtectionLinkBit
         STRB    r1, [r0]
@@ -816,18 +817,18 @@ checkboot
         LDRB    r1, [r0]
         TST     r1, #IOMD_ProtectionLinkBit
         BEQ     no_cmos_reset           ; if zero then CMOS is protected
- ]
+      ]
 
- [ STB :LAND: IOMD_C_FrontPanelButton <> 0
-  [ FrontPanelButtClearsCMOS
+    [ STB :LAND: IOMD_C_FrontPanelButton <> 0
+      [ FrontPanelButtClearsCMOS
         MOV     r0, #IOMD_Base          ; if front panel button pressed then CMOS reset
         LDRB    r0, [r0, #IOMD_CLINES]
         TST     r0, #IOMD_C_FrontPanelButton
         BEQ     cmos_reset
-  ]
- ]
+      ]
+    ]
 
- ] ; HAL
+ ]
 
         MOV     R0, #InitIRQWs
  [ HAL
@@ -839,9 +840,9 @@ checkboot
  ]
         BEQ     no_cmos_reset           ; power on bit checked again there
 
-        [ :LNOT: STB
+      [ :LNOT: STB
         ADD     sp, sp, #4              ; junk CannotReset flag from stack
-        ]
+      ]
 
 ; CMOS reset detectified.
 ; **************************************************************************
@@ -2007,18 +2008,18 @@ SkipHardResetPart2                      ; code executed on all types of reset
         CMP     r1, #PowerOnReset
         BNE     %FT75
 
- [ HAL
+ [ HAL :LAND: CheckProtectionLink
         LDR     r1, =HAL_StartFlags
         LDR     r1, [r1]
         TST     r1, #OSStartFlag_NoCMOSReset
         BNE     %FT75
  |
- [ CheckProtectionLink
+      [ CheckProtectionLink
         LDR     r1, =IOMD_MonitorType   ; check link bit again
         LDRB    r1, [r1]                ; no need to preload bus, since should
         TST     r1, #IOMD_ProtectionLinkBit ; be still there from earlier
         BEQ     %FT75                   ; zero => protected
- ]
+      ]
  ]
 
 
diff --git a/s/PMF/oseven b/s/PMF/oseven
index 3e28bd3..2d87b29 100644
--- a/s/PMF/oseven
+++ b/s/PMF/oseven
@@ -46,11 +46,12 @@ MOSDoPrint ROUT
         Pull    "R12,PC"
 
 MOSDoPrintWS                                    ; entry point when R12-> BYTEWS
+        CLRV
         LDRB    R1, WrchDest
-        CMP     R1, #4                          ; is printer disabled ?
-        MOVNE   PC, R14                         ; yes, then return (and V:=0)
+        TST     R1, #4                          ; is 'printer disabled' bit set ?
+        MOVNE   PC, R14                         ; yes, then return with V clear
 SWIPrintCharEntry
-        LDRB    R1, PrinterDrivType             ; is it user/net ???
+        LDRB    R1, PrinterDrivType             ; get the stream type
         B       FudgePrinterInsert
 
 ; *****************************************************************************
@@ -90,7 +91,7 @@ WRITE   ROUT
 
 ; *****************************************************************************
 ;
-;       FudgePrinterInsert - Write byte to net printer
+;       FudgePrinterInsert - Write byte to printer stream
 ;
 ; in:   R0 = character to send
 ;       R1 = printer type (3..255)
-- 
GitLab