| 40 | } |
| 41 | |
| 42 | void xMemInitHeap(xMemHeap_tag* heap, U32 base, U32 size, U32 flags) |
| 43 | { |
| 44 | U32 old_base = base; |
| 45 | S32 align = 1 << ((flags >> 9) & 0x1F); |
| 46 | if (flags & 0x100) |
| 47 | { |
| 48 | base = base & -align; |
| 49 | size -= (old_base - base); |
| 50 | } |
| 51 | else |
| 52 | { |
| 53 | base = (old_base + align - 1) & -align; |
| 54 | size -= (base - old_base); |
| 55 | } |
| 56 | |
| 57 | heap->state_idx = 0; |
| 58 | heap->hard_base = base; |
| 59 | heap->size = size; |
| 60 | heap->flags = flags; |
| 61 | heap->lastblk = NULL; |
| 62 | xHeapState_tag* sp = &heap->state[heap->state_idx]; |
| 63 | sp->curr = base; |
| 64 | sp->blk_ct = 0; |
| 65 | |
| 66 | if (flags & 0x10000) |
| 67 | { |
| 68 | heap->max_blks = (1 << ((flags >> 14) & 0x1)); |
| 69 | heap->blk = (xMemBlock_tag*)malloc(heap->max_blks * sizeof(xMemBlock_tag)); |
| 70 | memset(heap->blk, 0, heap->max_blks * sizeof(xMemBlock_tag)); |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | heap->max_blks = -1; |
| 75 | heap->blk = 0; |
| 76 | } |
| 77 | heap->opp_heap[0] = -1; |
| 78 | heap->opp_heap[1] = -1; |
| 79 | } |
| 80 | |
| 81 | #if 0 |
| 82 | // Not particularly close. This function is a nightmare, it has so many |