Reason Action
0 Initialise standard heap
1 Describe heap
2 Allocate block
3 Free block
4 Reallocate block
5 Tidy heap
6 Compact heap
7 Find anchor
8 Fix blocks
9 Unfix blocks regardless of counter
10 Unfix blocks
11 Increase anchors
12 Allocate with anchor extend
13 Free all blocks
14 Select heap
15 Relocate heap
16 Create a heap in a heap block
Provided by HeapManager
Initialise standard heap
Entry
R0 = 0
R1 -> base of heap
R2 = number of anchors to allocate
Initialises the standard heap. R1 points to the base of the heap - it will grow upwards from here. R2 specifies the numbers of anchors to allocate initially. Each anchor takes 8 bytes. Note that R1 is rounded up to the nearest multiple of 8 plus 4 (ie. 8N+4). The heap is automatically selected as the current heap.
Describe heap
Entry
R0 = 1
Exit
R0 = currently selected heap pointer, or +1 for standard heap
R2 = largest available block size
R3 = total free
R4 = memory used by heap
R5 = number of anchors allocated
R6 = number of anchors in use
Adds up all the sizes of the free blocks, and returns information about memory used by the heap. If the heap is empty then R2-R6 will be zero.
Allocate block
Entry
R0 = 2
R2 = size of block required
Exit
R1 -> anchor or zero if allocation failed
Tries to find a block of the required size. Increases the WimpSlot if necessary. If a call to Wimp_SlotSize fails then zero will be returned. Note that the size is rounded up to the next multiple of 8 plus 4.
To get a pointer to the actual block just load the word indirected by the anchor, ie block=!anchor.
Free block
Entry
R0 = 3
R1 = block pointer
Frees the memory used by the specified block.
Reallocate block
Entry
R0 = 4
R1 = block pointer
R2 = new size required
Exit
R1 -> anchor (the same anchor as before) or 0 if reallocate failed
Tries to resize the specified block. You should check R1 on exit to see if the resize was successful (only on increasing the size, decreasing the size will always be successful).
Tidy heap
Entry
R0 = 5
Tries to tidy the heap, reducing the WimpSlot if possible. This can be automatically performed once a second (in WimpExt_PrePoll) if you set bit 3 of R2 when you called WimpExt_Initialise. Note that this routine does not tidy the heap fully, it just does a little bit each time it is called. This is to keep the time cost down.
Compact heap
Entry
R0 = 6
Repeatedly calls Tidy Heap, until the heap is as small as it can get.
Find anchor
Entry
R0 = 7
R1 = block pointer
Exit
R1 -> anchor
Given a block pointer, returns a pointer to that block‘s anchor.
Fix blocks
Entry
R0 = 8
Fixes the heap. Subsequent calls to the Tidy or Compact routines will have no effect. Effectively, the heap becomes a non-relocatable heap like the RMA. This call is provided so that if you temporarily need to rely on the blocks not moving, you can easily do so. WimpExtension keeps a counter of the number of times you call this routine, so that if you, for example, fix the blocks twice in a row then you need to unfix them twice in a row before they are actually unfixed.
Unfix blocks regardless of counter
Entry
R0 = 9
Unfixes the heap, so that garbage disposal routines will work again. This call zeroes the counter straight away - ie. the blocks are immediately unfixed no matter how many times you called the fix routine.
Unfix blocks
Entry
R0 = 10
Unfixes the heap, so that garbage disposal routines will work again. This routine decrements the fix counter, and only actually unfixes the blocks if the counter reaches zero.
Increase anchors
Entry
R0 = 11
R2 = number of anchors to add
Exit
R1 = 0 indicates failure, non-zero indicates success
Increases the number of anchors. This routine is quite slow as it often has to move the entire heap up in memory so you should use this routine sparingly, if you need to use it at all. Note that this SWI causes blocks to be relocated.
Allocate with anchor extend
Entry
R0 = 12
R2 = size of block required
Exit
R1 -> anchor or zero if allocation failed
Tries to find a block of the required size. Increases the WimpSlot if necessary. If a call to Wimp_SlotSize fails then zero will be returned. Note that the size is rounded up to the next multiple of 8 plus 4. If no free anchors are available then the increase anchors call is used to make some more; therefore using this SWI can cause blocks to be relocated. It is, however, the recommended call to use for allocating blocks as it isn‘t limited by the number of anchors already created.
Free all blocks
Entry
R0 = 13
Frees all blocks in the currently selected heap belonging to your task.
Select heap
Entry
R0 = 14
R1 = heap pointer, or +1 for standard heap, or -1 for no change
Exit
R0 = previous heap pointer, or 0 if no previously selected heap
R1 = current heap pointer, or 0 if no currently selected heap
Selects a new heap to be used by the other WimpExt_Heap calls.
Relocate heap
Entry
R0 = 15
Compares the heap addresses specified by hp_base and hp_rootptr. If they are different, then hp_base is updated by hp_rootptr, and the anchors are recalculated to account for the change of address.
Create a heap in a heap block
Entry
R0 = 16
R1 = heap pointer (blank, it will be filled in by this call)
R2 = number of anchors to create
Exit
R1 = heap pointer, or 0 if the call failed due to lack of memory
This call creates a new heap inside a heap block in the currently selected heap. The new heap is not selected as the current heap.
|
|
|