Commit 41706835 authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Timestamp the RPi HAL on fake HAL CMOS update

As the penny pinchers didn't fit a hardware real time clock, on a CMOS write (or desktop shutdown) the HAL CMOS is stamped with the current time. On power up, if the time is found to be 1970 (the kernel default) the last shutdown time is used instead - while this time is going to be incorrect it should at least ensure the time doesn't go backwards in the moments before NetTime manages to find a time server.

Version 0.08. Tagged as 'SDCMOS-0_08'
parent d2f08614
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "0.07"
Module_Version SETA 7
Module_MajorVersion SETS "0.08"
Module_Version SETA 8
Module_MinorVersion SETS ""
Module_Date SETS "03 Oct 2012"
Module_ApplicationDate SETS "03-Oct-12"
Module_Date SETS "05 Oct 2012"
Module_ApplicationDate SETS "05-Oct-12"
Module_ComponentName SETS "SDCMOS"
Module_ComponentPath SETS "cddl/RiscOS/Sources/HWSupport/SD/SDCMOS"
Module_FullVersion SETS "0.07"
Module_HelpVersion SETS "0.07 (03 Oct 2012)"
Module_FullVersion SETS "0.08"
Module_HelpVersion SETS "0.08 (05 Oct 2012)"
END
/* (0.07)
/* (0.08)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 0.07
#define Module_MajorVersion_CMHG 0.08
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 03 Oct 2012
#define Module_Date_CMHG 05 Oct 2012
#define Module_MajorVersion "0.07"
#define Module_Version 7
#define Module_MajorVersion "0.08"
#define Module_Version 8
#define Module_MinorVersion ""
#define Module_Date "03 Oct 2012"
#define Module_Date "05 Oct 2012"
#define Module_ApplicationDate "03-Oct-12"
#define Module_ApplicationDate "05-Oct-12"
#define Module_ComponentName "SDCMOS"
#define Module_ComponentPath "cddl/RiscOS/Sources/HWSupport/SD/SDCMOS"
#define Module_FullVersion "0.07"
#define Module_HelpVersion "0.07 (03 Oct 2012)"
#define Module_LibraryVersionInfo "0:7"
#define Module_FullVersion "0.08"
#define Module_HelpVersion "0.08 (05 Oct 2012)"
#define Module_LibraryVersionInfo "0:8"
......@@ -35,7 +35,13 @@ StoreInHAL SETL {FALSE};
GET HighFSI
GET ModHand
GET OsBytes
GET OsWords
GET CMOS
GET FSNumbers
GET NewErrors
GET Territory
GET FileTypes
GET Services
GET VersionASM
AREA |Asm$$Code|, CODE, READONLY, PIC
......@@ -45,7 +51,11 @@ StoreInHAL SETL {FALSE};
DCD 0 ; Start
DCD Init - |Asm$$Code|
DCD Final - |Asm$$Code|
DCD 0; Service call handler
[ StoreInHAL
DCD Services - |Asm$$Code|
|
DCD 0 ; Service call handler
]
DCD Title - |Asm$$Code|
DCD Help - |Asm$$Code|
DCD 0 ; Keyword table
......@@ -59,7 +69,7 @@ StoreInHAL SETL {FALSE};
Title = Module_ComponentName, 0
Help = Module_ComponentName, 9, 9, Module_HelpVersion, 0
ALIGN
Flags & ModuleFlag_32bit
Flags DCD ModuleFlag_32bit
[ StoreInHAL
......@@ -210,6 +220,79 @@ TryInit ROUT
LDRNE r0, =FileType_MSDOS
TEQNE r6, r0
BNE %F90
|
; If the time is in 1970 then the kernel didn't find a real time
; clock, and NetTime hasn't picked up a link yet
SUB sp, sp, #8
MOV r0, #OsWord_ReadRealTimeClock
MOV r1, #3 ; time as UTC 5 byte cs
STRB r1, [sp]
MOV r1, sp
SWI XOS_Word
ADDVS sp, sp, #8
BVS %F80
LDR r3, =((71 * 365) + 18) * 86400
MOV r0, #100 ; want cs to end of 1970 from epoch 1900
UMULL r3, r4, r0, r3
LDR r0, [sp, #0]
LDRB r1, [sp, #4]
SUBS r14, r0, r3
SBCS r14, r1, r4
ADDPL sp, sp, #8 ; now > 1970
BPL %F80
; Try and find the last saved value
MOV r0, #open_read :OR: open_mustopen :OR: open_nodir :OR: open_nopath
LDR r1, [r12]
SWI XOS_Find
BVS %F70
MOV r1, r0
; Search for the CMOS in the ROM on disc
LDR r5, CMOSMarker
LDR r6, OSIm
MOV r0, #OSGBPB_ReadFromPTR
50 MOV r2, sp
MOV r3, #4
SWI XOS_GBPB
BVS %F60
LDR r14, [sp]
TEQ r14, r6
BEQ %F60 ; got to the end of the HAL and not found CMOS - give up
TEQ r14, r5
BNE %B50
; Read size of block in HAL
MOV r2, sp
MOV r3, #4
SWI XOS_GBPB
BVS %F60
LDR r6, [sp]
; Read the last timestamp
MOV r0, #OSGBPB_ReadFromGiven
MOV r2, sp
MOV r3, #5
ADD r4, r4, r6
SWI XOS_GBPB
BVS %F60
; Check it's not unset
LDR r3, [sp, #0]
LDRB r4, [sp, #4]
ORRS r3, r4, r3
MOVNE r0, sp
SWINE Territory_SetTime
60
MRS r3, CPSR ; preserve V set ness
MOV r0, #0 ; close file
SWI XOS_Find
MSR CPSR_f, r3
70
ADD sp, sp, #8 ; skip temp block
BVS %F90
80
]
; All good
CLRV
......@@ -227,7 +310,18 @@ TryInit ROUT
SETV
EXIT
MyByteV ROUT
[ StoreInHAL
Services ROUT
TEQ r1, #Service_ShutDown
MOVNE pc, lr
Push "r0, lr" ; keep original r0 in case MyByteV returns an error
Push "pc"
BL %FT15 ; now write the values out, along with the timestamp
NOP
Pull "r0, pc" ; and on with the shutdown (don't claim)
]
MyByteV
TEQ r0, #OsByte_WriteCMOS
MOVNE pc, lr ; only interested in when the CMOS is written
ADR r0, %F10
......@@ -238,11 +332,12 @@ MyByteV ROUT
Pull "r12" ; get our own r12 back
Pull "pc", VS ; if an error, just pass it up to original claim address
[ StoreInHAL
15
Push "r0-r7"
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
MOV r0, #open_update :OR: open_mustopen :OR: open_nodir :OR: open_nopath
LDR r1, [r12]
SWI XOS_Find
BVS %F90
......@@ -252,7 +347,7 @@ MyByteV ROUT
; running version!
LDR r5, CMOSMarker
LDR r6, OSIm
MOV r0, #4 ; read bytes from current file pointer
MOV r0, #OSGBPB_ReadFromPTR
20 MOV r2, sp
MOV r3, #4
SWI XOS_GBPB
......@@ -291,22 +386,37 @@ MyByteV ROUT
BLO %B30
; Overwrite the HAL with the block from the stack
MOV r0, #2 ; write bytes at current file pointer
MOV r0, #OSGBPB_WriteAtPTR
MOV r1, r5
MOV r2, sp
MOV r3, r6
SWI XOS_GBPB
BVS %F75
; Refresh the timestamp
MOV r0, #OsWord_ReadRealTimeClock
MOV r1, #3 ; time as UTC 5 byte cs
STRB r1, [sp]
MOV r1, sp
SWI XOS_Word
MOVVC r0, #OSGBPB_WriteAtPTR
MOVVC r1, r5
MOVVC r2, sp
MOVVC r3, #5
SWIVC XOS_GBPB
75
ADD sp, sp, r6
80 MOV r2, r0
80 MOV r2, r0 ; preserve the original error
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
90 ADD sp, sp, #4 ; skip temp block
STRVS r0, [sp]
Pull "r0-r7, pc" ; go to original claim address
Pull "r0-r7, pc" ; go to original claim address
|
Push "r0"
LDR r0, [r12]
......
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