예제 #1
0
        private void IrqWorkerMain()
        {
            DebugPrint(
                "Intel {0} Ethernet Driver irq worker thread started.\n",
                DebugStub.ArgList(this.cardName)
                );
            uint rcnt   = 0;
            uint missed = 0;
            uint nobuf  = 0;

            while (irqWorkerStop == false)
            {
                Thread.Yield(); //TODO: irq.WaitForInterrupt();
                uint icr = Read32(Register.ICR);
                HandleInterrupts(icr);

                rcnt   += Read32(Register.TOTAL_RECV_PACKETS);
                missed += Read32(0x4010);
                nobuf  += Read32(0x40a0);
                INucleusCalls.DebugPrintHex(10, rcnt - nobuf);
                INucleusCalls.DebugPrintHex(20, rcnt);
                INucleusCalls.DebugPrintHex(30, missed);

                //TODO: irq.AckInterrupt();
            }

            DisableInterrupts();
            DebugPrint(
                "Intel {0} Ethernet Driver irq worker thread stopped.\n",
                DebugStub.ArgList(this.cardName)
                );
        }
예제 #2
0
    public override void Run()
    {
        System.DebugStub.Print("Shell@" + Kernel.CurrentThread + ". ");
        while (true)
        {
            keyboardWaiter.Wait();
            char ch = (keyboardDriver.LastChar); // TODO: channels!

/*
 *          if (ch == 'a') {
 *              impact.othello.othello.Main(new System.String[1]{"-d"});
 *          } else if (ch == 'b') {
 *              impact.li_130.xlisp.Main(new System.String[0]);
 *          } else if (ch == 'c') {
 *              Crafty.Net.OO.Crafty.Main(new System.String[0]);
 *          } else if (ch == 'd') {
 *              SharpSAT.SATSolver.Main(new System.String[0]);
 *          }
 */

            INucleusCalls.VgaTextWrite(offset, backgroundColor + ch);
            offset++;
            if (offset == offsetHi)
            {
                offset = offsetLo;
            }
        }
    }
        private Packet MakePacketFromDescriptor(DmaMemory mem, ulong controlBits)
        {
            PacketFifo inDevPkts = rxPacketsInDevice.Acquire();
            Packet     packet    = inDevPkts.Pop();
            int        length    = (int)((controlBits & RxDescriptor.LENGTH_MASK)
                                         >> RxDescriptor.LENGTH_SHIFT);
            uint stat_err = (uint)((controlBits & RxDescriptor.ERR_STAT_MASK)
                                   >> RxDescriptor.ERR_STAT_SHIFT);

            // can't deal with fragments yet
            if ((stat_err & RxErrStatFields.END_OF_PACKET) == 0)
            {
                INucleusCalls.DebugPrintHex(40, 0xd0);
                DebugStub.Print("FRAGMENT\n");
                throw new Exception();
            }

            //DebugStub.Assert((stat_err & RxErrStatFields.END_OF_PACKET) != 0);
            //DebugStub.Assert(packet.GetFragmentVirtualAddress(0) == fragmentVirtAddr);
            packet.FromDeviceFlags = GetRecvPktFlags(stat_err);
            packet.SetFragment(0, mem.BytesRef(0, length));
            rxPacketsInDevice.Release(inDevPkts);

            return(packet);
        }
예제 #4
0
    public override void Run()
    {
        int nIter = 1048576;

        if (me == 0)
        {
            kernel.NewThread(other);
            Semaphore s0 = mySemaphore;
            Semaphore s1 = other.mySemaphore;
            kernel.Yield();
            INucleusCalls.DebugPrintHex(50, 0);
            long t1 = INucleusCalls.Rdtsc();
            for (int i = 0; i < nIter; i++)
            {
                s1.Signal();
                s0.Wait();
            }
            long t2   = INucleusCalls.Rdtsc();
            uint diff = (uint)((t2 - t1) >> 20);
            INucleusCalls.DebugPrintHex(50, diff);
            doneSemaphore.Signal();
        }
        else
        {
            Semaphore s1 = mySemaphore;
            Semaphore s0 = other.mySemaphore;
            kernel.Yield();
            for (int i = 0; i < nIter; i++)
            {
                s1.Wait();
                s0.Signal();
            }
        }
    }
예제 #5
0
 public Shell(KeyboardDriver keyboardDriver, Semaphore keyboardWaiter, uint offsetLo, uint offsetHi, uint backgroundColor)
 {
     this.keyboardDriver  = keyboardDriver;
     this.keyboardWaiter  = keyboardWaiter;
     this.offsetLo        = offsetLo;
     this.offsetHi        = offsetHi;
     this.offset          = offsetLo;
     this.backgroundColor = backgroundColor;
     for (uint i = offsetLo; i < offsetHi; i++)
     {
         INucleusCalls.VgaTextWrite(i, backgroundColor);
     }
 }
