示例#1
0
        private static void CreatePrologueAndEpilogueBlocks(InstructionSet instructionSet, BasicBlocks basicBlocks)
        {
            // Create the prologue block
            var context = instructionSet.CreateNewBlock(basicBlocks, BasicBlock.PrologueLabel);

            // Add a jump instruction to the first block from the prologue
            context.AppendInstruction(IRInstruction.Jmp);
            context.SetBranch(0);
            var prologue = context.BasicBlock;
            basicBlocks.AddHeaderBlock(prologue);

            // Create the epilogue block
            context = instructionSet.CreateNewBlock(basicBlocks, BasicBlock.EpilogueLabel);
            var epilogue = context.BasicBlock;
        }
示例#2
0
        /// <summary>
        /// Creates the ISR methods.
        /// </summary>
        private void CreateExceptionVector()
        {
            var type = TypeSystem.GetTypeByName("Mosa.Kernel.x86", "IDT");

            if (type == null)
                return;

            var method = type.FindMethodByName("ExceptionHandlerType");

            if (method == null)
                return;

            Operand exceptionMethod = Operand.CreateSymbolFromMethod(TypeSystem, method);

            Operand esp = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ESP);

            BasicBlocks basicBlocks = new BasicBlocks();
            InstructionSet instructionSet = new InstructionSet(25);
            Context ctx = instructionSet.CreateNewBlock(basicBlocks);
            basicBlocks.AddHeaderBlock(ctx.BasicBlock);

            // TODO - setup stack for call to the managed exception handler

            //1.
            //2.

            //3. Call the managed exception handler
            ctx.AppendInstruction(X86.Call, null, exceptionMethod);

            var vectorMethod = Compiler.CreateLinkerMethod("ExceptionVector");

            Compiler.CompileMethod(vectorMethod, basicBlocks, instructionSet);
        }
示例#3
0
        protected override void Run()
        {
            var typeInitializer = Compiler.Pipeline.FindFirst<TypeInitializerSchedulerStage>().TypeInitializerMethod;

            var basicBlocks = new BasicBlocks();
            var instructionSet = new InstructionSet(25);

            var context = instructionSet.CreateNewBlock(basicBlocks);
            basicBlocks.AddHeaderBlock(context.BasicBlock);

            var entryPoint = Operand.CreateSymbolFromMethod(TypeSystem, typeInitializer);

            context.AppendInstruction(IRInstruction.Call, null, entryPoint);
            context.MosaMethod = typeInitializer;

            var method = Compiler.CreateLinkerMethod(StartUpName);
            Compiler.CompileMethod(method, basicBlocks, instructionSet);

            Linker.EntryPoint = Linker.GetSymbol(method.FullName, SectionKind.Text);
        }
