From f17af1cfda4f108deb24f223d97cb59c9df2f341 Mon Sep 17 00:00:00 2001
From: Jeffrey Lee <jlee@gitlab.riscosopen.org>
Date: Sun, 29 Mar 2015 16:17:34 +0000
Subject: [PATCH] Fix OS_Byte 19 getting stuck if it's called just before the
 screen blanker activates. Add new OS_ReadSysInfo reason code for determining
 IIC bus count.

Detail:
  s/PMF/osbyte - For OS_Byte 19, move screen blanker check (and current GraphicsV driver check) inside the WFI loop so that the loop will terminate if the screen should blank (or current GraphicsV driver should die) before the next VSync occurs. Also move the Portable_Idle call to before the interrupt trigger - the old location meant that if the screen blanked we'd continue on to the Portable_Idle call and end up pointlessly stalling the system
  s/Middle - Add OS_ReadSysInfo 14, as a legitimate way of finding the number of IIC buses present on the system
Admin:
  Tested on Pandaboard


Version 5.35, 4.79.2.261. Tagged as 'Kernel-5_35-4_79_2_261'
---
 VersionASM   | 10 +++++-----
 VersionNum   | 14 +++++++-------
 s/Middle     | 19 ++++++++++++++++++-
 s/PMF/osbyte | 33 ++++++++++++++++-----------------
 4 files changed, 46 insertions(+), 30 deletions(-)

diff --git a/VersionASM b/VersionASM
index b7f10ec..a5e8320 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.260"
-Module_Date             SETS    "16 Mar 2015"
-Module_ApplicationDate  SETS    "16-Mar-15"
+Module_MinorVersion     SETS    "4.79.2.261"
+Module_Date             SETS    "29 Mar 2015"
+Module_ApplicationDate  SETS    "29-Mar-15"
 Module_ComponentName    SETS    "Kernel"
 Module_ComponentPath    SETS    "castle/RiscOS/Sources/Kernel"
-Module_FullVersion      SETS    "5.35 (4.79.2.260)"
-Module_HelpVersion      SETS    "5.35 (16 Mar 2015) 4.79.2.260"
+Module_FullVersion      SETS    "5.35 (4.79.2.261)"
+Module_HelpVersion      SETS    "5.35 (29 Mar 2015) 4.79.2.261"
                         END
diff --git a/VersionNum b/VersionNum
index 3455935..b145fe2 100644
--- a/VersionNum
+++ b/VersionNum
@@ -5,19 +5,19 @@
  *
  */
 #define Module_MajorVersion_CMHG        5.35
-#define Module_MinorVersion_CMHG        4.79.2.260
-#define Module_Date_CMHG                16 Mar 2015
+#define Module_MinorVersion_CMHG        4.79.2.261
+#define Module_Date_CMHG                29 Mar 2015
 
 #define Module_MajorVersion             "5.35"
 #define Module_Version                  535
-#define Module_MinorVersion             "4.79.2.260"
-#define Module_Date                     "16 Mar 2015"
+#define Module_MinorVersion             "4.79.2.261"
+#define Module_Date                     "29 Mar 2015"
 
-#define Module_ApplicationDate          "16-Mar-15"
+#define Module_ApplicationDate          "29-Mar-15"
 
 #define Module_ComponentName            "Kernel"
 #define Module_ComponentPath            "castle/RiscOS/Sources/Kernel"
 
-#define Module_FullVersion              "5.35 (4.79.2.260)"
-#define Module_HelpVersion              "5.35 (16 Mar 2015) 4.79.2.260"
+#define Module_FullVersion              "5.35 (4.79.2.261)"
+#define Module_HelpVersion              "5.35 (29 Mar 2015) 4.79.2.261"
 #define Module_LibraryVersionInfo       "5:35"
diff --git a/s/Middle b/s/Middle
index 8ff7f50..29696f0 100644
--- a/s/Middle
+++ b/s/Middle
@@ -1245,7 +1245,7 @@ dhte
 ; Out   r0 = sysinfo for r0in
 
 ReadSysInfo_Code ROUT
