Esempio n. 1
0
        public SceModule(bool isFlashModule)
        {
            this.isFlashModule = isFlashModule;

            modid = SceUidManager.getNewUid("SceModule");

            sceModuleAddressOffset -= (size + 256) & ~255;
            address = sceModuleAddressOffset;

            // Link SceModule structs together
            if (previousModule != null)
            {
                previousModule.next = address;
            }
            previousModule = this;

            // Internal context
            fileFormat = Loader.FORMAT_UNKNOWN;
            //textsection = new int[2];
            initsection         = new int[2];
            finisection         = new int[2];
            stubtextsection     = new int[2];
            unresolvedImports   = new LinkedList <DeferredStub>();
            importFixupAttempts = 0;
            resolvedImports     = new LinkedList <DeferredStub>();
            allocatedMemory     = new LinkedList <SysMemInfo>();
        }
Esempio n. 2
0
        public virtual int sceNetApctlAddHandler(TPointer handler, int handlerArg)
        {
            int          uid          = SceUidManager.getNewUid(uidPurpose);
            ApctlHandler apctlHandler = new ApctlHandler(this, uid, handler.Address, handlerArg);

            apctlHandlers[uid] = apctlHandler;

            return(uid);
        }
Esempio n. 3
0
        public virtual int sceNetResolverCreate(TPointer32 pRid, TPointer buffer, int bufferLength)
        {
            int        newID  = SceUidManager.getNewUid(uidPurpose);
            ResolverID newRID = new ResolverID(newID, true);

            RIDs[newID] = newRID;
            pRid.setValue(newRID.ID);

            return(0);
        }
Esempio n. 4
0
            public SysMemInfo(int partitionid, string name, int type, int size, int allocatedSize, int addr)
            {
                this.partitionid   = partitionid;
                this.name          = name;
                this.type          = type;
                this.size          = size;
                this.allocatedSize = allocatedSize;
                this.addr          = addr;

                uid            = SceUidManager.getNewUid("SysMem");
                blockList[uid] = this;
            }
Esempio n. 5
0
        private SceKernelVplInfo(string name, int partitionid, int attr, int size, int memType)
        {
            this.name = name;
            this.attr = attr;

            // Strange, the PSP is allocating a size of 0x1000 when requesting a size lower than 0x30...
            if (size <= 0x30)
            {
                size = 0x1000;
            }

            poolSize = size - vplHeaderSize;             // 32 bytes overhead per VPL

            freeSize = poolSize;

            dataBlockMap = new Dictionary <int, int>();

            uid = SceUidManager.getNewUid("ThreadMan-Vpl");
            threadWaitingList = ThreadWaitingList.createThreadWaitingList(SceKernelThreadInfo.PSP_WAIT_VPL, uid, attr, VplManager.PSP_VPL_ATTR_PRIORITY);
            this.partitionid  = partitionid;

            // Reserve psp memory
            int totalVplSize = Utilities.alignUp(size, vplAddrAlignment);             // 8-byte align

            sysMemInfo = Modules.SysMemUserForUserModule.malloc(partitionid, string.Format("ThreadMan-Vpl-0x{0:x}-{1}", uid, name), memType, totalVplSize, 0);
            if (sysMemInfo == null)
            {
                throw new Exception("SceKernelVplInfo: not enough free mem");
            }
            int addr = sysMemInfo.addr;

            // 24 byte header, probably not necessary to mimick this
            Memory mem = Memory.Instance;

            mem.write32(addr, addr - 1);
            mem.write32(addr + 4, size - 8);
            mem.write32(addr + 8, 0);             // based on number of allocations
            mem.write32(addr + 12, addr + size - 16);
            mem.write32(addr + 16, 0);            // based on allocations/fragmentation
            mem.write32(addr + 20, 0);            // based on created size? magic?

            allocAddress = addr;

            MemoryChunk initialMemoryChunk = new MemoryChunk(addr + vplHeaderSize, totalVplSize - vplHeaderSize);

            freeMemoryChunks = new MemoryChunkList(initialMemoryChunk);
        }
Esempio n. 6
0
        public SceKernelThreadInfo(string name, int entry_addr, int initPriority, int stackSize, int attr, int mpidStack)
        {
            if (stackSize < 512)
            {
                // 512 byte min. (required for interrupts)
                stackSize = 512;
            }
            else
            {
                // 256 byte size alignment.
                stackSize = (stackSize + 0xFF) & ~0xFF;
            }

            if (mpidStack == 0)
            {
                mpidStack = SysMemUserForUser.USER_PARTITION_ID;
            }

            this.name         = name;
            this.entry_addr   = entry_addr;
            this.initPriority = initPriority;
            this.stackSize    = stackSize;
            this.attr         = attr;
            uid = SceUidManager.getNewUid("ThreadMan-thread");
            // Setup the stack.
            int stackMemoryType = (attr & PSP_THREAD_ATTR_LOW_MEM_STACK) != 0 ? SysMemUserForUser.PSP_SMEM_Low : SysMemUserForUser.PSP_SMEM_High;

            stackSysMemInfo = Modules.SysMemUserForUserModule.malloc(mpidStack, string.Format("ThreadMan-Stack-0x{0:x}-{1}", uid, name), stackMemoryType, stackSize, 0);
            if (stackSysMemInfo == null)
            {
                stackAddr = 0;
            }
            else
            {
                stackAddr = stackSysMemInfo.addr;
            }

            // Inherit gpReg.
            gpReg_addr = Emulator.Processor.cpu._gp;
            // Inherit context.
            cpuContext = new CpuState(Emulator.Processor.cpu);
            wait       = new ThreadWaitInfo();
            reset();
        }
Esempio n. 7
0
        /// <summary>
        /// do not instantiate unless there is enough free mem.
        /// use the static helper function tryCreateFpl.
        /// </summary>
        private SceKernelFplInfo(string name, int partitionid, int attr, int blockSize, int numBlocks, int memType, int memAlign)
        {
            this.name      = name;
            this.attr      = attr;
            this.blockSize = blockSize;
            this.numBlocks = numBlocks;

            freeBlocks = numBlocks;

            uid = SceUidManager.getNewUid("ThreadMan-Fpl");
            this.partitionid = partitionid;
            blockAddress     = new int[numBlocks];
            blockAllocated   = new bool[numBlocks];
            for (int i = 0; i < numBlocks; i++)
            {
                blockAllocated[i] = false;
            }

            // Reserve psp memory
            int alignedBlockSize = memAlign == 0 ? blockSize : Utilities.alignUp(blockSize, memAlign - 1);
            int totalFplSize     = alignedBlockSize * numBlocks;

            sysMemInfo = Modules.SysMemUserForUserModule.malloc(partitionid, string.Format("ThreadMan-Fpl-0x{0:x}-{1}", uid, name), memType, totalFplSize, 0);
            if (sysMemInfo == null)
            {
                throw new Exception("SceKernelFplInfo: not enough free mem");
            }

            // Initialise the block addresses
            for (int i = 0; i < numBlocks; i++)
            {
                blockAddress[i] = sysMemInfo.addr + alignedBlockSize * i;
            }

            threadWaitingList = ThreadWaitingList.createThreadWaitingList(SceKernelThreadInfo.PSP_WAIT_FPL, uid, attr, FplManager.PSP_FPL_ATTR_PRIORITY);
        }