Initial revision
[ssr] / StraySrc / Libraries / Core / sh / flex
1 ;
2 ; flex.sh
3 ;
4 ; Flexible memory handling
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Flex.
12 ;
13 ; Flex 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)
16 ; any later version.
17 ;
18 ; Flex 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.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Flex. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Overview -------------------------------------------------------------
28 ;
29 ; Functions provided:
30 ;
31 ; flex_reduce
32 ; flex_compact
33 ; flex_free
34 ; flex_alloc
35 ; flex_size
36 ; flex_extend
37 ; flex_midExtend
38 ; flex_init
39 ; flex_save
40 ; flex_load
41 ; flex_dump
42 ;
43 ; Macros provided:
44 ;
45 ; FSAVE
46 ; FLOAD
47
48 ;+ LIB sapphire:^.bsh.flex
49
50 ; --- flex_reduce ---
51 ;
52 ; On entry: --
53 ;
54 ; On exit: --
55 ;
56 ; Use: Compacts the flex heap by one iteration.
57
58 IMPORT flex_reduce
59
60 ; --- flex_compact ---
61 ;
62 ; On entry: --
63 ;
64 ; On exit: --
65 ;
66 ; Use: Completely compacts the flex heap.
67
68 IMPORT flex_compact
69
70 ; --- flex_free ---
71 ;
72 ; On entry: R0 == pointer to the flex anchor
73 ;
74 ; On exit: --
75 ;
76 ; Use: Frees a flex block allocated by flex_alloc.
77
78 IMPORT flex_free
79
80 ; --- flex_alloc ---
81 ;
82 ; On entry: R0 == pointer to a flex anchor
83 ; R1 == desired size of flex block
84 ;
85 ; On exit: CS if no memory could be allocated, CC otherwise
86 ;
87 ; Use: Allocates a block in the shifting heap.
88
89 IMPORT flex_alloc
90
91 ; --- flex_size ---
92 ;
93 ; On entry: R0 == pointer to flex anchor
94 ;
95 ; On exit: R0 == size of allocated block
96 ;
97 ; Use: Reads the size of a flex block.
98
99 IMPORT flex_size
100
101 ; --- flex_extend ---
102 ;
103 ; On entry: R0 == pointer to flex anchor
104 ; R1 == new size of block to set
105 ;
106 ; On exit: CS if it failed due to lack of memory, CC otherwise
107 ;
108 ; Use: Alters the size of a block to the given value.
109
110 IMPORT flex_extend
111
112 ; --- flex_midExtend ---
113 ;
114 ; On entry: R0 == pointer to a flex anchor
115 ; R1 == `at' -- position in block to extend from
116 ; R2 == `by' -- how many bytes to extend (may be -ve)
117 ;
118 ; On exit: CS if it failed due to lack of memory, CC otherwise
119 ;
120 ; Use: Either creates a gap in a block (by>0) or deletes bytes
121 ; from a block. This is always done in such a way that the
122 ; byte originally at offset `at' is now at offset `at'+`by'.
123
124 IMPORT flex_midExtend
125
126 ; --- flex_init ---
127 ;
128 ; On entry: --
129 ;
130 ; On exit: --
131 ;
132 ; Use: Initialises the flex heap for use.
133
134 IMPORT flex_init
135
136 ; --- flex_save ---
137 ;
138 ; On entry: --
139 ;
140 ; On exit: --
141 ;
142 ; Use: Saves some registers on the flex relocation stack. R13
143 ; and R14 cannot be saved -- these registers are corrupted
144 ; during this routine's execution.
145 ;
146 ; Values saved on the flex relocation stack are adjusted as
147 ; flex moves blocks of memory around, so that they still point
148 ; to the same thing as they did before. Obviously, values
149 ; which aren't pointers into flex blocks may be corrupted.
150 ; Values pointing to objects deleted (either free blocks, or
151 ; areas removed by flex_midExtend) may also be corrupted.
152 ;
153 ; Since this routine takes no arguments, some other method has
154 ; to be used. The method chosen is to follow the call to
155 ; flex_save with a LDM or STM instruction containing the
156 ; registers to be saved. This instruction is skipped by the
157 ; routine, and thus not executed.
158 ;
159 ; Note that if you give the LDM or STM the same condition code
160 ; as the BL preceding it, it will never be executed, since
161 ; flex_save skips it if the condition is true and it can't be
162 ; executed if the condition is false.
163
164 [ :DEF:FLEX_STACK
165 IMPORT flex_save
166 ]
167
168 ; --- flex_load ---
169 ;
170 ; On entry: --
171 ;
172 ; On exit: Registers loaded from relocation stack as requested
173 ;
174 ; Use: Restores registers saved on flex's relocation stack. See
175 ; flex_save for calling information and details about the
176 ; relocation stack.
177
178 [ :DEF:FLEX_STACK
179 IMPORT flex_load
180 ]
181
182 ;----- Useful macros --------------------------------------------------------
183
184 ; --- Macro: FSAVE ---
185 ;
186 ; Arguments: rList == quoted register list to save on relocation stack
187 ;
188 ; Use: Assembles code to write the given register list on the
189 ; flex relocation stack. The register list should be in the
190 ; same form as that for an STM or LDM instruction.
191 ;
192 ; For full details about the flex relocation stack, see
193 ; flex_save.
194
195 [ :DEF:FLEX_STACK
196
197 MACRO
198 $label FSAVE $rList
199
200 BL flex_save
201 STMEA R14!,{$rList}
202
203 MEND
204
205 ]
206
207 ; --- Macro: FLOAD ---
208 ;
209 ; Arguments: rList == quoted register list to read from relocation stack
210 ;
211 ; Use: Assembles code to read the given register list from the
212 ; flex relocation stack. The register list should be in the
213 ; same form as that for an STM or LDM instruction.
214 ;
215 ; For full details about the flex relocation stack, see
216 ; flex_save.
217
218 [ :DEF:FLEX_STACK
219
220 MACRO
221 $label FLOAD $rList
222
223 BL flex_load
224 LDMEA R14!,{$rList}
225
226 MEND
227
228 ]
229
230 ;----- That's all, folks ----------------------------------------------------
231
232 END