//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 unsafe void InitializeUserMode() { if (!KConfig.UseUserMode) { return; } if (KConfig.UseTaskStateSegment) { TssAddr = VirtualPageManager.AllocatePages(1); PageTable.KernelTable.SetWritable(TssAddr, 4096); KernelMemoryMapManager.Header->Used.Add(new KernelMemoryMap(TssAddr, 4096, BootInfoMemoryType.TSS, AddressSpaceKind.Virtual)); } // Disabling Interrupts here is very important, otherwise we will get randomly an Invalid TSS Exception. Uninterruptible.Execute(() => { GDT.SetupUserMode(TssAddr); }); }