private bool Wait(WakeUp wakeUp) { try { CompilerIntrinsics.Cli(); if (waitSemaphore == null) { waitSemaphore = Kernel.kernel.NewSemaphore(0); } uint depth = lockDepth; uint cur = Kernel.CurrentThread; lockHolder = 0xffffffff; lockDepth = 0; lockSemaphore.SignalInterruptsDisabled(); bool gotIt = waitSemaphore.WaitInterruptsDisabled(wakeUp); lockSemaphore.WaitInterruptsDisabled(); lockDepth = depth; lockHolder = cur; return(gotIt); } finally { CompilerIntrinsics.Sti(); } }
public uint Read32(int offset) { try { CompilerIntrinsics.Cli(); return(NucleusCalls.PciMemRead32(id, (uint)offset)); } finally { CompilerIntrinsics.Sti(); } }
public void Write32(int offset, uint val) { try { CompilerIntrinsics.Cli(); NucleusCalls.PciMemWrite32(id, (uint)offset, val); } finally { CompilerIntrinsics.Sti(); } }
/*TODO * public byte Read8(int offset) { * return (byte)(Read32(offset)); * } * * public ushort Read16(int offset) { * return (ushort)(Read32(offset)); * } */ public uint Read32(int offset) { System.VTable.Assert((offset & 3) == 0); try { CompilerIntrinsics.Cli(); return(NucleusCalls.PciConfigRead32(id, (uint)offset)); } finally { CompilerIntrinsics.Sti(); } }
internal static void Print(char c) { CompilerIntrinsics.Cli(); NucleusCalls.VgaTextWrite(offset, (uint)(0x1e00 | c)); offset++; if (offset == 40 * 80) { offset = 80; } NucleusCalls.VgaTextWrite(offset, (uint)(0x3b00 | 33)); CompilerIntrinsics.Sti(); }
internal static void DebugPrintHex(uint screenOffset, uint hexMessage) { try { CompilerIntrinsics.Cli(); NucleusCalls.DebugPrintHex(screenOffset, hexMessage); } finally { CompilerIntrinsics.Sti(); } }
internal static long Rdtsc() { try { CompilerIntrinsics.Cli(); return(NucleusCalls.Rdtsc()); } finally { CompilerIntrinsics.Sti(); } }
internal static uint TryReadKeyboard() { try { CompilerIntrinsics.Cli(); return(NucleusCalls.TryReadKeyboard()); } finally { CompilerIntrinsics.Sti(); } }
internal static void VgaTextWrite(uint position, uint data) { try { CompilerIntrinsics.Cli(); NucleusCalls.VgaTextWrite(position, data); } finally { CompilerIntrinsics.Sti(); } }
internal PciMemory(uint id) { this.id = id; try { CompilerIntrinsics.Cli(); size = (int)NucleusCalls.PciMemSetup(id); } finally { CompilerIntrinsics.Sti(); } System.DebugStub.Print("PCI size = 0x" + size.ToString("X") + ". "); }
public void Reset() { try { CompilerIntrinsics.Cli(); isSet = false; } finally { CompilerIntrinsics.Sti(); } }
public Thread NewThread(ThreadStart start) { Thread t = new Thread(start); try { CompilerIntrinsics.Cli(); return(_NewThread(t)); } finally { CompilerIntrinsics.Sti(); } }
private static Object AllocateObjectInterruptsEnabled(VTable vtable) { CompilerIntrinsics.Cli(); for (;;) { Object o = AllocateObject(vtable); if (o != null) { CompilerIntrinsics.Sti(); return(o); } Kernel.Collect(); CompilerIntrinsics.Cli(); // TODO: superfluous } }
private static Array AllocateVectorInterruptsEnabled(VTable vtable, int len) { CompilerIntrinsics.Cli(); for (;;) { Array o = AllocateVector(vtable, len); if (o != null) { CompilerIntrinsics.Sti(); return(o); } Kernel.Collect(); CompilerIntrinsics.Cli(); // TODO: superfluous } }
public void Wait() { try { CompilerIntrinsics.Cli(); capacity--; if (capacity < 0) { Kernel.kernel.EnqueueAndYield(waiters); } } 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(); } } }
public bool TryWait() { try { CompilerIntrinsics.Cli(); if (capacity <= 0) { return(false); } capacity--; return(true); } finally { CompilerIntrinsics.Sti(); } }
internal static void Setup() { System.DebugStub.Print("Dma.Setup 1. "); try { CompilerIntrinsics.Cli(); ioMemory = NucleusCalls.PciDmaBuffer(); ioPhysical = NucleusCalls.PciDmaPhysicalAddr(); // The IO-MMU tables map 2MB, aligned by 2MB uint superPageSize = 0x200000; uint ioSuperPage = (ioPhysical + 2 * superPageSize) - (ioPhysical & (superPageSize - 1)); allocOffset = (int)(ioSuperPage - ioPhysical); } finally { CompilerIntrinsics.Sti(); } System.DebugStub.Print("Dma.Setup 2. ioPhysical = 0x" + ioPhysical.ToString("X") + " allocOffset = 0x" + allocOffset.ToString("X") + ". "); }
public void Set() { try { CompilerIntrinsics.Cli(); isSet = true; while (waitSemaphore.capacity != 0) { // signal a waiter waitSemaphore.SignalInterruptsDisabled(); } } finally { CompilerIntrinsics.Sti(); } }
public void Release() { try { CompilerIntrinsics.Cli(); if (lockDepth > 0) { lockDepth--; return; } lockHolder = 0xffffffff; lockSemaphore.SignalInterruptsDisabled(); } finally { CompilerIntrinsics.Sti(); } }
public void PulseAll() { try { CompilerIntrinsics.Cli(); if (waitSemaphore == null) { return; } while (waitSemaphore.capacity != 0) { waitSemaphore.SignalInterruptsDisabled(); } } finally { CompilerIntrinsics.Sti(); } }
internal DmaMemory(int length) { System.VTable.Assert(length >= 0); try { CompilerIntrinsics.Cli(); this.offset = allocOffset; this.length = length; if (allocOffset + length <= ioMemory.Length) { allocOffset += length; } } finally { CompilerIntrinsics.Sti(); } if (offset + length > ioMemory.Length) { throw new System.Exception("DmaMemory"); } }
public void Signal() { try { CompilerIntrinsics.Cli(); capacity++; Thread t = waiters.Dequeue(); if (t != null) { ThreadQueue ready = Kernel.kernel.readyQueue; ready.Enqueue(t); Kernel.kernel.EnqueueAndYield(ready); } } finally { CompilerIntrinsics.Sti(); } }
public void Yield() { try { CompilerIntrinsics.Cli(); if (collectionRequested) { EnqueueAndYield(collectionQueue); } else { EnqueueAndYield(readyQueue); } } finally { CompilerIntrinsics.Sti(); } }
private bool WaitOne(WakeUp wakeUp) { try { CompilerIntrinsics.Cli(); if (isSet) { return(true); } else { return(waitSemaphore.WaitInterruptsDisabled(wakeUp)); } } finally { CompilerIntrinsics.Sti(); } }
internal bool Acquire(WakeUp wakeUp) { try { CompilerIntrinsics.Cli(); uint cur = Kernel.CurrentThread; if (lockHolder == cur) { lockDepth++; return(true); } bool gotIt = lockSemaphore.WaitInterruptsDisabled(wakeUp); lockHolder = cur; return(gotIt); // TODO: return value doesn't match documentation, but should it? } finally { CompilerIntrinsics.Sti(); } }
public override void Run() { System.DebugStub.Print(" PLASMA Verve. "); System.DebugStub.Print("IoThread@" + Kernel.CurrentThread + ". "); byte[] pciDmaBuffer; try { CompilerIntrinsics.Cli(); pciDmaBuffer = NucleusCalls.PciDmaBuffer(); } finally { CompilerIntrinsics.Sti(); } if (pciDmaBuffer == null) { System.DebugStub.Print("No IO-MMU. "); Kernel.kernel.NewSemaphore(0).Wait(); return; } // Establish DMA buffer area Microsoft.Singularity.Io.DmaMemory.Setup(); // Enumerate and initialize PCI devices for (uint id = 0; id < 65536; id += 8) { uint v; try { CompilerIntrinsics.Cli(); v = NucleusCalls.PciConfigRead32(id, 0); } finally { CompilerIntrinsics.Sti(); } if (v == 0x107c8086) { // Intel NIC System.DebugStub.Print("Found Intel NIC. "); } } System.DebugStub.Print("IoThread done. "); Kernel.kernel.NewSemaphore(0).Wait(); }
public void Set() { try { CompilerIntrinsics.Cli(); if (waitSemaphore.capacity == 0) { // no waiters isSet = true; } else { // signal a waiter isSet = false; waitSemaphore.SignalInterruptsDisabled(); } } finally { CompilerIntrinsics.Sti(); } }
public bool TryAcquire() { try { CompilerIntrinsics.Cli(); uint cur = Kernel.CurrentThread; if (lockHolder == cur) { lockDepth++; return(true); } bool gotIt = lockSemaphore.TryWaitInterruptsDisabled(); if (gotIt) { lockHolder = cur; } return(gotIt); } finally { CompilerIntrinsics.Sti(); } }