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