예제 #6
0
    public override void Run()
    {
        int nIter = 1048576;

        INucleusCalls.DebugPrintHex(50, 0);
        long t1 = INucleusCalls.Rdtsc();
        {
            new BinaryTree(0);
        }
        long t2   = INucleusCalls.Rdtsc();
        uint diff = (uint)((t2 - t1) >> 20);

        INucleusCalls.DebugPrintHex(50, diff);
        doneSemaphore.Signal();
    }
예제 #7
0
    public override void Run()
    {
        int nIter = 65536;

        INucleusCalls.DebugPrintHex(50, 0);
        long t1 = INucleusCalls.Rdtsc();

        for (int i = 0; i < nIter; i++)
        {
            (new byte[1000])[0]++;
        }
        long t2   = INucleusCalls.Rdtsc();
        uint diff = (uint)((t2 - t1) >> 16);

        INucleusCalls.DebugPrintHex(50, diff);
        doneSemaphore.Signal();
    }
예제 #8
0
    // TODO: calibrate timing
    public static long GetUtcTime()
    {
        long tsc = INucleusCalls.Rdtsc();

        return(unchecked (tsc >> 8));
    }
예제 #9
0
 public DhcpClient(IAdapter adapter)
 {
     this.adapter  = adapter;
     transactionID = (uint)INucleusCalls.Rdtsc();
     //TODO: transactionID = (uint)(new Random()).Next();
 }
예제 #10
0
        private void WorkerMain()
        {
            DebugPrint("Worker starting\n");

            //TODO: Random r = new Random();
            //TODO: transactionID = (uint)r.Next();
            transactionID = (uint)INucleusCalls.Rdtsc();
            DateTime startTime = DateTime.Now;

            // Enter "Init" state of FSM
            ChangeState(new DhcpClientStateInitialize(this));

            while (workerDone == false)
            {
                // Check for timeouts
                DateTime now = DateTime.Now;
                if (now >= renewalTimeout)
                {
                    CancelRenewalTimeout();
                    @state.RenewalTimeoutEvent();
                }
                if (now >= rebindTimeout)
                {
                    CancelRebindTimeout();
                    @state.RebindTimeoutEvent();
                }
                if (now >= stateTimeout)
                {
                    CancelStateTimeout();
                    @state.StateTimeoutEvent();
                }

                // Poll for data
                try {
                    Bytes data = udp.PollReadData(PollInterval);
                    if (data != null)
                    {
                        DhcpFormat dhcp = DhcpFormat.Parse(data);
                        //delete data;
                        // Check transaction id is ours
                        if (dhcp.TransactionID != transactionID)
                        {
                            continue;
                        }

                        // Check client address is ours
                        if (dhcp.GetHardwareAddress() != MacAddress)
                        {
                            continue;
                        }

                        @state.ReceiveEvent(dhcp);
                    }
                }
                catch (InvalidDhcpFormatException idfe) {
                    DebugPrint(idfe.Message);
                }

                // XXX Temporary until process can run in background
                // from shell.  ie we'd like to run and renew lease
                // but shell blocks on running process and cleans up
                // after it for the time being.
                if (activeDhcpOptions != null)
                {
                    DebugPrint("Got options -- done\n");
                    break;
                }

                if (DateTime.Now - startTime > TimeSpan.FromSeconds(5))
                {
                    DebugPrint("Timed out\n");
                    break;
                }
            }
        }
