Ejemplo n.º 1
0
            public HeapInfo(SysMemInfo sysMemInfo)
            {
                this.sysMemInfo = sysMemInfo;
                MemoryChunk memoryChunk = new MemoryChunk(sysMemInfo.addr, sysMemInfo.size);

                freeMemoryChunks      = new MemoryChunkList(memoryChunk);
                allocatedMemoryChunks = new Dictionary <int, MemoryChunk>();
                allocType             = sysMemInfo.type;
            }
Ejemplo n.º 2
0
        // Allocates to 256-byte alignment
        public virtual SysMemInfo malloc(int partitionid, string name, int type, int size, int addr)
        {
            if (freeMemoryChunks == null)
            {
                return(null);
            }

            int allocatedAddress = 0;
            int allocatedSize    = 0;

            if (isValidPartitionId(partitionid))
            {
                MemoryChunkList freeMemoryChunk = freeMemoryChunks[partitionid];
                int             alignment       = defaultSizeAlignment - 1;

                // The allocated size has not to be aligned to the requested alignment
                // (for PSP_SMEM_LowAligned or PSP_SMEM_HighAligned),
                // it is only aligned to the default size alignment.
                allocatedSize = Utilities.alignUp(size, alignment);

                if (type == PSP_SMEM_LowAligned || type == PSP_SMEM_HighAligned)
                {
                    // Use the alignment provided in the addr parameter
                    alignment = addr - 1;
                }

                switch (type)
                {
                case PSP_SMEM_Low:
                case PSP_SMEM_LowAligned:
                    allocatedAddress = freeMemoryChunk.allocLow(allocatedSize, alignment);
                    break;

                case PSP_SMEM_High:
                case PSP_SMEM_HighAligned:
                    allocatedAddress = freeMemoryChunk.allocHigh(allocatedSize, alignment);
                    break;

                case PSP_SMEM_Addr:
                    allocatedAddress = freeMemoryChunk.alloc(addr & Memory.addressMask, allocatedSize);
                    break;

                default:
                    Console.WriteLine(string.Format("malloc: unknown type {0}", getTypeName(type)));
                    break;
                }
            }

            SysMemInfo sysMemInfo;

            if (allocatedAddress == 0)
            {
                Console.WriteLine(string.Format("malloc cannot allocate partition={0:D}, name='{1}', type={2}, size=0x{3:X}, addr=0x{4:X8}, maxFreeMem=0x{5:X}, totalFreeMem=0x{6:X}", partitionid, name, getTypeName(type), size, addr, maxFreeMemSize(partitionid), totalFreeMemSize(partitionid)));
                if (log.TraceEnabled)
                {
                    log.trace("Free list: " + DebugFreeMem);
                    log.trace("Allocated blocks:\n" + DebugAllocatedMem + "\n");
                }
                sysMemInfo = null;
            }
            else
            {
                sysMemInfo = new SysMemInfo(partitionid, name, type, size, allocatedSize, allocatedAddress);

                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("malloc partition={0:D}, name='{1}', type={2}, size=0x{3:X}, addr=0x{4:X8}: returns 0x{5:X8}", partitionid, name, getTypeName(type), size, addr, allocatedAddress));
                    if (log.TraceEnabled)
                    {
                        log.trace("Free list after malloc: " + DebugFreeMem);
                        log.trace("Allocated blocks after malloc:\n" + DebugAllocatedMem + "\n");
                    }
                }
            }

            return(sysMemInfo);
        }