6 ; © 1995-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's core utilities (coreutils).
13 ; Coreutils is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
18 ; Coreutils is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
23 ; You should have received a copy of the GNU General Public License
24 ; along with Coreutils. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ;----- Standard header ------------------------------------------------------
34 ;----- External dependencies ------------------------------------------------
38 ;----- Main code ------------------------------------------------------------
40 AREA |!!!Util$$Code|,CODE,READONLY
44 ; On entry: R0 == pointer to command line
45 ; R1 == pointer to command tail
46 ; R12 == pointer to workspace
47 ; R13 == pointer to stack
49 ; On exit: May return an error
51 ; Use: Sets up a wimpslot.
55 ; --- Find the command line ---
57 STR R14,[R12,#0] ;Store the link away
58 ADR R0,ss__keys ;Point to key tag definition
59 ADD R2,R12,#256 ;Output into workspace
60 MOV R3,#256 ;Allow 256 bytes for this
61 SWI XOS_ReadArgs ;Read the arguments
62 BVS ss__error ;If it failed, return error
64 ; --- Now process the arguments ---
66 LDR R0,[R12,#256+0] ;Load the `-help' switch
67 CMP R0,#0 ;Is that set?
68 BNE ss__help ;Yes -- give some help then
70 LDR R0,[R12,#256+4] ;Load the base offset
71 CMP R0,#0 ;Is that defined?
72 ADREQ R0,ss__usage ;No -- point to error
73 BEQ ss__error ;And return an error
74 BL ss__read ;Read this number
75 MOV R9,R0 ;And look after the result
77 LDR R0,[R12,#256+8] ;Load the heap offset
78 CMP R0,#0 ;Is that defined?
79 BLNE ss__read ;Yes -- read the value
80 MOV R10,R0 ;And look after that too
82 LDR R0,[R12,#256+12] ;Load the flex offset
83 CMP R0,#0 ;Is that defined?
84 BLNE ss__read ;Yes -- read the value
85 ADD R10,R10,R0 ;And bump on the heap size
87 LDR R8,[R12,#256+16] ;Load the application name
88 CMP R8,#0 ;Is that defined?
89 ADREQ R8,ss__app ;No -- use a default then
91 ; --- Read the memory limits imposed on me ---
93 MOV R0,#14 ;Read application space
94 MOV R1,#0 ;Don't provide new value
95 SWI XOS_ChangeEnvironment ;Read the value
96 MOV R7,R1 ;Look after that then
97 MOV R0,#0 ;Read the memory limit
98 MOV R1,#0 ;Don't provide new value
99 SWI XOS_ChangeEnvironment ;Read the value
100 MOV R6,R1 ;Look after that too
101 CMP R6,R7 ;Are these the same?
102 BCS %f00 ;We're OK -- skip onwards
104 ; --- We're running as a subprogram ---
106 SUB R14,R6,#&8000 ;Find how much memory I have
107 CMP R14,R9 ;Is there enough for base?
108 BCC ss__badSub ;No -- complain then
110 MOV R1,R7 ;Extend the memory limit
111 SWI XOS_ChangeEnvironment ;Now I can extend the slot
112 MOV R0,#-1 ;I want to read the size
113 MOV R1,#-1 ;Leave next slot alone too
114 SWI XWimp_SlotSize ;Read the current slot size
115 MOV R5,R0 ;Remember this value
116 ADD R0,R5,R10 ;Add on the heap size
117 MOV R1,#-1 ;Leave next slot alone still
118 SWI XWimp_SlotSize ;Try doing that then
119 SUB R7,R0,R5 ;Find how much we added
120 MOV R0,R5 ;Restore to old value
121 MOV R1,#-1 ;Leave next slot alone too
122 SWI XWimp_SlotSize ;Try doing that then
123 MOV R0,#0 ;Now put the memorylimit back
124 MOV R1,R6 ;Get the old memory limit
125 SWI XOS_ChangeEnvironment ;Put that back now
127 CMP R7,R10 ;Did we get enough memory?
128 BCC ss__noRoom ;No -- complain bitterly
129 B ss__end ;We finished OK then
131 ; --- We're in control here ---
133 00 ADD R6,R9,R10 ;Try to get it all
134 MOV R0,R6 ;Get this value
135 MOV R1,#-1 ;Don't change next slot
136 SWI XWimp_SlotSize ;Try doing that then
137 CMP R0,R6 ;Did we get enough?
138 BCC ss__noRoom ;No -- complain then
139 MOV R0,R9 ;Now set up base slot
140 MOV R1,#-1 ;Don't change next slot
141 SWI XWimp_SlotSize ;Try doing that then
142 B ss__end ;And stop the program
144 ss__keys DCB "help/S," ;0
151 DCB "Syntax: SetSlot -base <size>[K|M] "
152 DCB "[-heap <size>[K|M]] [-flex <size>[K|M]] "
153 DCB "[-appName <name>]",0
155 ss__app DCB "Application",0
161 ; On entry: R0 == pointer to a string
163 ; On exit: R0 == numeric value read from string
165 ; Use: Reads a number represented by a string. The number may be
166 ; postfixed by `K' or `M' to indicate that it's shifted left by
167 ; 10 or 20 bits. The resulting value is then aligned up to
168 ; the next multiple of the machine's page size. Scary.
172 STMFD R13!,{R1,R2,R14} ;Save some registers
174 ; --- Read the numeric value ---
176 MOV R1,R0 ;Point to the string
177 MOV R0,#10 ;By default it's base 10
178 SWI XOS_ReadUnsigned ;Read that value
179 BVS ss__error ;Handle a possible error
180 LDRB R14,[R1],#1 ;Find the terminating char
181 ORR R0,R14,#&20 ;Force it to lowercase
182 CMP R0,#'m' ;Is value in megabytes?
183 MOVEQ R2,R2,LSL #10 ;Yes -- shift it then
184 CMPNE R0,#'k' ;Is value in kilobytes?
185 MOVEQ R2,R2,LSL #10 ;Yes -- shift it then
186 LDREQB R14,[R1],#1 ;And get another byte
187 CMP R14,#&20 ;Make sure this is ctrl char
188 ADRCS R0,ss__junk ;No -- point to error
189 BCS ss__error ;And raise the error
191 ; --- Now align it to size ---
193 SWI XOS_ReadMemMapInfo ;Find out about memory map
194 BVS ss__error ;Handle a possible error
195 SUB R14,R0,#1 ;Turn page size into bitmask
196 ADD R0,R2,R14 ;And proceed to align
198 LDMFD R13!,{R1,R2,PC}^ ;Return to caller
201 DCB "Number not recognised",0
207 ; On entry: R9, R10 == memory requirements
211 ; Use: We didn't have enough memory to start as a subprogram, so
212 ; we complain to the user.
216 ADD R1,R12,#512 ;Point to spare bit of memory
217 MOV R14,#1 ;Get an error number
218 STR R14,[R1],#4 ;Store at the beginning
219 MOV R0,R8 ;Point to application name
220 BL ss__strcpy ;Copy that over
221 ADR R0,ss__badSubErr ;Point to the error
222 BL ss__strcpy ;Copy that too
223 MOV R0,R9,LSR #10 ;Get the size in K
224 MOV R2,#256 ;And a bogus buffer size
225 SWI XOS_ConvertInteger4 ;Write that out too
226 ADR R0,ss__badSubEr2 ;Point to rest of the text
227 BL ss__strcpy ;Copy that over
228 ADD R0,R12,#512 ;Point to base of error
229 B ss__error ;Complain now
231 ss__badSubErr DCB " must have at least ",0
232 ss__badSubEr2 DCB "K left in application space to start up as a "
239 ; On entry: R9, R10 == memory requirements
243 ; Use: We don't have enough memory for the heap or somesuch.
247 ADD R1,R12,#512 ;Point to spare bit of memory
248 MOV R14,#1 ;Get an error number
249 STR R14,[R1],#4 ;Store at the beginning
250 MOV R0,R8 ;Point to application name
251 BL ss__strcpy ;Copy that over
252 ADR R0,ss__noRoomErr ;Point to the error
253 BL ss__strcpy ;Copy that too
254 MOV R0,R9,LSR #10 ;Get the size in K
255 ADD R0,R0,R10,LSR #10 ;Add on the heap size
256 MOV R2,#256 ;And a bogus buffer size
257 SWI XOS_ConvertInteger4 ;Write that out too
258 ADR R0,ss__noRoomEr2 ;Point to rest of the text
259 BL ss__strcpy ;Copy that over
260 ADD R0,R12,#512 ;Point to base of error
261 B ss__error ;Complain now
263 ss__noRoomErr DCB " needs at least ",0
264 ss__noRoomEr2 DCB "K of memory available to start up",0
270 ; On entry: R0 == pointer to source
271 ; R1 == pointer to destination
273 ; On exit: R1 == pointer to terminating null
275 ; Use: Copies a string.
279 STMFD R13!,{R14} ;Save a register
280 00 LDRB R14,[R0],#1 ;Load a byte
281 CMP R14,#&20 ;Is this the end?
282 MOVCC R14,#0 ;Yes -- null terminate then
283 STRB R14,[R1],#1 ;Store it in the output
284 BCS %b00 ;Loop back if not done
285 SUB R1,R1,#1 ;Point back at the null
286 LDMFD R13!,{PC}^ ;And return to caller
296 ; Use: Gives help about setSlot.
300 ADR R0,ss__helpText ;Point to the help text
301 MOV R1,#0 ;Use system dictionary
302 LDR R2,=version ;Find the version string
303 ADR R14,main ;Find my base address
304 ADD R2,R14,R2 ;And get the string address
305 SWI XOS_PrettyPrint ;Display the text
306 B ss__end ;And return to caller
308 ss__helpText DCB "SetSlot ",27,0,13
310 DCB "Syntax: SetSlot -base <size>[K|M] "
311 DCB "[-heap <size>[K|M]] [-flex <size>[K|M]] "
312 DCB "[-appName <name>]",13
314 DCB "Ensures that there is enough memory for an "
315 DCB "application to start up. The base size is the "
316 DCB "amount of memory for the main image. The heap "
317 DCB "and flex sizes are added together to give the "
318 DCB "required initial size for the shifting heap.",13
325 ; On entry: R0 == pointer to error
329 ; Use: Returns to the OS with an error.
333 LDR R14,[R12,#0] ;Load the return address
334 ORRS PC,R14,#V_flag ;And return
344 ; Use: Returns to the OS successfully.
348 LDR R14,[R12,#0] ;Load the return address
349 BICS PC,R14,#V_flag ;And return
353 ;----- That's all, folks ----------------------------------------------------