Programmingkid | 6 Jun 2012 14:03
Picon

Re: Dynamic memory allocation


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?
<div>
<div>On Jun 4, 2012, at 7:53 PM, <a href="mailto:openbios-request@...">openbios-request@...g</a> wrote:</div>
<div>
<br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span">On 2012-Jun-3 18:48 , Programmingkid wrote:<br><blockquote type="cite">What word can be used in OpenBIOS to dynamically allocate memory? I have tried ALLOCATE, but that word doesn't exist in the dictionary.<br>
</blockquote>
<br>Alloc-mem is the one I'm most likely to use, unless I need dma-able<span class="Apple-converted-space">&nbsp;</span><br>memory, in whch case dma-alloc will be defined by the io nexus.<br><br>There's also always "," to allocate from the heap, depending on how much<span class="Apple-converted-space">&nbsp;</span><br>you need and where.<br></span></blockquote>
</div>
<br><div>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?</div>
</div>
Tarl Neustaedter | 6 Jun 2012 19:23

Re: Dynamic memory allocation

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.

Segher Boessenkool | 6 Jun 2012 19:18

Re: Dynamic memory allocation

> 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


Gmane