internal static void DebugPrintHex(uint screenOffset, uint hexMessage) { try { CompilerIntrinsics.Cli(); NucleusCalls.DebugPrintHex(screenOffset, hexMessage); } finally { CompilerIntrinsics.Sti(); } }
private void ThreadMain(uint id) { Thread t = threadTable[id]; CompilerIntrinsics.Sti(); t.start.Run(); CompilerIntrinsics.Cli(); t.alive = false; NucleusCalls.YieldTo(0); // Should never be reached: NucleusCalls.DebugPrintHex(0, 0xdead0002); while (true) { } }
public override void Run() { int nIter = 1048576; if (me == 0) { myId = Kernel.CurrentThread; Thread otherT = kernel.NewThread(other); uint otherId = otherT.id; kernel.Yield(); try { CompilerIntrinsics.Cli(); NucleusCalls.DebugPrintHex(50, 0); long t1 = NucleusCalls.Rdtsc(); for (int i = 0; i < nIter; i++) { NucleusCalls.YieldTo(otherId); } long t2 = NucleusCalls.Rdtsc(); uint diff = (uint)((t2 - t1) >> 20); NucleusCalls.DebugPrintHex(50, diff); } finally { CompilerIntrinsics.Sti(); } doneSemaphore.Signal(); } else { uint otherId = other.myId; kernel.Yield(); try { CompilerIntrinsics.Cli(); for (int i = 0; i < nIter; i++) { NucleusCalls.YieldTo(otherId); } } finally { CompilerIntrinsics.Sti(); } } }
private static void Main() { uint id = CurrentThread; if (id == 0) { kernel = new Kernel(); kernel.KernelMain(); } else { kernel.ThreadMain(id); } CompilerIntrinsics.Cli(); // TODO: superfluous NucleusCalls.DebugPrintHex(0, 0xdead0001); while (true) { } }
internal void ScheduleNextThread() { Thread t = readyQueue.Dequeue(); if (t == null) { if (collectionRequested) { CompilerIntrinsics.Cli(); // TODO: superfluous NucleusCalls.DebugPrintHex(70, ++gcCount); NucleusCalls.DebugPrintHex(60, 0); long t1 = NucleusCalls.Rdtsc(); // No ready threads. // Make anyone waiting for GC ready: while (true) { t = collectionQueue.Dequeue(); if (t == null) { break; } readyQueue.Enqueue(t); } t = readyQueue.Dequeue(); // Garbage collect, then we're ready to go. CompilerIntrinsics.Sti(); System.DebugStub.Print("GarbageCollecting. "); CompilerIntrinsics.Cli(); NucleusCalls.GarbageCollect(); collectionRequested = false; long t2 = NucleusCalls.Rdtsc(); uint diff = (uint)((t2 - t1) >> 10); NucleusCalls.DebugPrintHex(60, diff); } while (t == null) { // TODO: let the CPU sleep here // TODO: enable interrupts CompilerIntrinsics.Cli(); // TODO: superfluous if (!CheckWakeUp()) { // No threads to run. The system is finished. CompilerIntrinsics.Cli(); // TODO: superfluous NucleusCalls.DebugPrintHex(0, 0x76543210); while (true) { } } t = readyQueue.Dequeue(); CompilerIntrinsics.Cli(); // TODO: superfluous } } // Go to t. RunThread(t); // We're back. Somebody (not necessarily t) yielded to us. }