//public static Addr kernelStack = null; //public static Addr kernelStackBottom = null; //public static USize kernelStackSize = null; public static unsafe void InitializeUserMode() { if (!KConfig.UseUserMode) { return; } if (KConfig.UseTaskStateSegment) { //kernelStackSize = 256 * 4096; TssAddr = VirtualPageManager.AllocatePages(1); PageTable.KernelTable.SetWritable(TssAddr, 4096); KernelMemoryMapManager.Header->Used.Add(new KernelMemoryMap(TssAddr, 4096, BootInfoMemoryType.TSS, AddressSpaceKind.Virtual)); //kernelStack = RawVirtualFrameAllocator.RequestRawVirtalMemoryPages(256); // TODO: Decrease Kernel Stack, because Stack have to be changed directly because of multi-threading. //kernelStackBottom = kernelStack + kernelStackSize; //KernelMessage.WriteLine("tssEntry: {0:X8}, tssKernelStack: {1:X8}-{2:X8}", tssAddr, kernelStack, kernelStackBottom - 1); //MemoryManagement.PageTableExtensions.SetWritable(PageTable.KernelTable, kernelStack, 256 * 4096); } // Disabling Interrupts here is very important, otherwise we will get randomly an Invalid TSS Exception. IDTManager.Stop(); GDT.SetupUserMode(TssAddr); IDTManager.Start(); }
private static uint Cmd_RegisterInterrupt(SysCallContext *context, SystemMessage *args) { var proc = Scheduler.GetCurrentThread().Process; if (proc.Service != null) { IDTManager.SetInterruptHandler(args->Arg1, InterruptHandlers.Service, proc.Service); } return(0); }
internal static uint RegisterInterrupt(ref SysCallContext context, ref SystemMessage args) { var proc = Scheduler.GetCurrentThread().Process; if (proc.Service != null) { IDTManager.SetInterruptHandler(args.Arg1, InterruptHandlers.Service, proc.Service); } return(0); }
public static void Setup() { KernelMessage.WriteLine("Initialize SysCall Manager"); IDTManager.SetInterruptHandler(FunctionIRQ, FunctionInterruptHandler); IDTManager.SetPrivilegeLevel(FunctionIRQ, 0x03); IDTManager.SetInterruptHandler(ActionIRQ, ActionInterruptHandler); IDTManager.SetPrivilegeLevel(ActionIRQ, 0x03); IDTManager.Flush(); Commands = new SysCallHandlerInfo[256]; SetCommands(); }
public static bool Enter() { // This check is correct. // If Interrupts are disabled: Nobody can change it's state. We have exclusive control. // If Interrupts are enabled: This doesn't matter, because the other routine will re-enable it on ISR exit. // So, InterrupsEnabled() is a check, if the current thread is an ISR or not. if (IDTManager.InterrupsEnabled()) { Native.Cli(); return(true); } return(false); }
public static unsafe void Start() { SetThreadID(0); Enabled = true; KernelMessage.WriteLine("Enable Scheduler"); IDTManager.SetPrivilegeLevel((uint)KnownInterrupt.TerminateCurrentThread, 0x03); GDT.Tss->ESP0 = Threads[0].KernelStackBottom; GDT.LoadTaskRegister(); TriggerScheduler(); // Normally, you should never get here Panic.Error("Main-Thread still alive"); }
internal static void Enter(object obj) { var sync = Intrinsic.GetObjectAddress(obj) + IntPtr.Size; if (IDTManager.InterrupsEnabled()) { // Thread Native.Cli(); while (Native.CmpXChgLoad32(sync.ToInt32(), 2, 0) != 0) { } } else { // ISR while (Native.CmpXChgLoad32(sync.ToInt32(), 1, 0) != 0) { } } }
public static unsafe void Main() { try { ManagedMemoy.InitializeGCMemory(); StartUp.InitializeAssembly(); KMath.Init(); //Mosa.Runtime.StartUp.InitializeRuntimeMetadata(); BootInfo.SetupStage1(); Memory.InitialKernelProtect(); ApiContext.Current = new ApiHost(); Assert.Setup(AssertError); // Setup some pseudo devices DeviceManager.InitStage1(); //Setup Output and Debug devices DeviceManager.InitStage2(); // Write first output KernelMessage.WriteLine("<KERNEL:CONSOLE:BEGIN>"); PerformanceCounter.Setup(BootInfo.Header->KernelBootStartCycles); KernelMessage.WriteLine("Starting Abanu Kernel..."); KernelMessage.WriteLine("KConfig.UseKernelMemoryProtection: {0}", KConfig.UseKernelMemoryProtection); KernelMessage.WriteLine("KConfig.UsePAE: {0}", KConfig.UsePAE); KernelMessage.WriteLine("Apply PageTableType: {0}", (uint)BootInfo.Header->PageTableType); KernelMessage.WriteLine("GCInitialMemory: {0:X8}-{1:X8}", Address.GCInitialMemory, Address.GCInitialMemory + Address.GCInitialMemorySize - 1); Ulongtest1(); Ulongtest2(); InlineTest(); // Detect environment (Memory Maps, Video Mode, etc.) BootInfo.SetupStage2(); KernelMemoryMapManager.Setup(); //KernelMemoryMapManager.Allocate(0x1000 * 1000, BootInfoMemoryType.PageDirectory); // Read own ELF-Headers and Sections KernelElf.Setup(); // Initialize the embedded code (actually only a little proof of concept code) NativeCalls.Setup(); //InitialKernelProtect(); PhysicalPageManager.Setup(); KernelMessage.WriteLine("Phys free: {0}", PhysicalPageManager.FreePages); PhysicalPageManager.AllocatePages(10); KernelMessage.WriteLine("Phys free: {0}", PhysicalPageManager.FreePages); VirtualPageManager.Setup(); Memory.Setup(); // Now Memory Sub System is working. At this point it's valid // to allocate memory dynamically DeviceManager.InitFrameBuffer(); // Setup Programmable Interrupt Table PIC.Setup(); // Setup Interrupt Descriptor Table // Important Note: IDT depends on GDT. Never setup IDT before GDT. IDTManager.Setup(); InitializeUserMode(); SysCallManager.Setup(); KernelMessage.WriteLine("Initialize Runtime Metadata"); StartUp.InitializeRuntimeMetadata(); KernelMessage.WriteLine("Performing some Non-Thread Tests"); Tests(); } catch (Exception ex) { Panic.Error(ex.Message); } if (KConfig.SingleThread) { StartupStage2(); } else { ProcessManager.Setup(StartupStage2); } }