updated the new, which changed the display value<br>static void setup(void)<br>{<br> int size = (unsigned int)(&_eheap - &_heap) - HDRSIZE;<br> *((hdrtype_t *) hstart) = FREE_BLOCK(size);<br>// printf("%s memory size:0x%x,begin:0x%x end:0x%x, hstart:0x%x\n",__func__,size,(unsigned int)&_heap,(unsigned int)&_eheap,(unsigned int )*((hdrtype_t *) hstart));<br>
<br><br>}<br><br>static void *alloc(int len)<br>{<br> hdrtype_t header;<br> void *ptr = hstart;<br> <span style="color: rgb(255, 0, 0);"> printf("%s %d length:0x%x,ptr=0x%x \n",__func__,__LINE__,len,(unsigned int )ptr);</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);"> printf("%s %d memory begin:0x%x end:0x%x, hstart:0x%x\n",__func__,__LINE__,(unsigned int)&_heap,(unsigned int)&_eheap,(unsigned int ) hstart);</span><br> /* Align the size. */<br>
len = (len + 3) & ~3;<br> <br> if (!len || len > 0xffffff)<br> return (void *)NULL;<br>// while(1);<br><br> /* Make sure the region is setup correctly. */<br> if (!HAS_MAGIC(*((hdrtype_t *) ptr))){<br>
setup();<br> }<br> <span style="color: rgb(255, 0, 0);"> if (!HAS_MAGIC(*((hdrtype_t *) ptr))){</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> printf("set up error,*ptr=0x%x\n",(unsigned int)*((hdrtype_t *) ptr));</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);"> }</span><br style="color: rgb(255, 0, 0);"><br> /* Find some free space. */<br> do {<br> header = *((hdrtype_t *) ptr);<br> int size = SIZE(header);<br><br> if (!HAS_MAGIC(header) || size == 0) {<br>
printf("memory allocator panic!!! the size=0x%x. header=0x%x\n",size,(unsigned int)header);<br> halt();<br> }<br><br> if (header & FLAG_FREE) {<br> if (len <= size) {<br>
void *nptr = ptr + (HDRSIZE + len);<br> int nsize = size - (HDRSIZE + len);<br><br> /* If there is still room in this block,<br> * then mark it as such otherwise account<br>
* the whole space for that block.<br> */<br><br> if (nsize > 0) {<br> /* Mark the block as used. */<br> *((hdrtype_t *) ptr) = USED_BLOCK(len);<br>
<br> /* Create a new free block. */<br> *((hdrtype_t *) nptr) =<br> FREE_BLOCK(nsize);<br> } else {<br> /* Mark the block as used. */<br>
*((hdrtype_t *) ptr) = USED_BLOCK(size);<br> }<br><br> return (void *)(ptr + HDRSIZE);<br> }<br> }<br><br> ptr += HDRSIZE + size;<br><br> } while (ptr < hend);<br>
<br> /* Nothing available. */<br> return (void *)NULL;<br>}<br>result log:<br>Running option rom at ce00:0003<br>hello, initialize_usb<br>00:13.0 4387:1002.0 OHCI controller<br>Not supported.<br>00:13.1 4388:1002.1 OHCI controller<br>
Not supported.<br>00:13.2 4389:1002.2 OHCI controller<br>Not supported.<br>00:13.3 438a:1002.3 OHCI controller<br>Not supported.<br>00:13.4 438b:1002.4 OHCI controller<br>Not supported.<br>00:13.5 4386:1002.5 EHCI controller<br>
Not supported.<br>00:05.0 3038:1106.0 UHCI controller<br><span style="color: rgb(255, 0, 0);">alloc 82 length:0x238,ptr=0x3077e0 </span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);">alloc 83 memory begin:0x77e0 end:0x577e0, hstart:0x300000</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">set up error,*ptr=0xa2c0e2cc</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);">memory allocator panic!!! the size=0xc0e2cc. header=0xa2c0e2cc</span><br><br>
<div class="gmail_quote">On Sun, Aug 2, 2009 at 4:27 AM, Jason Wang <span dir="ltr"><<a href="mailto:wangqingpei@gmail.com">wangqingpei@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br clear="all">Hi all,<br> I added some printf message into malloc.c, and find that the function setup() which used to init the memory seems not executed very well. <br>I put my own malloc.c and the log attached to this mail. Hope some one can help me to find out the problems.<br>
<br>static void setup(void)<br>{<br> int size = (unsigned int)(&_eheap - &_heap) - HDRSIZE;<br><br> *((hdrtype_t *) hstart) = FREE_BLOCK(size);<br> <span style="color: rgb(255, 0, 0);">printf("%s the memory size:0x%x,begin:0x%x end:0x%x, hstart:0x%x\n",__func__,size,(unsigned int)&_heap,(unsigned int)&_eheap,(unsigned int )*((hdrtype_t *) hstart));</span><br style="color: rgb(255, 0, 0);">
<br><br>}<br><br>static void *alloc(int len)<br>{<br> <span style="color: rgb(255, 0, 0);"> hdrtype_t header;</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> void *ptr = hstart;</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);"> printf("%s length=0x%x, the ptr=0x%x\n",__func__,len,(unsigned int )*((hdrtype_t*)ptr));</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> printf("%s the memory begin:0x%x end:0x%x, hstart:0x%x\n",__func__,(unsigned int)&_heap,(unsigned int)&_eheap,(unsigned int )*((hdrtype_t *) hstart));</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);"> /* Align the size. */</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> len = (len + 3) & ~3;</span><br style="color: rgb(255, 0, 0);"><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);"> if (!len || len > 0xffffff)</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> return (void *)NULL;</span><br style="color: rgb(255, 0, 0);">
<br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);"> /* Make sure the region is setup correctly. */</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> if (!HAS_MAGIC(*((hdrtype_t *) ptr)))</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);"> setup();</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> if (!HAS_MAGIC(*((hdrtype_t *) ptr))){</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> printf("set up failed,ptr=0x%x\n",(unsigned int)*((hdrtype_t *) ptr));</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);"> }</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> /* Find some free space. */</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> do {</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);"> header = *((hdrtype_t *) ptr);</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> int size = SIZE(header);</span><br style="color: rgb(255, 0, 0);">
<br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> if (!HAS_MAGIC(header) || size == 0) {</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> printf("memory allocator panic!!! the size=0x%x. header=0x%x\n",size,(unsigned int)header);</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);"> halt();</span><br> }<br><br> if (header & FLAG_FREE) {<br> if (len <= size) {<br> void *nptr = ptr + (HDRSIZE + len);<br> int nsize = size - (HDRSIZE + len);<br>
<br> /* If there is still room in this block,<br> * then mark it as such otherwise account<br> * the whole space for that block.<br> */<br><br> if (nsize > 0) {<br>
/* Mark the block as used. */<br> *((hdrtype_t *) ptr) = USED_BLOCK(len);<br><br> /* Create a new free block. */<br> *((hdrtype_t *) nptr) =<br>
FREE_BLOCK(nsize);<br> } else {<br> /* Mark the block as used. */<br> *((hdrtype_t *) ptr) = USED_BLOCK(size);<br> }<br><br> return (void *)(ptr + HDRSIZE);<br>
}<br> }<br><br> ptr += HDRSIZE + size;<br><br> } while (ptr < hend);<br><br> /* Nothing available. */<br> return (void *)NULL;<br>}<br>log:<br>Attempting to init PCI bdf 06:05.0 (dev/ven 30381106)<br>
Copying option rom (size 130560) from 0xfff00000 to ce000<br>Checking rom 0x000ce000 (sig aa55 size 255)<br>Running option rom at ce00:0003<br>hello, initialize_usb<br>00:13.0 4387:1002.0 OHCI controller<br>Not supported.<br>
00:13.1 4388:1002.1 OHCI controller<br>Not supported.<br>00:13.2 4389:1002.2 OHCI controller<br>Not supported.<br>00:13.3 438a:1002.3 OHCI controller<br>Not supported.<br>00:13.4 438b:1002.4 OHCI controller<br>Not supported.<br>
00:13.5 4386:1002.5 EHCI controller<br>Not supported.<br>00:05.0 3038:1106.0 UHCI controller<br><span style="color: rgb(255, 0, 0);">alloc length=0x238, the ptr=0x0</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);">alloc the memory begin:0x7860 end:0x57860, hstart:0x0</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">setup the memory size:0x4fffc,begin:0x7860 end:0x57860, hstart:0xaa04fffc</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);">set up failed,ptr=0x0</span><br style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">memory allocator panic!!! the size=0x0. header=0x0</span><br><font color="#888888"><br>-- <br>Jason Wang <br>Peking University<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Jason Wang <br>Peking University<br>