From 2a3ad40a06542f8c9d036babb67f556b745a4b49 Mon Sep 17 00:00:00 2001
From: Jeffrey Lee <me@phlamethrower.co.uk>
Date: Fri, 30 Apr 2021 02:28:55 +0100
Subject: [PATCH] Fix compressed ROM support

When PhysRamTable was updated to store addresses in page units instead
of byte units (commit df4efb6), the code which allocates the ROM
decompression workspace didn't get updated, causing it to break. Add a
few extra shifts to the code in order to account for the changes.

Fixes issue reported on forums with (compressed) OMAP3 ROM failing to
boot: https://www.riscosopen.org/forum/forums/5/topics/16446

Version 6.57. Tagged as 'Kernel-6_57'
---
 VersionASM | 12 ++++++------
 VersionNum | 20 ++++++++++----------
 s/HAL      | 14 +++++++-------
 3 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/VersionASM b/VersionASM
index a7ee642..ace93fe 100644
--- a/VersionASM
+++ b/VersionASM
@@ -9,12 +9,12 @@
                         GBLS    Module_ApplicationDate
                         GBLS    Module_HelpVersion
                         GBLS    Module_ComponentName
-Module_MajorVersion     SETS    "6.56"
-Module_Version          SETA    656
+Module_MajorVersion     SETS    "6.57"
+Module_Version          SETA    657
 Module_MinorVersion     SETS    ""
-Module_Date             SETS    "28 Apr 2021"
-Module_ApplicationDate  SETS    "28-Apr-21"
+Module_Date             SETS    "30 Apr 2021"
+Module_ApplicationDate  SETS    "30-Apr-21"
 Module_ComponentName    SETS    "Kernel"
-Module_FullVersion      SETS    "6.56"
-Module_HelpVersion      SETS    "6.56 (28 Apr 2021)"
+Module_FullVersion      SETS    "6.57"
+Module_HelpVersion      SETS    "6.57 (30 Apr 2021)"
                         END
diff --git a/VersionNum b/VersionNum
index 9275661..4accfdb 100644
--- a/VersionNum
+++ b/VersionNum
@@ -1,21 +1,21 @@
-/* (6.56)
+/* (6.57)
  *
  * This file is automatically maintained by srccommit, do not edit manually.
  *
  */
-#define Module_MajorVersion_CMHG        6.56
+#define Module_MajorVersion_CMHG        6.57
 #define Module_MinorVersion_CMHG
-#define Module_Date_CMHG                28 Apr 2021
+#define Module_Date_CMHG                30 Apr 2021
 
-#define Module_MajorVersion             "6.56"
-#define Module_Version                  656
+#define Module_MajorVersion             "6.57"
+#define Module_Version                  657
 #define Module_MinorVersion             ""
-#define Module_Date                     "28 Apr 2021"
+#define Module_Date                     "30 Apr 2021"
 
-#define Module_ApplicationDate          "28-Apr-21"
+#define Module_ApplicationDate          "30-Apr-21"
 
 #define Module_ComponentName            "Kernel"
 
-#define Module_FullVersion              "6.56"
-#define Module_HelpVersion              "6.56 (28 Apr 2021)"
-#define Module_LibraryVersionInfo       "6:56"
+#define Module_FullVersion              "6.57"
+#define Module_HelpVersion              "6.57 (30 Apr 2021)"
+#define Module_LibraryVersionInfo       "6:57"
diff --git a/s/HAL b/s/HAL
index 33e2b29..4bfcc46 100644
--- a/s/HAL
+++ b/s/HAL
@@ -1392,22 +1392,22 @@ ROMDecompAlign_$pt * 20
         STR     v7, [sp, #8] ; Overwrite stacked WS size
         MOV     v6, #ROMDecompWSAddr_$pt ; Current log addr
 26
-        ADD     v2, v2, v5
-        BIC     v2, v2, v5 ; MB-aligned physram
+        ADD     v2, v2, v5, LSR #12
+        BIC     v2, v2, v5, LSR #12 ; MB-aligned physram
         LDMIA   v1, {a2, a3}
-        SUB     a2, v2, a2 ; Amount of bank used
-        SUB     a2, a3, a2 ; Amount of bank remaining
-        MOVS    a2, a2, ASR #ROMDecompAlign_$pt ; Round down to nearest MB
+        SUB     a2, v2, a2 ; Amount of bank used (page units)
+        RSB     a2, a2, a3, LSR #12 ; Amount of bank remaining (page units)
+        MOVS    a2, a2, ASR #ROMDecompAlign_$pt-12 ; Round down to nearest MB
         LDRLE   v2, [v1, #8]! ; Move to next bank if 0MB left
         BLE     %BT26
         CMP     a2, v7, LSR #ROMDecompAlign_$pt
         MOVHS   a4, v7
         MOVLO   a4, a2, LSL #ROMDecompAlign_$pt ; a4 = amount to take
-        MOV     a1, v2 ; set up parameters for MapIn call
+        MOV     a1, v2, LSL #12 ; set up parameters for MapIn call
         MOV     a2, v6
         MOV     a3, #OSAP_None
         SUB     v7, v7, a4 ; Decrease amount to allocate
-        ADD     v2, v2, a4 ; Increase physram ptr
+        ADD     v2, v2, a4, LSR #12 ; Increase physram ptr
         ADD     v6, v6, a4 ; Increase logram ptr
         BL      Init_MapIn_$pt
         CMP     v7, #0
-- 
GitLab