示例#4
0
        /// <summary>
        /// Creates the interrupt service routine (ISR) methods.
        /// </summary>
        private void CreateInterruptVectors()
        {
            var type = TypeSystem.GetTypeByName("Mosa.Kernel.x86", "IDT");

            if (type == null)
                return;

            var method = type.FindMethodByName("ProcessInterrupt");

            if (method == null)
                return;

            Operand interrupt = Operand.CreateSymbolFromMethod(TypeSystem, method);

            Operand esp = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ESP);

            for (int i = 0; i <= 255; i++)
            {
                BasicBlocks basicBlocks = new BasicBlocks();
                InstructionSet instructionSet = new InstructionSet(25);
                Context ctx = instructionSet.CreateNewBlock(basicBlocks);
                basicBlocks.AddHeaderBlock(ctx.BasicBlock);

                ctx.AppendInstruction(X86.Cli);
                if (i <= 7 || i >= 16 | i == 9) // For IRQ 8, 10, 11, 12, 13, 14 the cpu will automatically pushed the error code
                    ctx.AppendInstruction(X86.Push, null, Operand.CreateConstantUnsignedInt(TypeSystem, 0));
                ctx.AppendInstruction(X86.Push, null, Operand.CreateConstantUnsignedInt(TypeSystem, (uint)i));
                ctx.AppendInstruction(X86.Pushad);
                ctx.AppendInstruction(X86.Call, null, interrupt);
                ctx.AppendInstruction(X86.Popad);
                ctx.AppendInstruction(X86.Add, esp, esp, Operand.CreateConstantUnsignedInt(TypeSystem, 8));
                ctx.AppendInstruction(X86.Sti);
                ctx.AppendInstruction(X86.IRetd);

                var interruptMethod = Compiler.CreateLinkerMethod("InterruptISR" + i.ToString());
                Compiler.CompileMethod(interruptMethod, basicBlocks, instructionSet);
            }
        }
        protected override void Run()
        {
            if (multibootMethod == null)
            {
                multibootHeader = Linker.CreateSymbol(MultibootHeaderSymbolName, SectionKind.Text, 1, 0x30);

                multibootMethod = Compiler.CreateLinkerMethod("MultibootInit");

                Linker.EntryPoint = Linker.GetSymbol(multibootMethod.FullName, SectionKind.Text);

                WriteMultibootHeader();

                return;
            }

            var typeInitializerSchedulerStage = Compiler.Pipeline.FindFirst<TypeInitializerSchedulerStage>();

            var ecx = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ECX);
            var eax = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EAX);
            var ebx = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EBX);
            var ebp = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EBP);

            var basicBlocks = new BasicBlocks();
            var instructionSet = new InstructionSet(25);

            var ctx = instructionSet.CreateNewBlock(basicBlocks);
            basicBlocks.AddHeaderBlock(ctx.BasicBlock);

            // set sentinal on the stack to indicate the start of the stack
            var zero = Operand.CreateConstant(TypeSystem.BuiltIn.I4, 0);
            ctx.AppendInstruction(X86.Mov, Operand.CreateMemoryAddress(TypeSystem.BuiltIn.I4, ebp, 0), zero);

            // store multiboot registers eax and ebx at 0x200000 and 0x200004 respectively
            ctx.AppendInstruction(X86.Mov, ecx, Operand.CreateConstantSignedInt(TypeSystem, 0x200000));
            ctx.AppendInstruction(X86.Mov, Operand.CreateMemoryAddress(TypeSystem.BuiltIn.I4, ecx, 0), eax);
            ctx.AppendInstruction(X86.Mov, Operand.CreateMemoryAddress(TypeSystem.BuiltIn.I4, ecx, 4), ebx);

            // call type initializer
            var entryPoint = Operand.CreateSymbolFromMethod(TypeSystem, typeInitializerSchedulerStage.TypeInitializerMethod);
            ctx.AppendInstruction(X86.Call, null, entryPoint);

            // should never get here
            ctx.AppendInstruction(X86.Ret);

            Compiler.CompileMethod(multibootMethod, basicBlocks, instructionSet);
        }
示例#6
0
        protected override void Run()
        {
            if (multibootMethod == null)
            {
                multibootMethod = Compiler.CreateLinkerMethod("MultibootInit");

                WriteMultibootHeader();

                return;
            }

            var typeInitializerSchedulerStage = Compiler.Pipeline.FindFirst<TypeInitializerSchedulerStage>();

            var ecx = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ECX);
            var eax = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EAX);
            var ebx = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EBX);

            var basicBlocks = new BasicBlocks();
            var instructionSet = new InstructionSet(25);

            var ctx = instructionSet.CreateNewBlock(basicBlocks);
            basicBlocks.AddHeaderBlock(ctx.BasicBlock);

            ctx.AppendInstruction(X86.Mov, ecx, Operand.CreateConstantSignedInt(TypeSystem, 0x200000));
            ctx.AppendInstruction(X86.Mov, Operand.CreateMemoryAddress(TypeSystem.BuiltIn.I4, ecx, 0), eax);
            ctx.AppendInstruction(X86.Mov, Operand.CreateMemoryAddress(TypeSystem.BuiltIn.I4, ecx, 4), ebx);

            var entryPoint = Operand.CreateSymbolFromMethod(TypeSystem, typeInitializerSchedulerStage.TypeInitializerMethod);

            ctx.AppendInstruction(X86.Call, null, entryPoint);
            ctx.AppendInstruction(X86.Ret);

            Compiler.CompileMethod(multibootMethod, basicBlocks, instructionSet);

            Linker.EntryPoint = Linker.GetSymbol(multibootMethod.FullName);
        }