From fc0b6873efb048f6e1ac99363262a0df04dbeac2 Mon Sep 17 00:00:00 2001
From: Jeffrey Lee <jlee@gitlab.riscosopen.org>
Date: Sat, 5 Dec 2009 20:17:51 +0000
Subject: [PATCH] Fix HAL RTC initialisation in Cortex kernel

Detail:
  LookForHALRTC wasn't initialising R12 to point to the OS Byte workspace before calling CheckYear, and instead relying on the previous value. This resulted in the RTC initialisation breaking once HAL_InitDevices started doing things to corrupt R12.
Admin:
  Tested on rev C2 beagleboard


Version 5.35, 4.79.2.98.2.18. Tagged as 'Kernel-5_35-4_79_2_98_2_18'
---
 VersionASM | 10 ++++-----
 VersionNum | 14 ++++++------
 s/NewReset | 63 +++++++++++++++++++++++++++---------------------------
 3 files changed, 44 insertions(+), 43 deletions(-)

diff --git a/VersionASM b/VersionASM
index ff2bc94..9431994 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.98.2.17"
-Module_Date             SETS    "29 Nov 2009"
-Module_ApplicationDate  SETS    "29-Nov-09"
+Module_MinorVersion     SETS    "4.79.2.98.2.18"
+Module_Date             SETS    "05 Dec 2009"
+Module_ApplicationDate  SETS    "05-Dec-09"
 Module_ComponentName    SETS    "Kernel"
 Module_ComponentPath    SETS    "castle/RiscOS/Sources/Kernel"
-Module_FullVersion      SETS    "5.35 (4.79.2.98.2.17)"
-Module_HelpVersion      SETS    "5.35 (29 Nov 2009) 4.79.2.98.2.17"
+Module_FullVersion      SETS    "5.35 (4.79.2.98.2.18)"
+Module_HelpVersion      SETS    "5.35 (05 Dec 2009) 4.79.2.98.2.18"
                         END
diff --git a/VersionNum b/VersionNum
index a56be30..d30f6bf 100644
--- a/VersionNum
+++ b/VersionNum
@@ -5,19 +5,19 @@
  *
  */
 #define Module_MajorVersion_CMHG        5.35
-#define Module_MinorVersion_CMHG        4.79.2.98.2.17
-#define Module_Date_CMHG                29 Nov 2009
+#define Module_MinorVersion_CMHG        4.79.2.98.2.18
+#define Module_Date_CMHG                05 Dec 2009
 
 #define Module_MajorVersion             "5.35"
 #define Module_Version                  535
-#define Module_MinorVersion             "4.79.2.98.2.17"
-#define Module_Date                     "29 Nov 2009"
+#define Module_MinorVersion             "4.79.2.98.2.18"
+#define Module_Date                     "05 Dec 2009"
 
-#define Module_ApplicationDate          "29-Nov-09"
+#define Module_ApplicationDate          "05-Dec-09"
 
 #define Module_ComponentName            "Kernel"
 #define Module_ComponentPath            "castle/RiscOS/Sources/Kernel"
 
-#define Module_FullVersion              "5.35 (4.79.2.98.2.17)"
-#define Module_HelpVersion              "5.35 (29 Nov 2009) 4.79.2.98.2.17"
+#define Module_FullVersion              "5.35 (4.79.2.98.2.18)"
+#define Module_HelpVersion              "5.35 (05 Dec 2009) 4.79.2.98.2.18"
 #define Module_LibraryVersionInfo       "5:35"
diff --git a/s/NewReset b/s/NewReset
index 53022f4..2f49edb 100644
--- a/s/NewReset
+++ b/s/NewReset
@@ -2352,38 +2352,39 @@ HexTable = "0123456789ABCDEF"
 
  [ HAL
 LookForHALRTC
-	Push "R0-R2,R8,R14"
-	MOV	R0, #0
-	LDR	R0, [R0, #RTCFitted]
-	CMP	R0, #0
-	Pull "R0-R2,R8,PC",NE ; We already have an RTC
-	LDR	R0, =(0:SHL:16)+HALDeviceType_SysPeri+HALDeviceSysPeri_RTC
-	MOV	R1, #0
-	MOV	R8, #4
+        Push "R0-R2,R8,R12,R14"
+        MOV     R0, #0
+        LDR     R0, [R0, #RTCFitted]
+        CMP     R0, #0
+        Pull "R0-R2,R8,PC",NE ; We already have an RTC
+        LDR     R0, =(0:SHL:16)+HALDeviceType_SysPeri+HALDeviceSysPeri_RTC
+        MOV     R1, #0
+        MOV     R8, #4
 01
-	SWI	XOS_Hardware
-	Pull "R0-R2,R8,PC",VS
-	CMP	R1, #-1
-	Pull "R0-R2,R8,PC",EQ
-	LDR	R14, [R2, #HALDevice_Location]
-	; Currently, we only support devices located on IIC bus 0
-	CMP	R14, #HALDeviceBus_Ser+HALDeviceSerBus_IIC
-	BNE	%BT01
-	; Try activating
-	Push "R0-R3,R12"
-	MOV	R0, R2
-	MOV	LR, PC
-	LDR	PC, [R2, #HALDevice_Activate]
-	CMP	R0, #1
-	Pull "R0-R3,R12"
-	BNE	%BT01
-	DebugTX "HAL RTC detected!"
-	MOV	R0, #0
-	STR	R2, [R0, #RTCFitted]
-	; Read the time from the RTC into RealTime, and fixup YearCMOS if needed
-	BL	CheckYear
-	DebugTX "Leaving LookForHALRTC"
-	Pull "R0-R2,R8,PC"
+        SWI     XOS_Hardware
+        Pull "R0-R2,R8,PC",VS
+        CMP     R1, #-1
+        Pull "R0-R2,R8,PC",EQ
+        LDR     R14, [R2, #HALDevice_Location]
+        ; Currently, we only support devices located on IIC bus 0
+        CMP     R14, #HALDeviceBus_Ser+HALDeviceSerBus_IIC
+        BNE     %BT01
+        ; Try activating
+        Push "R0-R3"
+        MOV     R0, R2
+        MOV     LR, PC
+        LDR     PC, [R2, #HALDevice_Activate]
+        CMP     R0, #1
+        Pull "R0-R3"
+        BNE     %BT01
+        DebugTX "HAL RTC detected!"
+        MOV     R0, #0
+        STR     R2, [R0, #RTCFitted]
+        ; Read the time from the RTC into RealTime, and fixup YearCMOS if needed
+        BYTEWS  WsPtr
+        BL      CheckYear
+        DebugTX "Leaving LookForHALRTC"
+        Pull "R0-R2,R8,R12,PC"
  ]
 
         END
-- 
GitLab