Commit 6e62fd1f authored by Ben Avison's avatar Ben Avison
Browse files

Added support for writing fake CMOS on Raspberry Pi

Detail:
  For the Raspberry Pi, the CMOS RAM is embedded within the ROM image, since
  the default bootloader isn't flexible enough to load it from a separate
  file (and we need to know CMOS contents before modules like SDFS have
  initialised). This functionality is enabled by the build switch StoreInHAL
  passed in via the Makefile. Unrelatedly, removed a double free of the module
  workspace on finalisation.
Admin:
  Tested on Raspberry Pi.

Version 0.02. Tagged as 'SDCMOS-0_02'
parent b8788829
......@@ -3,6 +3,7 @@
COMPONENT = SDCMOS
RES_OBJ =
CMHGFILE =
ASFLAGS = ${MYASFLAGS}
include CModule
......
Dir <Obey$Dir>
amu standalone THROWBACK=-throwback MYASFLAGS="-pd \"StoreInHAL SETL {TRUE}\""
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "0.01"
Module_Version SETA 1
Module_MajorVersion SETS "0.02"
Module_Version SETA 2
Module_MinorVersion SETS ""
Module_Date SETS "07 Jun 2012"
Module_ApplicationDate SETS "07-Jun-12"
Module_Date SETS "15 Jul 2012"
Module_ApplicationDate SETS "15-Jul-12"
Module_ComponentName SETS "SDCMOS"
Module_ComponentPath SETS "cddl/RiscOS/Sources/HWSupport/SD/SDCMOS"
Module_FullVersion SETS "0.01"
Module_HelpVersion SETS "0.01 (07 Jun 2012)"
Module_FullVersion SETS "0.02"
Module_HelpVersion SETS "0.02 (15 Jul 2012)"
END
/* (0.01)
/* (0.02)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 0.01
#define Module_MajorVersion_CMHG 0.02
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 07 Jun 2012
#define Module_Date_CMHG 15 Jul 2012
#define Module_MajorVersion "0.01"
#define Module_Version 1
#define Module_MajorVersion "0.02"
#define Module_Version 2
#define Module_MinorVersion ""
#define Module_Date "07 Jun 2012"
#define Module_Date "15 Jul 2012"
#define Module_ApplicationDate "07-Jun-12"
#define Module_ApplicationDate "15-Jul-12"
#define Module_ComponentName "SDCMOS"
#define Module_ComponentPath "cddl/RiscOS/Sources/HWSupport/SD/SDCMOS"
#define Module_FullVersion "0.01"
#define Module_HelpVersion "0.01 (07 Jun 2012)"
#define Module_LibraryVersionInfo "0:1"
#define Module_FullVersion "0.02"
#define Module_HelpVersion "0.02 (15 Jul 2012)"
#define Module_LibraryVersionInfo "0:2"
......@@ -22,6 +22,11 @@
; Use is subject to license terms.
;
[ :LNOT::DEF: StoreInHAL
GBLL StoreInHAL
StoreInHAL SETL {FALSE};
]
GET ListOpts
GET Macros
GET System
......@@ -55,6 +60,17 @@ Help = Module_ComponentName, 9, 9, Module_HelpVersion, 0
ALIGN
Flags & ModuleFlag_32bit
[ StoreInHAL
NonCanonicalisedPath
= "SDFS::0.$.!Boot.Loader.riscos/img", 0
ALIGN
CMOSMarker UND #&C305
OSIm = "OSIm"
|
NonCanonicalisedPath
= "SDFS::0.$.CMOS", 0
ALIGN
......@@ -64,6 +80,8 @@ SaveCMOS
Len_SaveCMOS * .-SaveCMOS
ALIGN
]
Init ROUT
Entry
; This module is designed to be included in a ROM, in which case we have
......@@ -95,22 +113,30 @@ CallBackFromInit ROUT
SWI XOS_FSControl
BVS %F90
[ StoreInHAL
; Allocate a buffer to hold filename of the ROM image plus terminator
RSB r3, r5, #1
|
; Allocate a buffer for the command string - will contain "SaveCMOS "
; plus the canonicalised name of the file, plus a terminator
MOV r0, #ModHandReason_Claim
RSB r3, r5, #Len_SaveCMOS + 1
]
MOV r0, #ModHandReason_Claim
SWI XOS_Module
BVS %F90
STR r2, [r12]
; Get the canonicalised name
[ :LNOT: StoreInHAL
ADD r2, r2, #Len_SaveCMOS
]
MOV r5, r3
MOV r0, #FSControl_CanonicalisePath
MOV r3, #0
SWI XOS_FSControl
BVS %F90
[ :LNOT: StoreInHAL
; Copy in the "SaveCMOS " part now we have a few more working registers
ASSERT Len_SaveCMOS = 9
SUB r2, r2, #Len_SaveCMOS
......@@ -119,6 +145,7 @@ CallBackFromInit ROUT
LDRB r6, [r3]
STMIA r2!, {r4-r5}
STRB r6, [r2], #1
]
; Check it's the sort of file we're expecting
MOV r0, #OSFile_ReadWithTypeNoPath
......@@ -127,8 +154,14 @@ CallBackFromInit ROUT
BVS %F90
TST r0, #object_file
BEQ %F90
[ StoreInHAL
LDR r0, =FileType_EPROM
|
LDR r0, =FileType_Configuration
]
TEQ r6, r0
LDRNE r0, =FileType_MSDOS
TEQNE r6, r0
BNE %F90
; All good - get on ByteV
......@@ -162,18 +195,90 @@ CallBackFromInit ROUT
MyByteV ROUT
TEQ r0, #OsByte_WriteCMOS
MOVNE pc, lr ; only interested in when the CMOS is written
ADR r0, %F50
ADR r0, %F10
Push "r0, r12" ; set up address for claimant to return to (NB this code is not 26-bit compatible)
MOV r0, #OsByte_WriteCMOS
MOV pc, lr ; pass on, and...
50 ; ... we end up here after the CMOS has been written
10 ; ... we end up here after the CMOS has been written
Pull "r12" ; get our own r12 back
Pull "pc", VS ; if an error, just pass it up to original claim address
[ StoreInHAL
Push "r0-r6"
SUB sp, sp, #4 ; allocate space on stack for buffer
MOV r7, r1
MOV r0, #&CF ; open existing file for read/write, error if missing or directory, no path
LDR r1, [r12]
SWI XOS_Find
BVS %F90
MOV r1, r0
; Search for the CMOS in the ROM on disc - can't be sure it matches the
; running version!
LDR r5, CMOSMarker
LDR r6, OSIm
MOV r0, #4 ; read bytes from current file pointer
20 MOV r2, sp
MOV r3, #4
SWI XOS_GBPB
BVS %F80
LDR r14, [sp]
TEQ r14, r6
BEQ %F80 ; got to the end of the HAL and not found CMOS - give up
TEQ r14, r5
BNE %B20
; Read size of block in HAL
MOV r2, sp
MOV r3, #4
SWI XOS_GBPB
BVS %F80
LDR r6, [sp]
MOV r5, r1 ; keep file handle safe
; Copy the CMOS RAM into a block on the stack (should be small enough)
; in physical address order
SUB sp, sp, r6
MOV r3, #0
30 MOV r0, #OsByte_ReadCMOS
MOV r1, r3
CMP r3, #&10
ADDLO r1, r1, #&40
CMP r3, #&40
ADDLO r1, r1, #&F0
CMP r3, #&100
SUBLO r1, r1, #&40
SWI XOS_Byte
MOVVS r2, #0
STRB r2, [sp, r3]
ADD r3, r3, #1
CMP r3, r6
BLO %B30
; Overwrite the HAL with the block from the stack
MOV r0, #2 ; write bytes at current file pointer
MOV r1, r5
MOV r2, sp
MOV r3, r6
SWI XOS_GBPB
ADD sp, sp, r6
80 MOV r2, r0
MRS r3, CPSR
MOV r0, #0 ; close file
SWI XOS_Find
MOV r0, r2
MSR CPSR_f, r3
90 ADD sp, sp, #4 ; skip data block
STRVS r0, [sp]
Pull "r0-r6, pc" ; go to original claim address
|
Push "r0"
LDR r0, [r12]
SWI XOS_CLI ; save the CMOS to the file
STRVS r0, [sp]
Pull "r0, pc" ; go to original claim address
]
Final ROUT
Entry
......@@ -189,11 +294,7 @@ Final ROUT
MOV r2, r12
SWI XOS_Release
; Free the block containing the command string, if it was allocated
LDR r2, [r12]
TEQ r2, #0
MOVNE r0, #ModHandReason_Free
SWINE XOS_Module
; The block pointed at by r12 is freed for us by the kernel if nonzero
CLRV
EXIT
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment