[okl4-developer] Question about memsection_create_fixed, iguana server library
Nelson Tam
nelson at ok-labs.com
Tue Apr 15 11:39:42 EST 2008
Hi Anand,
On 11/04/2008, at 2:49 PM, Anand Gore wrote:
> I wanted to dynamically load a binary to a specific location e.g.
>
> 0x2000000 in my task/thread. Here is the code I have -
>
> mnsigned int base_address=0x200000;
>
> mm_s memsection_create_fixed(section_size, base_address); if(mm_s !=
> 0) {
>
> memcpy(base_address, binary_buffer, sizeof(binary_buffer));
>
> func=(func_t)base_address;
>
> func();
>
> }
>
> The binary is built and linked to a fixed address 0x2000000, such
> that there will be an initialization function at 0x2000000.
>
> But I read in the document that the memsection_create_fixed is going
> to go away sometime down the line.
>
> I am wondering if there is going to be a replacement function for
> that or there is a better way to do this.
>
There certainly will be, in fact, there already is. Here's how:
1. Compile OKL4 as normal, and find the file build/images/weaver.xml
2. Find the <physical_memory> elements. Is 0x2000000 contained in the
regions? If not, add a new <physical_memory> element with <region
base="0x2000000" size=[hex value of section_size] />.
3. Find the <physical_pool> elements. Create a new pool:
<physical_pool name="my_binary_pool">
<memory base="0x2000000" size=[hex value of section_size] />
</physical_pool>
4. Find the <program> XML element that contains the thread that you
want to give the binary to.
<program ...>
<memsection name="my_binary" file="/path/to/binary"
phys_addr="0x2000000" physpool="my_binary_pool">
</program>
This is neat, because this even copies the contents of /path/to/binary
to 0x2000000 physical. Two things to beware of - the binary must fit
into section_size; and the binary is copied into the region verbatim
(wouldn't work if it is an ELF file).
The memsection will be created, mapped, and its contents initialised
before any user threads are executed.
During runtime, the thread may obtain the reference to the fixed
memsection by doing:
binary_ms = env_memsection(iguana_getenv("MY_BINARY")); /* note
upper case */
Hope this helps! Please let us know if you run into any obstacles.
--
(nt)
Nelson Tam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1560 bytes
Desc: not available
Url : http://lists.okl4.org/pipermail/developer/attachments/20080415/ec5f6536/attachment.bin
More information about the Developer
mailing list