4 ; Flexible memory handling
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Sapphire library.
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)
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.
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.
27 ;----- Overview -------------------------------------------------------------
49 [ :LNOT::DEF:flex__dfn
52 ;+ LIB sapphire:^.bsh.flex
60 ; Use: Compacts the flex heap by one iteration.
64 ; --- flex_compact ---
70 ; Use: Completely compacts the flex heap.
76 ; On entry: R0 == pointer to the flex anchor
80 ; Use: Frees a flex block allocated by flex_alloc.
86 ; On entry: R0 == pointer to a flex anchor
87 ; R1 == desired size of flex block
89 ; On exit: CS if no memory could be allocated, CC otherwise
91 ; Use: Allocates a block in the shifting heap.
97 ; On entry: R0 == pointer to flex anchor
99 ; On exit: R0 == size of allocated block
101 ; Use: Reads the size of a flex block.
105 ; --- flex_extend ---
107 ; On entry: R0 == pointer to flex anchor
108 ; R1 == new size of block to set
110 ; On exit: CS if it failed due to lack of memory, CC otherwise
112 ; Use: Alters the size of a block to the given value.
116 ; --- flex_midExtend ---
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)
122 ; On exit: CS if it failed due to lack of memory, CC otherwise
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'.
128 IMPORT flex_midExtend
136 ; Use: Initialises the flex heap for use.
140 ; --- flex_stackPtr ---
142 ; On entry: R0 == 0 to read, or value to set
144 ; On exit: R0 == old value
146 ; Use: Either reads or writes the flex stack pointer. This sort
147 ; of thing is useful in exception handlers etc.
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.
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.
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.
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.
185 ; On exit: Registers loaded from relocation stack as requested
187 ; Use: Restores registers saved on flex's relocation stack. See
188 ; flex_save for calling information and details about the
193 ;----- Useful macros --------------------------------------------------------
195 ; --- Macro: FSAVE ---
197 ; Arguments: rList == quoted register list to save on relocation stack
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.
203 ; For full details about the flex relocation stack, see
214 ; --- Macro: FLOAD ---
216 ; Arguments: rList == quoted register list to read from relocation stack
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.
222 ; For full details about the flex relocation stack, see
235 ;----- That's all, folks ----------------------------------------------------