예제 #11
0
    public override void Run()
    {
        //int nIter = 1048576;
        int nIter = 65536;

        INucleusCalls.DebugPrintHex(50, 0);
        long t1 = INucleusCalls.Rdtsc();

        /* int array
         * int[] a = new int[9];
         * for (int i = 0; i < nIter; i++)
         * {
         *  if (i < 9) a[i] = i;
         *  new BinaryTree(0);
         * }
         * for (int i = 0; i < 9; i++) {
         *  System.Console.WriteLine(" i => " + a[i]);
         * }*/

        // cast/instance of/array store

        /*B[] a = new C[10];
         * for (int i = 0; i < 10; i++) {
         *  if (i < 2) a[i] = new C();
         *  else if (i < 4) a[i] = new D();
         *  else a[i] = new E();
         * }
         *
         * // instance of
         * for (int i = 0; i < 10; i++) {
         *  if (a[i] is D) {
         *      INucleusCalls.DebugPrintHex(20, (uint)i);
         *  }
         * }
         *
         * // cast
         * for (int i = 0; i < 10; i++) {
         *  if (i > 4) {
         *      E e = (E)a[i];
         *      INucleusCalls.DebugPrintHex(20, (uint)i);
         *  }
         * }
         *
         * // box/unboxing
         * System.Object[] a = new System.Object[9];
         * for (int i = 0; i < 9; i++) {
         *  a[i] = i;
         * }
         * for (int i = 0; i < 9; i++) {
         *  int j = (int)a[i];
         *  INucleusCalls.DebugPrintHex(20, (uint)j);
         * }
         *
         * // interface lookup
         * C1 c1 = new C1();
         * C2 c2 = new C2(1);
         * I i = null;
         * if (foo == 2) i = c1;
         * else i = c2;
         * foo = i.m(3);
         * INucleusCalls.DebugPrintHex(20, (uint)foo);
         *
         * System.Object o = null;
         * if (foo == 2) o = c1;
         * else o = c2;
         * J oj = (J)o;
         * int result = oj.mj(3);
         * INucleusCalls.DebugPrintHex(20, (uint)result);
         *
         * // int[][]
         * int[][] board = new int[8][];
         *
         * for (int i = 0; i < 8; i++) {
         *  board[i] = new int[8] { 0, 1, 2, 3, 4, 5, 6, 7 };
         * }
         * for (int i=0; i<8; i++) {
         *  for (int j=0; j<8; j++) {
         *      INucleusCalls.DebugPrintHex(20, (uint)i);
         *      INucleusCalls.DebugPrintHex(30, (uint)j);
         *      INucleusCalls.DebugPrintHex(40, (uint)board[i][j]);
         *  }
         * }*/


        //impact.othello.othello.Main(new System.String[1] { "-d" });
        //Crafty.Net.OO.Crafty.Main(new System.String[0]);
        //SharpSAT.SATSolver.Main(new System.String[1]{"input"});
        //impact.li_130.xlisp.Main(new System.String[0]);

        long t2   = INucleusCalls.Rdtsc();
        uint diff = (uint)((t2 - t1) >> 16);

        INucleusCalls.DebugPrintHex(50, diff);
        doneSemaphore.Signal();
    }
예제 #12
0
    public override void Run()
    {
        System.DebugStub.Print("KeyboardDriver@" + Kernel.CurrentThread + ". ");
        uint      listener = 0;
        Semaphore done     = kernel.NewSemaphore(0);

        b1 = new BenchmarkAlloc(done);
        b2 = new BenchmarkAlloc2(done);

        while (true)
        {
            Kernel.kernel.Yield();
            uint key = INucleusCalls.TryReadKeyboard();
            char ch  = z;

            bool key_down = (key >> 7 == 0);

            key &= 0x7f;

            switch (key)
            {
            case LSHIFT_SCAN:
            case RSHIFT_SCAN:
                shift = key_down;
                continue;

            case CTRL_SCAN:
                ctrl = key_down;
                continue;

            case ALT_SCAN:
                alt = key_down;
                continue;

            default:
                if (key_down && key <= ASCII_TABLE_SIZE)
                {
                    ch = shift ? SHIFT_SCAN_ASCII[key] : SCAN_ASCII[key];
                    break;
                }
                continue;
            }

            if (key == 2)
            {
                // '1'
                kernel.NewThread(
                    new BenchmarkYieldTo(kernel, done, 0));
                done.Wait();
            }
            else if (key == 3)
            {
                // '2'
                kernel.NewThread(
                    new BenchmarkSemaphore(kernel, done, 0));
                done.Wait();
            }
            else if (key == 4)
            {
                // '3'
                kernel.NewThread(b1);
                done.Wait();
            }
            else if (key == 5)
            {
                // '4'
                kernel.NewThread(b2);
                done.Wait();
            }
            else if (key == 6)
            {
                // '5'
                t = new BinaryTree(23); // 16 * 2^(23+1) = 16 * 16MB = 256MB
            }
            else if (key == 7)
            {
                // '6'
                //if (t != null) t.Flip();
                //t = null;
            }
            if (ch != z)
            {
                if (ch == '\t' && ctrl && !shift)
                {
                    listener++;
                    if (listener >= listeners.Length)
                    {
                        listener = 0;
                    }
                }
                else if (ch == '\t' && ctrl && shift)
                {
                    listener--;
                    if (listener >= listeners.Length)
                    {
                        listener = (uint)listeners.Length - 1;
                    }
                }
                else
                {
                    LastChar = ch;
                    listeners[listener].Signal();
                }
            }
        }
    }