예제 #1
0
    private void KernelMain()
    {
        CompilerIntrinsics.Cli(); // TODO: superfluous
        for (uint i = 0; i < 50 * 80; i++)
        {
            NucleusCalls.VgaTextWrite(i, 0);
        }

        Thread init = new Thread(new InitThread(), true);

        _NewThread(init);

        uint x = 0xe100;
        uint y = 0;

        while (true)
        {
            CompilerIntrinsics.Cli(); // TODO: superfluous
            NucleusCalls.VgaTextWrite(79, x);
            x++;

            // Schedule thread, wait for exception or interrupt
            ScheduleNextThread();

            // CurrentThread received exception, interrupt, or exited voluntarily
            uint   cid = CurrentThread;
            Thread t   = threadTable[cid];

            CompilerIntrinsics.Cli(); // TODO: superfluous
            uint cState = NucleusCalls.GetStackState(cid);
            if (cState == STACK_EMPTY)
            {
                // Thread received an exception.  Kill it.
                t.alive = false;
            }

            CompilerIntrinsics.Cli(); // TODO: superfluous
            if (t.alive)
            {
                // Thread was interrupted.  It's still ready to run.
                NucleusCalls.SendEoi();
                CheckWakeUp();
                CompilerIntrinsics.Cli(); // TODO: superfluous
                NucleusCalls.StartTimer(0);
                readyQueue.Enqueue(t);
            }
            else
            {
                NucleusCalls.VgaTextWrite(78, (uint)(0x5b00 + 0x1100 * (y++) + 48 + cid));
                // Thread is dead.  Dead threads always jump back to stack 0.
                threadTable[cid] = null;
                NucleusCalls.ResetStack(cid);
            }
        }
    }