-        CMP     r0,#14 ;R0 > 13, so illegal value
+        CMP     r0,#15 ;R0 > 14, so illegal value
         ADDLO   PC, PC, R0,LSL #2
         B       ReadSysInfo_InvalidReason
 
@@ -1263,6 +1263,7 @@ ReadSysInfo_Code ROUT
         B       %FT110
         B       %FT120
         B       %FT130
+        B       %FT140
 
 ReadSysInfo_InvalidReason
         ADR     r0, ErrorBlock_BadReadSysInfo
@@ -2127,6 +2128,22 @@ RSI_DebugRX
 
         MakeErrorBlock BadKeyHandler
 
+; OS_ReadSysInfo 14 - Return IIC bus count
+;
+; On entry:
+;    r0 = 14 (reason code 14)
+;
+; On exit:
+;    r0 = Number of IIC buses (as per HAL_IICBuses)
+;
+
+140
+        Push    "r1-r3,sb,lr"
+        AddressHAL
+        CallHAL HAL_IICBuses
+        Pull    "r1-r3,sb,lr"
+        ExitSWIHandler
+
 ;
 ; Extended ROM footer functions
 ;
diff --git a/s/PMF/osbyte b/s/PMF/osbyte
index 3f0fd25..af41a90 100644
--- a/s/PMF/osbyte
+++ b/s/PMF/osbyte
@@ -532,7 +532,9 @@ Osbyte12 ROUT
 Osbyte13 ROUT
 
         MRS     R3, CPSR                ; Interrupts disabled at the moment
+        LDRB    R2, CFStime
 
+10
         ; bug fix for MED-03165. Having a DPMS-blanked screen stopped printing.
         ; The reason is that HSyncs stop and VSyncs stop as a consequence,
         ; but the Hourglass module uses this call to wait for the next VSync
@@ -541,22 +543,30 @@ Osbyte13 ROUT
         ; immediately. This is equivalent to the operation of the DPMSUtils
         ; module shipped with OS 3.50.
 
-        VDWS    R2
+        VDWS    LR
 
-        LDRB    R0, [R2,#ScreenBlankFlag]
-        LDRB    R1, [R2,#ScreenBlankDPMSState]
+        LDRB    R0, [LR,#ScreenBlankFlag]
+        LDRB    R1, [LR,#ScreenBlankDPMSState]
 
         TEQ     R0, #0                  ; NE => blanked
         TSTNE   R1, #1                  ; NE => blanked and DPMS turned off HSyncs
         MyOsbyte NE                     ; if true exit immediately
 
         ; Also, exit now if we don't have a driver active
-        LDR     R0, [R2,#CurrentGraphicsVDriver]
+        LDR     R0, [LR,#CurrentGraphicsVDriver]
         CMP     R0, #GraphicsVInvalid
         MyOsbyte EQ
 
-        LDRB    R2, CFStime
-10
+ [ StorkPowerSave
+; It is actually better to call Idle with interrupts disabled as it stops the interrupt
+; going off on the way through the SWI dispatch and accidentally waiting for the next
+; interrupt... The Idle will return when an interrupt is pending - it will be handled below
+        LDR     R0, =ZeroPage
+        LDRB    R0, [R0, #PortableFlags]
+        TST     R0, #PortableFeature_Idle
+        SWINE   XPortable_Idle
+ ]
+
         BIC     R1, R3, #I32_bit
         MSR     CPSR_c, R1              ; CLI
 
@@ -573,17 +583,6 @@ Osbyte13 ROUT
         LDRB    R1, CFStime
         TEQ     R1, R2
         MyOsbyte NE
-
- [ StorkPowerSave
-; It is actually better to call Idle with interrupts disabled as it stops the interrupt
-; going off on the way through the SWI dispatch and accidentally waiting for the next
-; interrupt... The Idle will return when an interrupt is pending - it will be handled when
-; we branch back up and enable interrupts.
-        LDR     R0, =ZeroPage
-        LDRB    R0, [R0, #PortableFlags]
-        TST     R0, #PortableFeature_Idle
-        SWINE   XPortable_Idle
- ]
         B       %BT10
 
 ; *****************************************************************************
-- 
GitLab