Example #1
0
        public int MakeThread(
            long EntryPoint,
            long StackTop,
            long ArgsPtr,
            int Priority,
            int ProcessorId)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException(nameof(Process));
            }

            AThread Thread = new AThread(GetTranslator(), Memory, EntryPoint);

            KThread KernelThread = new KThread(Thread, ProcessorId, Priority);

            int Handle = HandleTable.OpenHandle(KernelThread);

            KernelThread.Handle = Handle;

            int ThreadId = GetFreeTlsSlot(Thread);

            long Tpidr = MemoryRegions.TlsPagesAddress + ThreadId * TlsSize;

            Thread.ThreadState.ProcessId = ProcessId;
            Thread.ThreadState.ThreadId  = ThreadId;
            Thread.ThreadState.CntfrqEl0 = TickFreq;
            Thread.ThreadState.Tpidr     = Tpidr;

            Thread.ThreadState.X0  = (ulong)ArgsPtr;
            Thread.ThreadState.X1  = (ulong)Handle;
            Thread.ThreadState.X31 = (ulong)StackTop;

            Thread.ThreadState.Break     += BreakHandler;
            Thread.ThreadState.SvcCall   += SvcHandler.SvcCall;
            Thread.ThreadState.Undefined += UndefinedHandler;

            Thread.WorkFinished += ThreadFinished;

            ThreadsByTpidr.TryAdd(Thread.ThreadState.Tpidr, KernelThread);

            return(Handle);
        }
Example #2
0
        public int MakeThread(
            long EntryPoint,
            long StackTop,
            long ArgsPtr,
            int Priority,
            int ProcessorId)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException(nameof(Process));
            }

            AThread CpuThread = new AThread(GetTranslator(), Memory, EntryPoint);

            KThread Thread = new KThread(CpuThread, this, ProcessorId, Priority);

            Thread.LastPc = EntryPoint;

            int Handle = HandleTable.OpenHandle(Thread);

            long Tpidr = GetFreeTls();

            int ThreadId = (int)((Tpidr - MemoryManager.TlsIoRegionStart) / 0x200) + 1;

            CpuThread.ThreadState.ProcessId = ProcessId;
            CpuThread.ThreadState.ThreadId  = ThreadId;
            CpuThread.ThreadState.CntfrqEl0 = TickFreq;
            CpuThread.ThreadState.Tpidr     = Tpidr;

            CpuThread.ThreadState.X0  = (ulong)ArgsPtr;
            CpuThread.ThreadState.X1  = (ulong)Handle;
            CpuThread.ThreadState.X31 = (ulong)StackTop;

            CpuThread.ThreadState.Break     += BreakHandler;
            CpuThread.ThreadState.SvcCall   += SvcHandler.SvcCall;
            CpuThread.ThreadState.Undefined += UndefinedHandler;

            CpuThread.WorkFinished += ThreadFinished;

            Threads.TryAdd(CpuThread.ThreadState.Tpidr, Thread);

            return(Handle);
        }