예제 #1
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();
        }
예제 #2
0
        public static string getWaitName(int waitType, int waitId, ThreadWaitInfo wait, int status)
        {
            StringBuilder s = new StringBuilder();

            switch (waitType)
            {
            case PSP_WAIT_NONE:
                s.Append(string.Format("None"));
                break;

            case PSP_WAIT_SLEEP:
                s.Append(string.Format("Sleep"));
                break;

            case PSP_WAIT_DELAY:
                s.Append(string.Format("Delay"));
                break;

            case PSP_WAIT_THREAD_END:
                s.Append(string.Format("ThreadEnd (0x{0:X4})", wait.ThreadEnd_id));
                break;

            case PSP_WAIT_EVENTFLAG:
                s.Append(string.Format("EventFlag (0x{0:X4})", wait.EventFlag_id));
                break;

            case PSP_WAIT_SEMA:
                s.Append(string.Format("Semaphore (0x{0:X4})", wait.Semaphore_id));
                break;

            case PSP_WAIT_MUTEX:
                s.Append(string.Format("Mutex (0x{0:X4})", wait.Mutex_id));
                break;

            case PSP_WAIT_LWMUTEX:
                s.Append(string.Format("LwMutex (0x{0:X4})", wait.LwMutex_id));
                break;

            case PSP_WAIT_MBX:
                s.Append(string.Format("Mbx (0x{0:X4})", wait.Mbx_id));
                break;

            case PSP_WAIT_VPL:
                s.Append(string.Format("Vpl (0x{0:X4})", wait.Vpl_id));
                break;

            case PSP_WAIT_FPL:
                s.Append(string.Format("Fpl (0x{0:X4})", wait.Fpl_id));
                break;

            case PSP_WAIT_MSGPIPE:
                s.Append(string.Format("MsgPipe (0x{0:X4})", wait.MsgPipe_id));
                break;

            case PSP_WAIT_EVENTHANDLER:
                s.Append(string.Format("EventHandler"));
                break;

            case PSP_WAIT_CALLBACK_DELETE:
                s.Append(string.Format("CallBackDelete"));
                break;

            case JPCSP_WAIT_IO:
                s.Append(string.Format("Io (0x{0:X4})", wait.Io_id));
                break;

            case JPCSP_WAIT_UMD:
                s.Append(string.Format("Umd (0x{0:X2})", wait.wantedUmdStat));
                break;

            case JPCSP_WAIT_GE_LIST:
                s.Append(string.Format("Ge List ({0})", Modules.sceGe_userModule.getGeList(waitId)));
                break;

            case JPCSP_WAIT_NET:
                s.Append(string.Format("Network"));
                break;

            case JPCSP_WAIT_AUDIO:
                s.Append(string.Format("Audio"));
                break;

            case JPCSP_WAIT_DISPLAY_VBLANK:
                s.Append(string.Format("Display Vblank (vcount={0:D}, current={1:D})", waitId, Modules.sceDisplayModule.Vcount));
                break;

            case JPCSP_WAIT_CTRL:
                s.Append(string.Format("Ctrl"));
                break;

            case JPCSP_WAIT_USB:
                s.Append(string.Format("Usb"));
                break;

            case JPCSP_WAIT_VIDEO_DECODER:
                s.Append(string.Format("VideoDecoder"));
                break;

            default:
                s.Append(string.Format("Unknown waitType={0:D}", waitType));
                break;
            }

            if ((status & PSP_THREAD_WAITING) != 0)
            {
                if (wait.forever)
                {
                    s.Append(" (forever)");
                }
                else
                {
                    int restDelay = (int)(wait.microTimeTimeout - Emulator.Clock.microTime());
                    if (restDelay < 0)
                    {
                        restDelay = 0;
                    }
                    s.Append(string.Format(" (delay {0:D} us, rest {1:D} us)", wait.micros, restDelay));
                }
            }

            return(s.ToString());
        }