Ejemplo n.º 1
0
 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();
     }
 }
Ejemplo n.º 2
0
 public uint Read32(int offset)
 {
     try {
         CompilerIntrinsics.Cli();
         return(NucleusCalls.PciMemRead32(id, (uint)offset));
     }
     finally {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 3
0
 public void Write32(int offset, uint val)
 {
     try {
         CompilerIntrinsics.Cli();
         NucleusCalls.PciMemWrite32(id, (uint)offset, val);
     }
     finally {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 4
0
/*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();
            }
        }
Ejemplo n.º 5
0
 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();
 }
Ejemplo n.º 6
0
 internal static void DebugPrintHex(uint screenOffset, uint hexMessage)
 {
     try
     {
         CompilerIntrinsics.Cli();
         NucleusCalls.DebugPrintHex(screenOffset, hexMessage);
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 7
0
 internal static long Rdtsc()
 {
     try
     {
         CompilerIntrinsics.Cli();
         return(NucleusCalls.Rdtsc());
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 8
0
 internal static uint TryReadKeyboard()
 {
     try
     {
         CompilerIntrinsics.Cli();
         return(NucleusCalls.TryReadKeyboard());
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 9
0
 internal static void VgaTextWrite(uint position, uint data)
 {
     try
     {
         CompilerIntrinsics.Cli();
         NucleusCalls.VgaTextWrite(position, data);
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 10
0
 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") + ". ");
 }
Ejemplo n.º 11
0
 public void Reset()
 {
     try
     {
         CompilerIntrinsics.Cli();
         isSet = false;
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 12
0
    public Thread NewThread(ThreadStart start)
    {
        Thread t = new Thread(start);

        try
        {
            CompilerIntrinsics.Cli();
            return(_NewThread(t));
        }
        finally
        {
            CompilerIntrinsics.Sti();
        }
    }
Ejemplo n.º 13
0
 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
     }
 }
Ejemplo n.º 14
0
 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
     }
 }
Ejemplo n.º 15
0
 public void Wait()
 {
     try
     {
         CompilerIntrinsics.Cli();
         capacity--;
         if (capacity < 0)
         {
             Kernel.kernel.EnqueueAndYield(waiters);
         }
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 16
0
    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)
        {
        }
    }
Ejemplo n.º 17
0
    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();
            }
        }
    }
Ejemplo n.º 18
0
 public bool TryWait()
 {
     try
     {
         CompilerIntrinsics.Cli();
         if (capacity <= 0)
         {
             return(false);
         }
         capacity--;
         return(true);
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 19
0
 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") + ". ");
 }
Ejemplo n.º 20
0
 public void Set()
 {
     try
     {
         CompilerIntrinsics.Cli();
         isSet = true;
         while (waitSemaphore.capacity != 0)
         {
             // signal a waiter
             waitSemaphore.SignalInterruptsDisabled();
         }
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 21
0
 public void Release()
 {
     try
     {
         CompilerIntrinsics.Cli();
         if (lockDepth > 0)
         {
             lockDepth--;
             return;
         }
         lockHolder = 0xffffffff;
         lockSemaphore.SignalInterruptsDisabled();
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 22
0
 public void PulseAll()
 {
     try
     {
         CompilerIntrinsics.Cli();
         if (waitSemaphore == null)
         {
             return;
         }
         while (waitSemaphore.capacity != 0)
         {
             waitSemaphore.SignalInterruptsDisabled();
         }
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 23
0
 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");
     }
 }
Ejemplo n.º 24
0
 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();
     }
 }
Ejemplo n.º 25
0
 public void Yield()
 {
     try
     {
         CompilerIntrinsics.Cli();
         if (collectionRequested)
         {
             EnqueueAndYield(collectionQueue);
         }
         else
         {
             EnqueueAndYield(readyQueue);
         }
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 26
0
 private bool WaitOne(WakeUp wakeUp)
 {
     try
     {
         CompilerIntrinsics.Cli();
         if (isSet)
         {
             return(true);
         }
         else
         {
             return(waitSemaphore.WaitInterruptsDisabled(wakeUp));
         }
     }
     finally
     {
         CompilerIntrinsics.Sti();
     }
 }
Ejemplo n.º 27
0
 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();
     }
 }
Ejemplo n.º 28
0
        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();
        }
Ejemplo n.º 29
0
 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();
     }
 }
Ejemplo n.º 30
0
 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();
     }
 }