j
: Next unread message k
: Previous unread message j a
: Jump to all threads
j l
: Jump to MailingList overview
On Jun 4, 2012, at 7:53 PM, openbios-request@openbios.org wrote:
On 2012-Jun-3 18:48 , Programmingkid wrote:
What word can be used in OpenBIOS to dynamically allocate memory? I have tried ALLOCATE, but that word doesn't exist in the dictionary.
Alloc-mem is the one I'm most likely to use, unless I need dma-able memory, in whch case dma-alloc will be defined by the io nexus.
There's also always "," to allocate from the heap, depending on how much you need and where.
I couldn't find any documentation on alloc-mem, but I think this is how it works. It pops the top number on the stack and tries to allocate that amount of memory. If it succeeds it returns the address of the memory. If it fails, it returns 0. I think I would release the memory using free-mem. Does this sound about right?
Attachments:
I couldn't find any documentation on alloc-mem,
See the Open Firmware specification.
but I think this is how it works. It pops the top number on the stack and tries to allocate that amount of memory. If it succeeds it returns the address of the memory. If it fails, it returns 0. I think I would release the memory using free-mem. Does this sound about right?
alloc-mem ( len -- a-addr ) free-mem ( a-addr len -- )
alloc-mem calls ABORT" if it fails. Note that free-mem takes the length as input as well.
Segher
On 2012-Jun-6 08:03 , Programmingkid wrote:
I couldn't find any documentation on alloc-mem, but I think this is how it works. It pops the top number on the stack and tries to allocate that amount of memory. If it succeeds it returns the address of the memory. If it fails, it returns 0. I think I would release the memory using free-mem. Does this sound about right?
It's documented in ieee 1275, page 109.
As for free-mem, that's probably correct, but most FCode never calls it. The assumption is that any memory allocated during boot needs to stay allocated.