Source
...
Target
Commits (1)
  • Robert Sprowson's avatar
    Add file-like-devices for zero: random: urandom: · 3c234253
    Robert Sprowson authored
    Add rough parallels to Unix /dev/zero /dev/[u]random alongside existing null.
    To avoid consuming lots of FS numbers we lump these all together as "SourceFS" and use special fields to select which is wanted. Other sources can be trivially added by extending the special field table.
    Currently [u]random are stateless, in that there is one global seed for all open random sources, and the PRBS is based on the algorithm for rand() in the ISO9899 C standard - in future more sources of entropy could be mashed in.
    To use, simply OPENIN"zero:" or "random:" "urandom:" and BGET or OS_GBPB as much data as you want - EOF is never reached.
    Misc other changes:
      Get 'standalone' passed in from the Makefile, rather than work out 'standalonemessages' here.
      Remove unused "serial:" support switch.
      Replace a few magic numbers with values from Hdr.
    
    Version 1.33. Tagged as 'SystemDevs-1_33'
    3c234253
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "1.32"
Module_Version SETA 132
Module_MajorVersion SETS "1.33"
Module_Version SETA 133
Module_MinorVersion SETS ""
Module_Date SETS "16 Mar 2012"
Module_ApplicationDate SETS "16-Mar-12"
Module_Date SETS "15 Jul 2016"
Module_ApplicationDate SETS "15-Jul-16"
Module_ComponentName SETS "SystemDevs"
Module_ComponentPath SETS "castle/RiscOS/Sources/HWSupport/SystemDevs"
Module_FullVersion SETS "1.32"
Module_HelpVersion SETS "1.32 (16 Mar 2012)"
Module_FullVersion SETS "1.33"
Module_HelpVersion SETS "1.33 (15 Jul 2016)"
END
/* (1.32)
/* (1.33)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.32
#define Module_MajorVersion_CMHG 1.33
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 16 Mar 2012
#define Module_Date_CMHG 15 Jul 2016
#define Module_MajorVersion "1.32"
#define Module_Version 132
#define Module_MajorVersion "1.33"
#define Module_Version 133
#define Module_MinorVersion ""
#define Module_Date "16 Mar 2012"
#define Module_Date "15 Jul 2016"
#define Module_ApplicationDate "16-Mar-12"
#define Module_ApplicationDate "15-Jul-16"
#define Module_ComponentName "SystemDevs"
#define Module_ComponentPath "castle/RiscOS/Sources/HWSupport/SystemDevs"
#define Module_FullVersion "1.32"
#define Module_HelpVersion "1.32 (16 Mar 2012)"
#define Module_LibraryVersionInfo "1:32"
#define Module_FullVersion "1.33"
#define Module_HelpVersion "1.33 (15 Jul 2016)"
#define Module_LibraryVersionInfo "1:33"
; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; > Sources.ResFiles
;
MACRO
$lab MyFileR $name
$lab ResourceFile $MergedMsgs, Resources.$ApplicationName..$name
MEND
; Insert here the names of the files to be put into Resources:$.Resources.<app>
; The source files are held in the DataFiles directory
; eg. MyFileR !RunImage
MyFileR Messages
END
......@@ -12,7 +12,7 @@
; See the License for the specific language governing permissions and
; limitations under the License.
;
TTL > SystemDevs - System Devices (vdu:, rawvdu:, kbd:, rawkbd:, null:)
TTL > SystemDevs - System Devices (vdu:, rawvdu:, kbd:, rawkbd:, null:, zero:, random:, urandom:)
; ***********************************
; *** C h a n g e L i s t ***
......@@ -74,13 +74,12 @@
GET Hdr:ListOpts
GET Hdr:Macros
GET Hdr:System
GET Hdr:Machine.<Machine>
GET Hdr:ModHand
GET Hdr:Services
GET Hdr:Proc
GET Hdr:FSNumbers
GET Hdr:HighFSI
GET Hdr:LowFSi
GET Hdr:LowFSI
GET Hdr:NewErrors
GET Hdr:OsBytes
GET Hdr:CMOS
......@@ -93,8 +92,6 @@
AREA |SystemDevices$$Code|, CODE, READONLY, PIC
GBLL debug
GBLL export_serial ; =true for exported serial:
debug SETL {FALSE}
GBLS get1
......@@ -104,22 +101,21 @@ debug SETL {FALSE}
get1 SETS " GET Hdr:Debug"
get2 SETS " GET Hdr:HostFS"
get3 SETS " GET Hdr:HostDebug"
]
]
$get1
$get2
$get3
export_serial SETL False
GBLL export_serial ; =true for exported serial:
export_serial SETL {FALSE}
GBLL Host_Debug
Host_Debug SETL {TRUE}
GBLL standalonemessages
[ :DEF: standalone
standalonemessages SETL standalone
|
standalonemessages SETL {FALSE}
]
[ :LNOT: :DEF: standalone
GBLL standalone
standalone SETL {FALSE} ; Build-in Messages file and i/f to ResourceFS
]
TAB * 9
LF * 10
......@@ -136,6 +132,8 @@ KbdLength # 4
PrinterHandle # 4 ; !=0 if in use, ==0 if free, only used if Opening the variable fails.
PrinterType # 4 ; 0..255 or -1 if not changed by SussSpecial
SourceRandSeed # 4
GSFormat # 1
LastChar # 1
RdchSrc # 1
......@@ -144,7 +142,6 @@ WrchDest # 1
FilenameBuffer # 0 ; both Kbd / PrinterSussType use this buffer
KbdBuffer # 256
ALIGN
message_file_block # 16 ; File handle for MessageTrans
message_file_open # 4 ; Opened message file flag
......@@ -200,9 +197,10 @@ SystemDevices_Init Entry
50
MOV wp, r2 ; Dereference on all resets !
[ standalonemessages
[ standalone
ADRL r0, resourcefsfiles
SWI XResourceFS_RegisterFiles ; ignore errors (starts on Service_ResourceFSStarting)
SWI XResourceFS_RegisterFiles
EXIT VS
]
; OSS Flag that the message file is closed.
......@@ -210,6 +208,9 @@ SystemDevices_Init Entry
MOV r0, #0
STR r0, message_file_open
MOV r0, #1 ; ISO9899:1999 7.20.2.2
STR r0, SourceRandSeed
MOV r0, #OsByte_ReadCMOS ; Read configured DumpFormat
MOV r1, #PrintSoundCMOS
SWI XOS_Byte
......@@ -223,8 +224,14 @@ SystemDevices_Init Entry
BLVC AddDevices
ADRVC r0, nullcommand ; setup system var for Null:
SWIVC OS_CLI
ADRVC r0, nullcommand ; setup system variables
SWIVC XOS_CLI
ADRVC r0, zerocommand
SWIVC XOS_CLI
ADRVC r0, randomcommand
SWIVC XOS_CLI
ADRVC r0, urandomcommand
SWIVC XOS_CLI
EXIT
......@@ -232,6 +239,12 @@ SystemDevices_Init Entry
nullcommand
= "Set PrinterType$0 null:",0
zerocommand
= "Set zero$$Path source#zero:",0
randomcommand
= "Set random$$Path source#random:",0
urandomcommand
= "Set urandom$$Path source#urandom:",0
ALIGN
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
......@@ -241,7 +254,7 @@ SystemDevices_ServiceTable
DCD 0
DCD SystemDevices_ServiceEntry-Module_BaseAddr
DCD Service_FSRedeclare
[ standalonemessages
[ standalone
DCD Service_ResourceFSStarting
]
DCD 0
......@@ -252,14 +265,14 @@ SystemDevices_Service ROUT
MOV r0, r0
TEQ r1, #Service_FSRedeclare
[ standalonemessages
[ standalone
TEQNE r1, #Service_ResourceFSStarting
]
MOVNE pc, lr
SystemDevices_ServiceEntry
[ standalonemessages
[ standalone
TEQ r1, #Service_ResourceFSStarting
BNE %FT30
Push "r0-r3,lr"
......@@ -286,6 +299,9 @@ AddDevices Entry "r1-r3"
MOV r2, #(null_FSInfoBlock-Module_BaseAddr)
SWI XOS_FSControl
MOVVC r2, #(source_FSInfoBlock-Module_BaseAddr)
SWIVC XOS_FSControl
MOVVC r2, #(vdu_FSInfoBlock-Module_BaseAddr)
SWIVC XOS_FSControl
......@@ -308,9 +324,9 @@ AddDevices Entry "r1-r3"
EXIT
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Collect all module headers together here in ADR range of AddDevices
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; null - notpermanent, alwaysopen, nullok
null_ModuleBase * Module_BaseAddr
......@@ -320,6 +336,17 @@ null_StartupText * null_ModuleBase
null FSHeader fsinfo_notpermanent + fsinfo_nullnameok + fsinfo_alwaysopen + fsnumber_null
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; source - notpermanent, alwaysopen, nullok, read only, specials
source_ModuleBase * Module_BaseAddr
source_Commands * source_ModuleBase ; ie. 0 - no commands or help
source_StartupText * source_ModuleBase
source_Put * source_ModuleBase
source FSHeader fsinfo_notpermanent + fsinfo_nullnameok + fsinfo_alwaysopen + fsinfo_readonly + fsinfo_special + fsnumber_Source
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; vdu - notpermanent, alwaysopen, nullok
......@@ -406,6 +433,7 @@ SerialOptString DCB "serial:",0
]
null_Name DCB "null", 0
source_Name DCB "source", 0
vdu_Name DCB "vdu", 0
rawvdu_Name DCB "rawvdu", 0
kbd_Name DCB "kbd", 0
......@@ -416,6 +444,7 @@ serial_Name DCB "serial", 0
]
CloseNullFiles DCB "null:close", 0
CloseSourceFiles DCB "source:close", 0
CloseVduFiles DCB "vdu:close", 0
CloseRawVduFiles DCB "rawvdu:close", 0
CloseKbdFiles DCB "kbd:close", 0
......@@ -438,6 +467,10 @@ SystemDevices_Die Entry "r0-r1"
ADR r1, null_Name
BL CloseAndRemoveDevice
ADR r0, CloseSourceFiles
ADR r1, source_Name
BL CloseAndRemoveDevice
ADR r0, CloseVduFiles
ADR r1, vdu_Name
BL CloseAndRemoveDevice
......@@ -475,7 +508,7 @@ SystemDevices_Die Entry "r0-r1"
MOV r0, #0
STR r0, message_file_open
[ standalonemessages
[ standalone
ADRL R0, resourcefsfiles
SWI XResourceFS_DeregisterFiles
]
......@@ -640,7 +673,8 @@ null_Get
null_GBPB
CMP r0, #2 ; nop reads (ie. nothing done)
ASSERT OSGBPB_WriteAtGiven < OSGBPB_WriteAtPTR
CMP r0, #OSGBPB_WriteAtPTR ; nop reads (ie. nothing done)
ADDLS r2, r2, r3 ; Update memory^ for pedants
ADDLS r4, r4, r3 ; Also fileptr for that same crowd
MOVLS r3, #0 ; All done if write / no xfer if read
......@@ -656,6 +690,154 @@ null_Args Entry
BL CommonArgs_Write
B null_ArgsFunc
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; S O U R C E S T R E A M
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; source: supports multiple open files, all distinct
; Special field determines which source it is. Currently implemented are
; 'zero' Input is infinite zeros
; 'random' Input is from PRNG
; 'urandom' Input is from PRNG
; Output is not permitted
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
source_Open ROUT
CMP r0, #fsopen_ReadOnly ; 0 -> OPENIN, 1 -> OPENOUT, 2 -> OPENUP
BNE source_OpInvalid
ADR r2, source_Specials
10
LDRB r4, [r2] ; Length to match
TEQ r4, #0 ; Give up, end of table
BEQ source_OpInvalid
ADD r5, r2, #2 ; Start of template
20
SUBS r4, r4, #1
BMI %FT40
LDRB r0, [r5, r4] ; From table
LDRB r1, [r6, r4] ; From special string
ASCII_LowerCase r1, r3
TEQ r0, r1
BEQ %BT20
30
LDRB r4, [r2], #2 ; Mismatch, jump to next
ADD r2, r2, r4
B %BT10
40
LDRB r4, [r2] ; Template match, guard against substrings
LDRB r1, [r6, r4]
TEQ r1, #0
TEQNE r1, #'.'
TEQNE r1, #','
TEQNE r1, #';'
BNE %BT30 ; No acceptable terminator found
MOV r0, #fsopen_ReadPermission + fsopen_UnbufferedGBPB
; Zero devid, read only, bulk GBPB source of 0's
LDRB r1, [r2, #1] ; Munge special string to a (non zero) sub-FS identifier
MOV r2, #0 ; Unbuffered
RETURNVC
source_Specials
DCB 4, 1, "zero"
DCB 6, 2, "random"
DCB 7, 3, "urandom"
DCB 0
ALIGN
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
source_Get
SUBS r0, r1, #1 ; Which source?
BEQ source_GetZero ; r0 => 0
source_GetRandom
MOV r4, lr
BL source_Rand
MOVS r0, r0, LSR #24
MOV lr, r4
; Fall through
source_GetZero
CMP r0, #256 ; C & V clear
RETURN
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
source_Args Entry
CMP r0, #fsargs_EOFCheck ; Not EOF. Ever
MOVEQ r2, #0
BLNE CommonArgs
B source_OpProcessed
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
source_Close
RETURNVC
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
source_File Entry
BL CommonFile ; Can't do Load/Save/Create
B source_OpProcessed ; so no monitor filename needed
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
source_Func Entry
BL CommonFunc
B source_OpProcessed ; so no monitor filename needed
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
source_GBPB Entry
TEQ r0, #OSGBPB_ReadFromGiven
TEQNE r0, #OSGBPB_ReadFromPTR
PullEnv NE
BNE source_OpInvalid ; Only reads please
ADD r4, r4, r3 ; New file pointer
10
TEQ r3, #0 ; Anything to do?
EXIT EQ
SUBS r0, r1, #1 ; Which source?
BLNE source_Rand
TST r2, #3
BNE %FT20
CMP r3, #4
STRCS r0, [r2], #4
SUBCS r3, r3, #4
BCS %BT10
20 ; Not aligned or < one word left
STRB r0, [r2], #1
SUB r3, r3, #1
B %BT10
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
source_Rand
LDR r1, SourceRandSeed
LDR r2, =1103515245
LDR r0, =12345
MLA r0, r1, r2, r0 ; ISO9899:1999 7.20.2.2
STR r0, SourceRandSeed
MOV pc, lr
source_OpProcessed
EXIT EQ ; EQ -> op done ok or nop'ed
PullEnv ; NE -> make some noise
source_OpInvalid
addr r0, ErrorBlock_BadFilingSystemOperation
Push "r1, lr"
addr r1, source_Name
BL copy_error_one ; Will set the V bit
Pull "r1, pc"
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; V D U S T R E A M S
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
......@@ -1372,7 +1554,7 @@ printer_PutToObject
printer_GBPB Entry
TEQ r0, #2 ; only write with no pointer supported!
TEQ r0, #OSGBPB_WriteAtPTR ; only write with no pointer supported!
BNE NaffPrinterOp
AND r1, r1, #&FF00
......@@ -1766,17 +1948,9 @@ serial_Args Entry
InsertDebugRoutines
]
GBLS conditionalgetbodge
[ standalonemessages
GBLS ApplicationName
ApplicationName SETS "SystemDevs"
conditionalgetbodge SETS "GET s.ResFiles"
[ standalone
resourcefsfiles
|
conditionalgetbodge SETS ""
]
$conditionalgetbodge
[ standalonemessages
DCD 0
ResourceFile $MergedMsgs, Resources.SystemDevs.Messages
DCD 0
]
END