├── Src ├── Boot │ └── Bootloader │ │ ├── stdafx.cpp │ │ ├── kernel.h │ │ ├── mmu.hpp │ │ ├── stdafx.h │ │ ├── Bootloader.inf │ │ ├── Bootloader.vcxproj.filters │ │ ├── bootloader.h │ │ ├── Paging.cpp │ │ ├── Bootloader.cpp │ │ └── Bootloader.vcxproj ├── Tomato │ └── System │ │ ├── TMTCRT │ │ ├── TMTCRT.Shared │ │ │ ├── stdafx.cpp │ │ │ ├── stdafx.h │ │ │ ├── DllMain.cpp │ │ │ ├── crtinit.cpp │ │ │ ├── crtinit.h │ │ │ ├── ExternVariables.h │ │ │ ├── TMTCRT.Shared.vcxitems │ │ │ ├── TMTCRT.Shared.vcxitems.filters │ │ │ └── memory.cpp │ │ └── TMTCRT.Kernel │ │ │ ├── TMTCRT.Kernel.vcxproj.filters │ │ │ └── TMTCRT.Kernel.vcxproj │ │ ├── BootVideo │ │ ├── BootFont.h │ │ ├── GlyphProvider.cpp │ │ ├── stdafx.cpp │ │ ├── stdafx.h │ │ ├── GlyphProvider.h │ │ ├── VGAExternalController.cpp │ │ ├── BootVideo.hpp │ │ ├── ReadMe.txt │ │ ├── BootVideo.vcxproj.filters │ │ ├── VGAGraphicsController.cpp │ │ ├── BootVideo.cpp │ │ └── BootVideo.vcxproj │ │ └── OSKernel │ │ ├── OSKernel.cpp │ │ ├── setrspjmp.asm │ │ ├── KernelService.cpp │ │ ├── MemoryManager.cpp │ │ ├── ProcessManager.cpp │ │ ├── intrins.h │ │ ├── KernelService.h │ │ ├── stdafx.cpp │ │ ├── InternelStates.h │ │ ├── stdafx.h │ │ ├── ProcessManager.h │ │ ├── MemoryManager.h │ │ ├── ReadMe.txt │ │ ├── OSKernel.vcxproj.filters │ │ └── OSKernel.vcxproj └── include │ ├── common │ └── math.h │ └── kernel │ ├── kernel.h │ └── mmu.hpp ├── Build ├── Readme.txt ├── unmount.s ├── copy.cmd ├── mount.s ├── make.cmd ├── build.cmd └── pre.cmd ├── .gitattributes ├── .gitignore └── Tomato.sln /Src/Boot/Bootloader/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" -------------------------------------------------------------------------------- /Src/Tomato/System/TMTCRT/TMTCRT.Shared/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // 2 | #include "stdafx.h" -------------------------------------------------------------------------------- /Src/Boot/Bootloader/kernel.h: -------------------------------------------------------------------------------- 1 | D:/Work/Projects/OS/Tomato/Src/include/kernel/kernel.h -------------------------------------------------------------------------------- /Src/Boot/Bootloader/mmu.hpp: -------------------------------------------------------------------------------- 1 | D:/Work/Projects/OS/Tomato/Src/include/kernel/mmu.hpp -------------------------------------------------------------------------------- /Build/Readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunnycase/TomatoOS/HEAD/Build/Readme.txt -------------------------------------------------------------------------------- /Build/unmount.s: -------------------------------------------------------------------------------- 1 | select vdisk file = "D:\VM\Tomato OS x64.vhd" 2 | detach vdisk 3 | exit -------------------------------------------------------------------------------- /Build/copy.cmd: -------------------------------------------------------------------------------- 1 | diskpart -s mount.s 2 | xcopy .\efi x:\efi /e /y 3 | xcopy .\Tomato x:\Tomato /e /y 4 | diskpart -s unmount.s -------------------------------------------------------------------------------- /Build/mount.s: -------------------------------------------------------------------------------- 1 | select vdisk file = "D:\VM\Tomato OS x64.vhd" 2 | attach vdisk 3 | select partition 2 4 | assign letter = X 5 | exit -------------------------------------------------------------------------------- /Src/Tomato/System/BootVideo/BootFont.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunnycase/TomatoOS/HEAD/Src/Tomato/System/BootVideo/BootFont.h -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/OSKernel.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunnycase/TomatoOS/HEAD/Src/Tomato/System/OSKernel/OSKernel.cpp -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/setrspjmp.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunnycase/TomatoOS/HEAD/Src/Tomato/System/OSKernel/setrspjmp.asm -------------------------------------------------------------------------------- /Build/make.cmd: -------------------------------------------------------------------------------- 1 | cmd /c build 2 | diskpart -s mount.s 3 | xcopy .\efi x:\efi /e /y 4 | xcopy .\Tomato x:\Tomato /e /y 5 | diskpart -s unmount.s -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/KernelService.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunnycase/TomatoOS/HEAD/Src/Tomato/System/OSKernel/KernelService.cpp -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/MemoryManager.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunnycase/TomatoOS/HEAD/Src/Tomato/System/OSKernel/MemoryManager.cpp -------------------------------------------------------------------------------- /Src/Tomato/System/BootVideo/GlyphProvider.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunnycase/TomatoOS/HEAD/Src/Tomato/System/BootVideo/GlyphProvider.cpp -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/ProcessManager.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunnycase/TomatoOS/HEAD/Src/Tomato/System/OSKernel/ProcessManager.cpp -------------------------------------------------------------------------------- /Src/Tomato/System/TMTCRT/TMTCRT.Shared/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include -------------------------------------------------------------------------------- /Src/Tomato/System/TMTCRT/TMTCRT.Shared/DllMain.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS - C 运行时库 3 | // DLL 入口点 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-23 6 | #include "stdafx.h" 7 | 8 | -------------------------------------------------------------------------------- /Build/build.cmd: -------------------------------------------------------------------------------- 1 | cd /d D:\Software\Development\SDKs\UDK2014 2 | build -p MdeModulePkg\MdeModulePkg.dsc -m MdeModulePkg\Application\Tomato\Boot\Bootloader\Bootloader.inf 3 | cd /d D:\Work\Projects\OS\Tomato\Build\x64\Debug -------------------------------------------------------------------------------- /Build/pre.cmd: -------------------------------------------------------------------------------- 1 | mkdir x64 2 | cd x64 3 | mkdir Debug 4 | cd Debug 5 | mkdir EFI 6 | cd EFI 7 | mkdir Boot 8 | cd /d D:\Software\Development\SDKs\UDK2014 9 | edksetup 10 | cd /d D:\Work\Projects\OS\Tomato\x64\Debug -------------------------------------------------------------------------------- /Src/Tomato/System/TMTCRT/TMTCRT.Shared/crtinit.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS - C 运行时库 3 | // 初始化 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-23 6 | #include "stdafx.h" 7 | #include "crtinit.h" 8 | 9 | void Tomato::CRT::_crt_init() 10 | { 11 | _crt_init_heap(); 12 | } -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/intrins.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // [Internal] 指令 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-22 6 | #pragma once 7 | 8 | extern "C" { 9 | // 设置 RSP 并跳转 10 | extern __declspec(noreturn) void setrspjmp(void* ptr, void(*func)()); 11 | } -------------------------------------------------------------------------------- /Src/Tomato/System/TMTCRT/TMTCRT.Shared/crtinit.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS - C 运行时库 3 | // 初始化 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-23 6 | #pragma once 7 | 8 | namespace Tomato { 9 | namespace CRT { 10 | void _crt_init_heap(); 11 | 12 | void _crt_init(); 13 | } 14 | } -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/KernelService.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // [Internal] 内核服务 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-22 6 | #pragma once 7 | 8 | namespace Tomato { 9 | namespace OS { 10 | 11 | class KernelService 12 | { 13 | public: 14 | KernelService(); 15 | 16 | void Run(); 17 | }; 18 | } 19 | } -------------------------------------------------------------------------------- /Src/Tomato/System/BootVideo/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // BootVideo.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // OSKernel.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/InternelStates.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // [Internal] 内部状态 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-22 6 | #pragma once 7 | #include "../BootVideo/BootVideo.hpp" 8 | 9 | namespace Tomato { 10 | namespace OS { 11 | 12 | extern BootVideo bootVideo; 13 | 14 | void KeFastFail(const wchar_t* message); 15 | } 16 | } -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include 9 | // TODO: reference additional headers your program requires here 10 | #include 11 | #include -------------------------------------------------------------------------------- /Src/Tomato/System/BootVideo/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | #include 8 | #include 9 | // TODO: reference additional headers your program requires here 10 | #include 11 | #include -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/ProcessManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // [Internal] 进程管理器 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-22 6 | #pragma once 7 | 8 | namespace Tomato { 9 | namespace OS { 10 | 11 | class Process 12 | { 13 | public: 14 | Process(); 15 | }; 16 | 17 | class ProcessManager 18 | { 19 | public: 20 | ProcessManager(); 21 | 22 | void AddProcess(Process&& process); 23 | }; 24 | } 25 | } -------------------------------------------------------------------------------- /Src/include/common/math.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // [Internal] 数学辅助 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-32 6 | #pragma once 7 | #include 8 | 9 | // 向上取整除法 10 | inline size_t CeilDiv(size_t numerator, size_t denominator) 11 | { 12 | auto factor = numerator / denominator; 13 | if (numerator % denominator) 14 | factor++; 15 | return factor; 16 | } 17 | 18 | inline bool TestBit(uint64_t value, int index) 19 | { 20 | return (value & (1ui64 << index)) != 0; 21 | } -------------------------------------------------------------------------------- /Src/Tomato/System/TMTCRT/TMTCRT.Shared/ExternVariables.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS - C 运行时库 3 | // 外部变量 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-23 6 | #pragma once 7 | 8 | #ifdef CRT_KERNEL 9 | #include "../../../System/OSKernel/MemoryManager.h" 10 | #include "../../BootVideo/BootVideo.hpp" 11 | #endif 12 | 13 | namespace Tomato { 14 | namespace CRT { 15 | #ifdef CRT_KERNEL 16 | extern Tomato::OS::BootVideo* bootVideo; 17 | extern Tomato::OS::MemoryManager* memoryManager; 18 | #endif 19 | } 20 | } -------------------------------------------------------------------------------- /Src/Tomato/System/TMTCRT/TMTCRT.Kernel/TMTCRT.Kernel.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 7 | 8 | 9 | -------------------------------------------------------------------------------- /Src/Tomato/System/BootVideo/GlyphProvider.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // [Internal] 字形提供程序 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-22 6 | #pragma once 7 | #include "BootFont.h" 8 | 9 | namespace Tomato { 10 | namespace OS { 11 | 12 | class GlyphProvider 13 | { 14 | public: 15 | GlyphProvider() = default; 16 | 17 | void Initialize(BitmapFont font); 18 | const unsigned char* GetGlyph(uint16_t chr) const noexcept; 19 | private: 20 | void GenerateIndexer(); 21 | private: 22 | BitmapFont font; 23 | const unsigned char* indexes[UINT16_MAX]; 24 | }; 25 | } 26 | } -------------------------------------------------------------------------------- /Src/Boot/Bootloader/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif -------------------------------------------------------------------------------- /Src/include/kernel/kernel.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // [Internal] 内核定义 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-18 6 | #pragma once 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include 13 | #include 14 | 15 | typedef struct 16 | { 17 | UINT8* AcpiTable; 18 | SMBIOS_TABLE_ENTRY_POINT* SmbiosTable; 19 | EFI_RUNTIME_SERVICES* RT; 20 | EFI_MEMORY_DESCRIPTOR* MemoryDescriptor; 21 | UINTN MemoryDescriptorEntryCount; 22 | UINTN MemoryDescriptorSize; 23 | UINTN FrameWidth; 24 | UINTN FrameHeight; 25 | EFI_PHYSICAL_ADDRESS FrameBufferBase; 26 | UINT32 FrameBufferSize; 27 | 28 | } KernelEntryParams; 29 | 30 | typedef void(__cdecl *KernelEntryPoint)(KernelEntryParams); 31 | 32 | #define KernelPoolType (EFI_MEMORY_TYPE)0x80000001 33 | #define KernelPagingDataType (EFI_MEMORY_TYPE)0x80000002 34 | #define KernelImageBase 0x140000000ui64 35 | #define KernelSize (uint64_t)(2 * 1024 * 1024) 36 | #define PAGE_SIZE 4096 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif -------------------------------------------------------------------------------- /Src/Tomato/System/BootVideo/VGAExternalController.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // [Internal] 引导阶段视频控制 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-21 6 | #include "stdafx.h" 7 | #include "BootVideo.hpp" 8 | 9 | using namespace Tomato::OS; 10 | 11 | namespace 12 | { 13 | enum : uint16_t 14 | { 15 | MiscellaneousOutputReadRegister = 0x3CC, 16 | DataRegister = 0x3CF 17 | }; 18 | 19 | void delay() 20 | { 21 | for (size_t i = 0; i < 10000; i++); 22 | } 23 | 24 | #pragma pack(push, 1) 25 | 26 | // 输出杂项寄存器 27 | struct tagMiscellaneousOutputReg 28 | { 29 | union 30 | { 31 | struct 32 | { 33 | uint8_t IOAS : 1; 34 | uint8_t RAMEnable: 1; 35 | uint8_t ColorSelect : 2; 36 | uint8_t : 1; 37 | uint8_t OEPage : 1; 38 | uint8_t HSYNCP : 1; 39 | uint8_t VSYNCP : 1; 40 | }; 41 | uint8_t value; 42 | }; 43 | 44 | tagMiscellaneousOutputReg(uint8_t value) 45 | :value(value) {} 46 | 47 | static tagMiscellaneousOutputReg Read() 48 | { 49 | return __inbyte(MiscellaneousOutputReadRegister); 50 | } 51 | }; 52 | static_assert(sizeof(tagMiscellaneousOutputReg) == 1, "size of tagGraphicsModeReg must be 1."); 53 | 54 | #pragma pack(pop) 55 | } 56 | 57 | uint8_t VGAExternalController::ReadMode() 58 | { 59 | return tagMiscellaneousOutputReg::Read().value; 60 | } -------------------------------------------------------------------------------- /Src/Tomato/System/TMTCRT/TMTCRT.Shared/TMTCRT.Shared.vcxitems: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | {45d41acc-2c3c-43d2-bc10-02aa73ffc7c7} 7 | 8 | 9 | 10 | %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Src/Tomato/System/TMTCRT/TMTCRT.Shared/TMTCRT.Shared.vcxitems.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {3f50e3cd-9a17-4586-b752-b7a142472fa2} 6 | 7 | 8 | {38a9f3c2-6d7c-4c73-8629-fe8c5db36aee} 9 | 10 | 11 | 12 | 13 | Headers 14 | 15 | 16 | Headers 17 | 18 | 19 | Headers 20 | 21 | 22 | 23 | 24 | Sources 25 | 26 | 27 | Sources 28 | 29 | 30 | Sources 31 | 32 | 33 | Sources 34 | 35 | 36 | -------------------------------------------------------------------------------- /Src/Tomato/System/BootVideo/BootVideo.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // [Internal] 引导阶段视频控制 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-20 6 | #pragma once 7 | #include "GlyphProvider.h" 8 | #include 9 | 10 | namespace Tomato { 11 | namespace OS 12 | { 13 | // VGA 视频客户端 14 | class VGAVideoClient 15 | { 16 | public: 17 | int ConsoleWrite(unsigned char ch); 18 | void ConsoleClear(const unsigned short c); 19 | unsigned ConsoleSetColor(const unsigned c); 20 | }; 21 | 22 | class VGAGraphicsController 23 | { 24 | public: 25 | uint8_t ReadMode(); 26 | }; 27 | 28 | class VGAExternalController 29 | { 30 | public: 31 | uint8_t ReadMode(); 32 | }; 33 | 34 | class BootVideo 35 | { 36 | public: 37 | BootVideo() = default; 38 | 39 | void Initialize(uint32_t* frameBuffer, size_t bufferSize, size_t frameWidth, size_t frameHeight); 40 | void PutChar(wchar_t chr); 41 | void PutString(const wchar_t* string); 42 | void PutString(const wchar_t* string, size_t count); 43 | void PutFormat(const wchar_t* format, ...); 44 | void MovePositionTo(size_t x, size_t y); 45 | void ClearScreen(); 46 | void SetBackground(uint32_t color); 47 | private: 48 | void FixCurrentFramePointer(); 49 | private: 50 | GlyphProvider glyphProvider; 51 | uint32_t* frameBuffer, *currentFramePointer; 52 | size_t bufferSize; 53 | size_t frameWidth, frameHeight; 54 | size_t currentX, currentY; 55 | uint32_t foreground, background; 56 | }; 57 | } 58 | } -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/MemoryManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // [Internal] 内存管理器 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-22 6 | #pragma once 7 | #include 8 | 9 | struct _EFI_MEMORY_DESCRIPTOR; 10 | typedef _EFI_MEMORY_DESCRIPTOR EFI_MEMORY_DESCRIPTOR; 11 | 12 | namespace Tomato { 13 | namespace OS { 14 | 15 | class PhysicalMemory 16 | { 17 | public: 18 | void Initialize(const EFI_MEMORY_DESCRIPTOR* memoryDescriptor, size_t descriptorSize, size_t descriptorCount); 19 | 20 | void* AllocatePages(size_t pageCount); 21 | void FreePages(void* pageAddr, size_t pageCount); 22 | private: 23 | // 获取内存大小 24 | void AcquireMemorySize(const EFI_MEMORY_DESCRIPTOR* memoryDescriptor, size_t descriptorSize, size_t descriptorCount); 25 | // 初始化使用情况控制块 26 | void InitializeUsageControlBlock(const EFI_MEMORY_DESCRIPTOR* memoryDescriptor, size_t descriptorSize, size_t descriptorCount); 27 | void FlushUsageControlBlock(); 28 | private: 29 | typedef uint64_t usageControlBlock_t; 30 | 31 | size_t physicalMemorySize; // 物理内存大小 32 | usageControlBlock_t* usageControlBlock; // 使用量控制块 33 | size_t usageControlBlockBits; 34 | size_t usageControlBlockSize; 35 | size_t pageUsed, pageAvaliable; 36 | }; 37 | 38 | class MemoryManager 39 | { 40 | public: 41 | MemoryManager() = default; 42 | 43 | void Initialize(const EFI_MEMORY_DESCRIPTOR* memoryDescriptor, size_t descriptorSize, size_t descriptorCount); 44 | // 分配页 45 | void* AllocatePages(size_t pageCount); 46 | void FreePages(void* pageAddr, size_t pageCount); 47 | private: 48 | PhysicalMemory physicalMemory; 49 | }; 50 | } 51 | } -------------------------------------------------------------------------------- /Src/Boot/Bootloader/Bootloader.inf: -------------------------------------------------------------------------------- 1 | ## @file 2 | # Tomato OS Bootloader 3 | # (c) 2015 SunnyCase 4 | # 创建日期:2015-4-21 5 | ## 6 | 7 | [Defines] 8 | INF_VERSION = 0x00010005 9 | BASE_NAME = Bootloader 10 | FILE_GUID = BAA61BC6-2100-4E9F-B340-2E2A2170D8E0 11 | 12 | MODULE_TYPE = UEFI_APPLICATION 13 | VERSION_STRING = 1.0 14 | UEFI_SPECIFICATION_VERSION = 0x0002001E 15 | ENTRY_POINT = UefiMain 16 | 17 | 18 | # 19 | # VALID_ARCHITECTURES = X64 20 | # 21 | 22 | [Sources.X64] 23 | Bootloader.cpp 24 | Paging.cpp 25 | 26 | [Packages] 27 | MdePkg/MdePkg.dec 28 | 29 | [LibraryClasses] 30 | UefiApplicationEntryPoint 31 | UefiLib 32 | 33 | [Protocols] 34 | gEfiLoadedImageProtocolGuid 35 | gEfiSimpleFileSystemProtocolGuid 36 | 37 | [BuildOptions] 38 | MSFT:*_*_IA32_CC_FLAGS == /nologo /W4 /WX- /Gy /c /D UNICODE /Od /FIAutoGen.h /EHs-c- /GF /Gs8192 /Zi /Gm /D _CRT_SECURE_NO_WARNINGS /D _CRT_SECURE_NO_DEPRECATE 39 | MSFT:*_*_IA32_PP_FLAGS == /nologo /E /TC /FIAutoGen.h 40 | 41 | MSFT:*_*_X64_DLINK_FLAGS == /OUT:"D:\Work\Projects\OS\Tomato\x64\Debug\EFI\Boot\bootx64.efi" /MANIFEST /NXCOMPAT:NO /PDB:"D:\Work\Projects\OS\Tomato\x64\Debug\EFI\Boot\bootx64.pdb" /DYNAMICBASE:NO /MACHINE:X64 /ENTRY:"_ModuleEntryPoint" /INCREMENTAL /SUBSYSTEM:EFI_APPLICATION /MANIFESTUAC:NO /ERRORREPORT:PROMPT /NOLOGO /NODEFAULTLIB /TLBID:1 42 | MSFT:*_*_X64_CC_FLAGS == /nologo /W4 /WX- /Gy /c /D UNICODE /Od /FIAutoGen.h /EHs-c- /GF /Gs8192 /Zi /Gm /D _CRT_SECURE_NO_WARNINGS /D _CRT_SECURE_NO_DEPRECATE 43 | MSFT:*_*_X64_PP_FLAGS == /nologo /E /TC /FIAutoGen.h -------------------------------------------------------------------------------- /Src/Boot/Bootloader/Bootloader.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | -------------------------------------------------------------------------------- /Src/Tomato/System/BootVideo/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | STATIC LIBRARY : BootVideo Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this BootVideo library project for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your BootVideo application. 9 | 10 | 11 | BootVideo.vcxproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | BootVideo.vcxproj.filters 18 | This is the filters file for VC++ projects generated using an Application Wizard. 19 | It contains information about the association between the files in your project 20 | and the filters. This association is used in the IDE to show grouping of files with 21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 22 | "Source Files" filter). 23 | 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 27 | StdAfx.h, StdAfx.cpp 28 | These files are used to build a precompiled header (PCH) file 29 | named BootVideo.pch and a precompiled types file named StdAfx.obj. 30 | 31 | ///////////////////////////////////////////////////////////////////////////// 32 | Other notes: 33 | 34 | AppWizard uses "TODO:" comments to indicate parts of the source code you 35 | should add to or customize. 36 | 37 | ///////////////////////////////////////////////////////////////////////////// 38 | -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | CONSOLE APPLICATION : OSKernel Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this OSKernel application for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your OSKernel application. 9 | 10 | 11 | OSKernel.vcxproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | OSKernel.vcxproj.filters 18 | This is the filters file for VC++ projects generated using an Application Wizard. 19 | It contains information about the association between the files in your project 20 | and the filters. This association is used in the IDE to show grouping of files with 21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 22 | "Source Files" filter). 23 | 24 | OSKernel.cpp 25 | This is the main application source file. 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | Other standard files: 29 | 30 | StdAfx.h, StdAfx.cpp 31 | These files are used to build a precompiled header (PCH) file 32 | named OSKernel.pch and a precompiled types file named StdAfx.obj. 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | Other notes: 36 | 37 | AppWizard uses "TODO:" comments to indicate parts of the source code you 38 | should add to or customize. 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | -------------------------------------------------------------------------------- /Src/Boot/Bootloader/bootloader.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // Bootloader 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-19 6 | #pragma once 7 | #include "kernel.h" 8 | #include "mmu.hpp" 9 | 10 | #define MPrint(fmt, ...) Print((const CHAR16*)fmt, __VA_ARGS__) 11 | 12 | #define EXIT_IF_NOT_SUCCESS(status, imageHandle, fmt, ...) if(EFI_ERROR((status))){\ 13 | MPrint(fmt, __VA_ARGS__); \ 14 | gBS->Exit(imageHandle, status, 0, nullptr); } 15 | 16 | static UINTN KernelPoolSize = 1024 * 1024; // 1 MB 17 | 18 | inline UINTN AlignSize(UINTN size, UINTN align) 19 | { 20 | UINTN newSize = size - size % align; 21 | if (newSize < size) newSize += align; 22 | return newSize; 23 | } 24 | 25 | class KernelFile 26 | { 27 | public: 28 | KernelFile(EFI_HANDLE imageHandle) 29 | :imageHandle(imageHandle){} 30 | KernelFile(KernelFile&& file); 31 | ~KernelFile(); 32 | 33 | void LoadKernelFile(); 34 | bool ValidateKernel(); 35 | KernelEntryPoint GetEntryPoint(); 36 | 37 | UINT8* GetKernelFileBuffer() const { return kernelFileBuffer; } 38 | private: 39 | KernelFile& operator=(KernelFile&) = delete; 40 | KernelFile(KernelFile&) = delete; 41 | private: 42 | EFI_HANDLE imageHandle; 43 | UINT8* kernelFileBuffer; 44 | }; 45 | 46 | class Bootloader 47 | { 48 | public: 49 | Bootloader(EFI_HANDLE imageHandle) 50 | :imageHandle(imageHandle){} 51 | 52 | void Boot(); 53 | private: 54 | void PrintMemoryMap(); 55 | void PreparePaging(); 56 | void MappingFrameBuffer(Tomato::OS::PDPTable& pdpTable); 57 | // 启用分页 58 | void EnablePaging(); 59 | KernelFile LoadKernel(); 60 | void PrepareKernel(KernelFile& file); 61 | void RunKernel(KernelEntryPoint entryPoint); 62 | void InitializeKernelEntryParams(); 63 | void PrepareVirtualMemoryMapping(); 64 | void SetGraphicsMode(); 65 | private: 66 | EFI_HANDLE imageHandle; 67 | EFI_PHYSICAL_ADDRESS kernelMemBuffer; 68 | EFI_IMAGE_SECTION_HEADER* sectionStart; 69 | UINTN sectionCount; 70 | EFI_GRAPHICS_OUTPUT_PROTOCOL* gop; 71 | KernelEntryParams params; 72 | Tomato::OS::PML4Table* pml4Table; 73 | }; 74 | 75 | -------------------------------------------------------------------------------- /Src/Tomato/System/BootVideo/BootVideo.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | 35 | 36 | Source Files 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/OSKernel.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | 67 | 68 | Source Files 69 | 70 | 71 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Src/Tomato/System/BootVideo/VGAGraphicsController.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // [Internal] 引导阶段视频控制 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-21 6 | #include "stdafx.h" 7 | #include "BootVideo.hpp" 8 | 9 | using namespace Tomato::OS; 10 | 11 | namespace 12 | { 13 | enum : uint16_t 14 | { 15 | AddressRegister = 0x3CE, 16 | DataRegister = 0x3CF 17 | }; 18 | 19 | void delay() 20 | { 21 | for (size_t i = 0; i < 10000; i++); 22 | } 23 | 24 | #pragma pack(push, 1) 25 | 26 | template 27 | struct RegAccessor 28 | { 29 | protected: 30 | static uint8_t ReadValue() 31 | { 32 | __outbyte(AddressRegister, Index); 33 | delay(); 34 | return __inbyte(DataRegister); 35 | } 36 | 37 | static void WriteValue(uint8_t value) 38 | { 39 | __outbyte(AddressRegister, Index); 40 | delay(); 41 | __outbyte(DataRegister, value); 42 | delay(); 43 | } 44 | }; 45 | 46 | #define DEFINE_GRAPHICSREG_FUNCS(name) \ 47 | name(uint8_t value) \ 48 | :value(value) {} \ 49 | \ 50 | static name Read() \ 51 | { \ 52 | return ReadValue(); \ 53 | } \ 54 | \ 55 | void Write() \ 56 | { \ 57 | WriteValue(value); \ 58 | } 59 | 60 | // 显示模式寄存器 61 | struct tagGraphicsModeReg : RegAccessor<0x5> 62 | { 63 | union 64 | { 65 | struct 66 | { 67 | uint8_t WriteMode : 2; 68 | uint8_t : 1; 69 | uint8_t ReadMode : 1; 70 | uint8_t HostOE : 1; 71 | uint8_t ShiftReg : 1; 72 | uint8_t Shift256 : 1; 73 | }; 74 | uint8_t value; 75 | }; 76 | DEFINE_GRAPHICSREG_FUNCS(tagGraphicsModeReg); 77 | }; 78 | static_assert(sizeof(tagGraphicsModeReg) == 1, "size of tagGraphicsModeReg must be 1."); 79 | 80 | // 内存映射类别 81 | enum MemoryMapKind : uint8_t 82 | { 83 | A0000h_BFFFFh = 0, // 128K 84 | A0000h_AFFFFh = 1, // 64K 85 | B0000h_B7FFFh = 2, // 32K 86 | B8000h_BFFFFh = 3 // 32K 87 | }; 88 | 89 | // Graphics Controller 杂项寄存器 90 | struct tagMiscellaneousGraphicsReg : RegAccessor<0x6> 91 | { 92 | union 93 | { 94 | struct 95 | { 96 | uint8_t AlphaDisable : 1; // 关闭字符模式,否则图形模式 97 | uint8_t ChainOE: 1; 98 | MemoryMapKind MemoryMap : 2; 99 | uint8_t : 4; 100 | }; 101 | uint8_t value; 102 | }; 103 | DEFINE_GRAPHICSREG_FUNCS(tagMiscellaneousGraphicsReg); 104 | }; 105 | static_assert(sizeof(tagMiscellaneousGraphicsReg) == 1, "size of tagMiscellaneousGraphicsReg must be 1."); 106 | 107 | #pragma pack(pop) 108 | } 109 | 110 | uint8_t VGAGraphicsController::ReadMode() 111 | { 112 | auto value = tagMiscellaneousGraphicsReg::Read(); 113 | value.AlphaDisable = 1; 114 | value.MemoryMap = MemoryMapKind::B8000h_BFFFFh; 115 | value.Write(); 116 | 117 | return tagMiscellaneousGraphicsReg::Read().value; 118 | } -------------------------------------------------------------------------------- /Src/Tomato/System/TMTCRT/TMTCRT.Shared/memory.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS - C 运行时库 3 | // 内存相关 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-23 6 | #include "stdafx.h" 7 | #include "ExternVariables.h" 8 | #include "crtinit.h" 9 | 10 | namespace { 11 | struct _heapheader 12 | { 13 | void* heap_ptr; // 系统堆指针 14 | size_t page_count; 15 | size_t obj_count; 16 | }; 17 | 18 | struct _heapentry : public _heapinfo 19 | { 20 | _heapheader* header; 21 | _heapentry* prev; 22 | _heapentry* next; 23 | 24 | void free() 25 | { 26 | if (_useflag != _USEDENTRY) return; 27 | 28 | _useflag = _FREEENTRY; 29 | header->obj_count--; 30 | // 同一个堆中的可以合并 31 | if (next && next->_useflag == _FREEENTRY && header == next->header) 32 | { 33 | _size += next->_size + sizeof(_heapentry); 34 | next = next->next; 35 | } 36 | if (!header->obj_count) 37 | { 38 | 39 | #ifdef CRT_KERNEL 40 | memoryManager->FreePages(header->heap_ptr, header->page_count); 41 | #endif 42 | } 43 | } 44 | }; 45 | 46 | _heapentry* _heapHead = nullptr; 47 | enum : size_t 48 | { 49 | DefaultHeapPages = 16, 50 | DefaultHeapSize = DefaultHeapPages * 4096 51 | }; 52 | } 53 | 54 | using namespace Tomato::CRT; 55 | 56 | // 初始化堆 57 | void Tomato::CRT::_crt_init_heap() 58 | { 59 | #ifdef CRT_KERNEL 60 | // 内核模式未分配堆,需自行分配 61 | uint8_t* heapData = (uint8_t*)memoryManager->AllocatePages(DefaultHeapPages); 62 | #else 63 | uint8_t* heapData = nullptr; 64 | #endif 65 | auto header = (_heapheader*)(heapData); 66 | header->heap_ptr = heapData; 67 | header->page_count = DefaultHeapPages; 68 | header->obj_count = 1; 69 | auto heap = (_heapentry*)(heapData + sizeof(_heapheader)); 70 | heap->_pentry = (int*)((uint8_t*)heap + sizeof(_heapentry)); 71 | heap->_size = DefaultHeapSize - sizeof(_heapheader) - sizeof(_heapentry); 72 | heap->_useflag = _FREEENTRY; 73 | heap->header = header; 74 | heap->prev = nullptr; 75 | heap->next = nullptr; 76 | _heapHead = heap; 77 | } 78 | 79 | void* __cdecl malloc( 80 | _In_ _CRT_GUARDOVERFLOW size_t _Size 81 | ) 82 | { 83 | // 包含控制块的大小 84 | const auto size_with_cb = _Size + sizeof(_heapentry); 85 | // 在堆链表中寻找 86 | for (auto heap = _heapHead; heap; heap = heap->next) 87 | { 88 | #ifdef CRT_KERNEL 89 | bootVideo->PutFormat(L"Heap at %x\r\n", heap); 90 | #endif 91 | if (heap->_useflag == _FREEENTRY) 92 | { 93 | // 大小相等则直接修改为使用中 94 | if (heap->_size == _Size) 95 | { 96 | heap->_useflag = _USEDENTRY; 97 | return heap->_pentry; 98 | } 99 | // 否则分离出来 100 | else if (heap->_size >= size_with_cb) 101 | { 102 | heap->_size -= size_with_cb; 103 | auto newheap = (_heapentry*)((uint8_t*)(heap->_pentry) + heap->_size); 104 | newheap->_size = _Size; 105 | newheap->header = heap->header; 106 | newheap->prev = heap; 107 | newheap->next = heap->next; 108 | newheap->_useflag = _USEDENTRY; 109 | newheap->_pentry = (int*)((uint8_t*)(newheap)+sizeof(_heapentry)); 110 | heap->header->obj_count++; 111 | heap->next = newheap; 112 | return newheap->_pentry; 113 | } 114 | } 115 | } 116 | return nullptr; 117 | } 118 | 119 | void __cdecl free( 120 | _Pre_maybenull_ _Post_invalid_ void* _Block 121 | ) 122 | { 123 | if (!_Block)return; 124 | 125 | auto heap = (_heapentry*)((uint8_t*)_Block - sizeof(_heapentry)); 126 | heap->free(); 127 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | 24 | # Visual Studio 2015 cache/options directory 25 | .vs/ 26 | 27 | # MSTest test Results 28 | [Tt]est[Rr]esult*/ 29 | [Bb]uild[Ll]og.* 30 | 31 | # NUNIT 32 | *.VisualState.xml 33 | TestResult.xml 34 | 35 | # Build Results of an ATL Project 36 | [Dd]ebugPS/ 37 | [Rr]eleasePS/ 38 | dlldata.c 39 | 40 | # DNX 41 | project.lock.json 42 | artifacts/ 43 | 44 | *_i.c 45 | *_p.c 46 | *_i.h 47 | *.ilk 48 | *.meta 49 | *.obj 50 | *.pch 51 | *.pdb 52 | *.pgc 53 | *.pgd 54 | *.rsp 55 | *.sbr 56 | *.tlb 57 | *.tli 58 | *.tlh 59 | *.tmp 60 | *.tmp_proj 61 | *.log 62 | *.vspscc 63 | *.vssscc 64 | .builds 65 | *.pidb 66 | *.svclog 67 | *.scc 68 | 69 | # Chutzpah Test files 70 | _Chutzpah* 71 | 72 | # Visual C++ cache files 73 | ipch/ 74 | *.aps 75 | *.ncb 76 | *.opensdf 77 | *.sdf 78 | *.cachefile 79 | 80 | # Visual Studio profiler 81 | *.psess 82 | *.vsp 83 | *.vspx 84 | 85 | # TFS 2012 Local Workspace 86 | $tf/ 87 | 88 | # Guidance Automation Toolkit 89 | *.gpState 90 | 91 | # ReSharper is a .NET coding add-in 92 | _ReSharper*/ 93 | *.[Rr]e[Ss]harper 94 | *.DotSettings.user 95 | 96 | # JustCode is a .NET coding add-in 97 | .JustCode 98 | 99 | # TeamCity is a build add-in 100 | _TeamCity* 101 | 102 | # DotCover is a Code Coverage Tool 103 | *.dotCover 104 | 105 | # NCrunch 106 | _NCrunch_* 107 | .*crunch*.local.xml 108 | 109 | # MightyMoose 110 | *.mm.* 111 | AutoTest.Net/ 112 | 113 | # Web workbench (sass) 114 | .sass-cache/ 115 | 116 | # Installshield output folder 117 | [Ee]xpress/ 118 | 119 | # DocProject is a documentation generator add-in 120 | DocProject/buildhelp/ 121 | DocProject/Help/*.HxT 122 | DocProject/Help/*.HxC 123 | DocProject/Help/*.hhc 124 | DocProject/Help/*.hhk 125 | DocProject/Help/*.hhp 126 | DocProject/Help/Html2 127 | DocProject/Help/html 128 | 129 | # Click-Once directory 130 | publish/ 131 | 132 | # Publish Web Output 133 | *.[Pp]ublish.xml 134 | *.azurePubxml 135 | ## TODO: Comment the next line if you want to checkin your 136 | ## web deploy settings but do note that will include unencrypted 137 | ## passwords 138 | #*.pubxml 139 | 140 | *.publishproj 141 | 142 | # NuGet Packages 143 | *.nupkg 144 | # The packages folder can be ignored because of Package Restore 145 | **/packages/* 146 | # except build/, which is used as an MSBuild target. 147 | !**/packages/build/ 148 | # Uncomment if necessary however generally it will be regenerated when needed 149 | #!**/packages/repositories.config 150 | 151 | # Windows Azure Build Output 152 | csx/ 153 | *.build.csdef 154 | 155 | # Windows Store app package directory 156 | AppPackages/ 157 | 158 | # Visual Studio cache files 159 | # files ending in .cache can be ignored 160 | *.[Cc]ache 161 | # but keep track of directories ending in .cache 162 | !*.[Cc]ache/ 163 | 164 | # Others 165 | ClientBin/ 166 | [Ss]tyle[Cc]op.* 167 | ~$* 168 | *~ 169 | *.dbmdl 170 | *.dbproj.schemaview 171 | *.pfx 172 | *.publishsettings 173 | node_modules/ 174 | orleans.codegen.cs 175 | 176 | # RIA/Silverlight projects 177 | Generated_Code/ 178 | 179 | # Backup & report files from converting an old project file 180 | # to a newer Visual Studio version. Backup files are not needed, 181 | # because we have git ;-) 182 | _UpgradeReport_Files/ 183 | Backup*/ 184 | UpgradeLog*.XML 185 | UpgradeLog*.htm 186 | 187 | # SQL Server files 188 | *.mdf 189 | *.ldf 190 | 191 | # Business Intelligence projects 192 | *.rdl.data 193 | *.bim.layout 194 | *.bim_*.settings 195 | 196 | # Microsoft Fakes 197 | FakesAssemblies/ 198 | 199 | # Node.js Tools for Visual Studio 200 | .ntvs_analysis.dat 201 | 202 | # Visual Studio 6 build log 203 | *.plg 204 | 205 | # Visual Studio 6 workspace options file 206 | *.opt 207 | 208 | # LightSwitch generated files 209 | GeneratedArtifacts/ 210 | _Pvt_Extensions/ 211 | ModelManifest.xml 212 | -------------------------------------------------------------------------------- /Tomato.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.22609.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Boot", "Boot", "{02C4C52E-2504-4FC3-BD09-D65AB289D2A3}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Bootloader", "Src\Boot\Bootloader\Bootloader.vcxproj", "{28B7C1E8-BD49-48E7-AC26-C5AE7A8ADAE2}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tomato", "Tomato", "{73562C4E-411B-44E9-8A0C-24A471AC9068}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "System", "System", "{5D4300C9-E1CF-4FD4-980C-D3E746A88DA2}" 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OSKernel", "Src\Tomato\System\OSKernel\OSKernel.vcxproj", "{04FC833C-8561-487F-8A2F-BD5A26D3DF8A}" 15 | EndProject 16 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BootVideo", "Src\Tomato\System\BootVideo\BootVideo.vcxproj", "{1E5A446D-7442-4D55-8F1E-EE51522B0FEB}" 17 | EndProject 18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TMTCRT", "TMTCRT", "{67CA607C-CDC7-4A57-A10A-6A86DF861F68}" 19 | EndProject 20 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TMTCRT.Kernel", "Src\Tomato\System\TMTCRT\TMTCRT.Kernel\TMTCRT.Kernel.vcxproj", "{BDA96904-85BB-4F2A-BF7A-659F0D5ACD8D}" 21 | EndProject 22 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TMTCRT.User", "Src\Tomato\System\TMTCRT\TMTCRT.User\TMTCRT.User.vcxproj", "{4FAE964A-A282-4C89-9EAD-18026E9F74B5}" 23 | EndProject 24 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TMTCRT.Shared", "Src\Tomato\System\TMTCRT\TMTCRT.Shared\TMTCRT.Shared.vcxitems", "{45D41ACC-2C3C-43D2-BC10-02AA73FFC7C7}" 25 | EndProject 26 | Global 27 | GlobalSection(SharedMSBuildProjectFiles) = preSolution 28 | Src\Tomato\System\TMTCRT\TMTCRT.Shared\TMTCRT.Shared.vcxitems*{4fae964a-a282-4c89-9ead-18026e9f74b5}*SharedItemsImports = 4 29 | Src\Tomato\System\TMTCRT\TMTCRT.Shared\TMTCRT.Shared.vcxitems*{bda96904-85bb-4f2a-bf7a-659f0d5acd8d}*SharedItemsImports = 4 30 | Src\Tomato\System\TMTCRT\TMTCRT.Shared\TMTCRT.Shared.vcxitems*{45d41acc-2c3c-43d2-bc10-02aa73ffc7c7}*SharedItemsImports = 9 31 | EndGlobalSection 32 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 33 | Debug|x64 = Debug|x64 34 | Debug|x86 = Debug|x86 35 | Release|x64 = Release|x64 36 | Release|x86 = Release|x86 37 | EndGlobalSection 38 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 39 | {28B7C1E8-BD49-48E7-AC26-C5AE7A8ADAE2}.Debug|x64.ActiveCfg = Debug|x64 40 | {28B7C1E8-BD49-48E7-AC26-C5AE7A8ADAE2}.Debug|x86.ActiveCfg = Debug|Win32 41 | {28B7C1E8-BD49-48E7-AC26-C5AE7A8ADAE2}.Debug|x86.Build.0 = Debug|Win32 42 | {28B7C1E8-BD49-48E7-AC26-C5AE7A8ADAE2}.Release|x64.ActiveCfg = Release|x64 43 | {28B7C1E8-BD49-48E7-AC26-C5AE7A8ADAE2}.Release|x64.Build.0 = Release|x64 44 | {28B7C1E8-BD49-48E7-AC26-C5AE7A8ADAE2}.Release|x86.ActiveCfg = Release|Win32 45 | {28B7C1E8-BD49-48E7-AC26-C5AE7A8ADAE2}.Release|x86.Build.0 = Release|Win32 46 | {04FC833C-8561-487F-8A2F-BD5A26D3DF8A}.Debug|x64.ActiveCfg = Debug|x64 47 | {04FC833C-8561-487F-8A2F-BD5A26D3DF8A}.Debug|x64.Build.0 = Debug|x64 48 | {04FC833C-8561-487F-8A2F-BD5A26D3DF8A}.Debug|x86.ActiveCfg = Debug|Win32 49 | {04FC833C-8561-487F-8A2F-BD5A26D3DF8A}.Debug|x86.Build.0 = Debug|Win32 50 | {04FC833C-8561-487F-8A2F-BD5A26D3DF8A}.Release|x64.ActiveCfg = Release|Win32 51 | {04FC833C-8561-487F-8A2F-BD5A26D3DF8A}.Release|x86.ActiveCfg = Release|Win32 52 | {04FC833C-8561-487F-8A2F-BD5A26D3DF8A}.Release|x86.Build.0 = Release|Win32 53 | {1E5A446D-7442-4D55-8F1E-EE51522B0FEB}.Debug|x64.ActiveCfg = Debug|x64 54 | {1E5A446D-7442-4D55-8F1E-EE51522B0FEB}.Debug|x64.Build.0 = Debug|x64 55 | {1E5A446D-7442-4D55-8F1E-EE51522B0FEB}.Debug|x86.ActiveCfg = Debug|Win32 56 | {1E5A446D-7442-4D55-8F1E-EE51522B0FEB}.Debug|x86.Build.0 = Debug|Win32 57 | {1E5A446D-7442-4D55-8F1E-EE51522B0FEB}.Release|x64.ActiveCfg = Release|Win32 58 | {1E5A446D-7442-4D55-8F1E-EE51522B0FEB}.Release|x86.ActiveCfg = Release|Win32 59 | {1E5A446D-7442-4D55-8F1E-EE51522B0FEB}.Release|x86.Build.0 = Release|Win32 60 | {BDA96904-85BB-4F2A-BF7A-659F0D5ACD8D}.Debug|x64.ActiveCfg = Debug|x64 61 | {BDA96904-85BB-4F2A-BF7A-659F0D5ACD8D}.Debug|x64.Build.0 = Debug|x64 62 | {BDA96904-85BB-4F2A-BF7A-659F0D5ACD8D}.Debug|x86.ActiveCfg = Debug|Win32 63 | {BDA96904-85BB-4F2A-BF7A-659F0D5ACD8D}.Debug|x86.Build.0 = Debug|Win32 64 | {BDA96904-85BB-4F2A-BF7A-659F0D5ACD8D}.Release|x64.ActiveCfg = Release|Win32 65 | {BDA96904-85BB-4F2A-BF7A-659F0D5ACD8D}.Release|x86.ActiveCfg = Release|Win32 66 | {BDA96904-85BB-4F2A-BF7A-659F0D5ACD8D}.Release|x86.Build.0 = Release|Win32 67 | {4FAE964A-A282-4C89-9EAD-18026E9F74B5}.Debug|x64.ActiveCfg = Debug|x64 68 | {4FAE964A-A282-4C89-9EAD-18026E9F74B5}.Debug|x64.Build.0 = Debug|x64 69 | {4FAE964A-A282-4C89-9EAD-18026E9F74B5}.Debug|x86.ActiveCfg = Debug|Win32 70 | {4FAE964A-A282-4C89-9EAD-18026E9F74B5}.Debug|x86.Build.0 = Debug|Win32 71 | {4FAE964A-A282-4C89-9EAD-18026E9F74B5}.Release|x64.ActiveCfg = Release|Win32 72 | {4FAE964A-A282-4C89-9EAD-18026E9F74B5}.Release|x86.ActiveCfg = Release|Win32 73 | {4FAE964A-A282-4C89-9EAD-18026E9F74B5}.Release|x86.Build.0 = Release|Win32 74 | EndGlobalSection 75 | GlobalSection(SolutionProperties) = preSolution 76 | HideSolutionNode = FALSE 77 | EndGlobalSection 78 | GlobalSection(NestedProjects) = preSolution 79 | {28B7C1E8-BD49-48E7-AC26-C5AE7A8ADAE2} = {02C4C52E-2504-4FC3-BD09-D65AB289D2A3} 80 | {5D4300C9-E1CF-4FD4-980C-D3E746A88DA2} = {73562C4E-411B-44E9-8A0C-24A471AC9068} 81 | {04FC833C-8561-487F-8A2F-BD5A26D3DF8A} = {5D4300C9-E1CF-4FD4-980C-D3E746A88DA2} 82 | {1E5A446D-7442-4D55-8F1E-EE51522B0FEB} = {5D4300C9-E1CF-4FD4-980C-D3E746A88DA2} 83 | {67CA607C-CDC7-4A57-A10A-6A86DF861F68} = {5D4300C9-E1CF-4FD4-980C-D3E746A88DA2} 84 | {BDA96904-85BB-4F2A-BF7A-659F0D5ACD8D} = {67CA607C-CDC7-4A57-A10A-6A86DF861F68} 85 | {4FAE964A-A282-4C89-9EAD-18026E9F74B5} = {67CA607C-CDC7-4A57-A10A-6A86DF861F68} 86 | {45D41ACC-2C3C-43D2-BC10-02AA73FFC7C7} = {67CA607C-CDC7-4A57-A10A-6A86DF861F68} 87 | EndGlobalSection 88 | EndGlobal 89 | -------------------------------------------------------------------------------- /Src/Tomato/System/BootVideo/BootVideo.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // 引导阶段视频控制 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-20 6 | #include "stdafx.h" 7 | #include "BootVideo.hpp" 8 | #include "BootFont.h" 9 | 10 | using namespace Tomato::OS; 11 | // Note: Some systems may require 0xB0000 Instead of 0xB8000 12 | // We dont care for portability here, so pick either one 13 | #define VID_MEMORY 0xB8000 14 | 15 | // these vectors together act as a corner of a bounding rect 16 | // This allows GotoXY() to reposition all the text that follows it 17 | static unsigned int _xPos = 0, _yPos = 0; 18 | static unsigned _startX = 0, _startY = 0; 19 | 20 | // current color 21 | static unsigned _color = 0; 22 | 23 | int VGAVideoClient::ConsoleWrite(unsigned char ch) 24 | { 25 | if (ch == 0) 26 | return 0; 27 | 28 | if (ch == '\n' || ch == '\r') { /* start new line */ 29 | _yPos += 2; 30 | _xPos = _startX; 31 | return 0; 32 | } 33 | 34 | if (_xPos > 79) { /* start new line */ 35 | _yPos += 2; 36 | _xPos = _startX; 37 | return 0; 38 | } 39 | 40 | /* draw the character */ 41 | unsigned char* p = (unsigned char*)VID_MEMORY + (_xPos++) * 2 + _yPos * 80; 42 | *p++ = ch; 43 | *p = _color; 44 | 45 | return ch; 46 | } 47 | 48 | void VGAVideoClient::ConsoleClear(const unsigned short c) { 49 | 50 | unsigned char* p = (unsigned char*)VID_MEMORY; 51 | 52 | for (int i = 0; i < 160 * 30; i += 2) { 53 | 54 | p[i] = ' '; /* Need to watch out for MSVC++ optomization memset() call */ 55 | p[i + 1] = c; 56 | } 57 | 58 | // go to start of previous set vector 59 | _xPos = _startX; _yPos = _startY; 60 | } 61 | 62 | unsigned VGAVideoClient::ConsoleSetColor(const unsigned c) { 63 | 64 | unsigned t = _color; 65 | _color = c; 66 | return t; 67 | } 68 | 69 | void BootVideo::Initialize(uint32_t * frameBuffer, size_t bufferSize, size_t frameWidth, size_t frameHeight) 70 | { 71 | this->glyphProvider.Initialize(GetBootFont()); 72 | this->frameBuffer = frameBuffer; 73 | this->bufferSize = bufferSize; 74 | this->frameWidth = frameWidth; 75 | this->frameHeight = frameHeight; 76 | this->currentX = 0; 77 | this->currentY = 0; 78 | this->currentFramePointer = frameBuffer; 79 | this->foreground = 0x00ff99ff; 80 | } 81 | 82 | void BootVideo::PutChar(wchar_t chr) 83 | { 84 | auto& font = GetBootFont(); 85 | if (chr == L'\r') 86 | currentX = 0; 87 | else if (chr == L'\n') 88 | currentY += font.Height; 89 | else 90 | { 91 | int cx, cy; 92 | const unsigned char *glyph = glyphProvider.GetGlyph(chr); 93 | auto pixel = currentFramePointer; 94 | 95 | auto startPixel = pixel; 96 | for (cy = 0; cy < font.Height; cy++, glyph++) 97 | { 98 | unsigned char line = *glyph; 99 | auto pixel = startPixel; 100 | for (cx = 0; cx < font.Width; cx++) 101 | { 102 | *pixel++ = (line & 0x80ui8) ? foreground : background; 103 | line <<= 1; 104 | } 105 | startPixel += frameWidth; 106 | } 107 | currentX += font.Width; 108 | if (currentX >= frameWidth) 109 | { 110 | currentX = 0; 111 | currentY += font.Height; 112 | } 113 | } 114 | if (currentY + font.Height >= frameHeight) 115 | { 116 | ClearScreen(); 117 | currentY = 0; 118 | } 119 | FixCurrentFramePointer(); 120 | } 121 | 122 | void BootVideo::PutString(const wchar_t * string) 123 | { 124 | while (*string) 125 | PutChar(*string++); 126 | } 127 | 128 | void BootVideo::PutString(const wchar_t * string, size_t count) 129 | { 130 | for (size_t i = 0; i < count; i++) 131 | PutChar(*string++); 132 | } 133 | 134 | wchar_t tbuf[64]; 135 | wchar_t bchars[] = { L'0',L'1',L'2',L'3',L'4',L'5',L'6',L'7',L'8',L'9',L'A',L'B',L'C',L'D',L'E',L'F' }; 136 | wchar_t str[64] = { 0 }; 137 | 138 | void _itow(uint64_t i, unsigned base, wchar_t* buf) { 139 | int pos = 0; 140 | int opos = 0; 141 | int top = 0; 142 | 143 | buf[0] = '0'; 144 | buf[1] = '\0'; 145 | 146 | if (i == 0 || base > 16) { 147 | buf[0] = '0'; 148 | buf[1] = '\0'; 149 | return; 150 | } 151 | 152 | while (i != 0) { 153 | tbuf[pos] = bchars[i % base]; 154 | pos++; 155 | i /= base; 156 | } 157 | top = pos--; 158 | for (opos = 0; opos < top; pos--, opos++) { 159 | buf[opos] = tbuf[pos]; 160 | } 161 | buf[opos] = 0; 162 | } 163 | 164 | void _itow_s(uint64_t i, unsigned base, wchar_t* buf) { 165 | 166 | if (base > 16) return; 167 | if (i < 0) { 168 | *buf++ = '-'; 169 | i *= -1; 170 | } 171 | _itow(i, base, buf); 172 | } 173 | 174 | void BootVideo::PutFormat(const wchar_t * format, ...) 175 | { 176 | if (!format)return; 177 | 178 | va_list args; 179 | va_start(args, format); 180 | 181 | for (size_t i = 0; format[i]; i++) { 182 | 183 | switch (format[i]) { 184 | 185 | case L'%': 186 | 187 | switch (format[i + 1]) { 188 | 189 | /*** characters ***/ 190 | case L'c': { 191 | wchar_t c = va_arg(args, wchar_t); 192 | PutChar(c); 193 | i++; // go to next character 194 | break; 195 | } 196 | 197 | /*** address of ***/ 198 | case 's': { 199 | wchar_t* c = (wchar_t*)va_arg(args, wchar_t*); 200 | //char str[32]={0}; 201 | //itoa(c, 16, str); 202 | PutString(c); 203 | i++; // go to next character 204 | break; 205 | } 206 | 207 | /*** integers ***/ 208 | case 'd': 209 | case 'i': { 210 | int c = va_arg(args, int); 211 | _itow_s(c, 10, str); 212 | PutString(str); 213 | i++; // go to next character 214 | break; 215 | } 216 | case 'l': { 217 | int64_t c = va_arg(args, int64_t); 218 | _itow_s(c, 10, str); 219 | PutString(str); 220 | i++; // go to next character 221 | break; 222 | } 223 | /*** display in hex ***/ 224 | case 'X': 225 | case 'x': { 226 | int c = va_arg(args, int); 227 | //char str[32]={0}; 228 | _itow_s(c, 16, str); 229 | PutString(str); 230 | i++; // go to next character 231 | break; 232 | } 233 | 234 | default: 235 | va_end(args); 236 | return; 237 | } 238 | 239 | break; 240 | 241 | default: 242 | PutChar(format[i]); 243 | break; 244 | } 245 | 246 | } 247 | 248 | va_end(args); 249 | } 250 | 251 | void BootVideo::MovePositionTo(size_t x, size_t y) 252 | { 253 | currentX = std::min(x, frameWidth - 1); 254 | currentY = std::min(y, frameHeight - 1); 255 | FixCurrentFramePointer(); 256 | } 257 | 258 | void BootVideo::ClearScreen() 259 | { 260 | auto end = (uint32_t*)((uint8_t*)frameBuffer + bufferSize) + 1; 261 | for (auto pixel = frameBuffer; pixel < end; pixel++) 262 | *pixel = background; 263 | } 264 | 265 | void BootVideo::SetBackground(uint32_t color) 266 | { 267 | background = color; 268 | } 269 | 270 | void BootVideo::FixCurrentFramePointer() 271 | { 272 | currentFramePointer = frameBuffer + currentY * frameWidth + currentX; 273 | } 274 | 275 | namespace std 276 | { 277 | void __CLRCALL_PURE_OR_CDECL _Debug_message(const wchar_t *, 278 | const wchar_t *, unsigned int) 279 | { 280 | 281 | } 282 | } -------------------------------------------------------------------------------- /Src/include/kernel/mmu.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // [Internal] MMU 支持 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-19 6 | #pragma once 7 | #include 8 | #include 9 | 10 | #if (_MSC_VER < 1900) && !defined(noexcept) 11 | #define noexcept throw() 12 | #endif 13 | 14 | namespace Tomato { 15 | namespace OS 16 | { 17 | 18 | #pragma pack(push, 1) 19 | 20 | #ifdef _M_X64 21 | #define MSR_IA32_EFER 0xC0000080 22 | 23 | union tagMSR_IA32_EFER 24 | { 25 | struct 26 | { 27 | uint64_t SCE : 1; // SYSCALL Enable 28 | uint64_t Reserved_0 : 7; 29 | uint64_t LME : 1; // IA-32e Mode Enable 30 | uint64_t Reserved_1 : 1; 31 | uint64_t LMA : 1; // IA-32e Mode Active 32 | uint64_t NXE : 1; // Execute Disable Bit Enable 33 | uint64_t Reserved_2 : 52; 34 | }; 35 | uint64_t value; 36 | 37 | tagMSR_IA32_EFER(uint64_t value) 38 | :value(value) 39 | {} 40 | }; 41 | 42 | union tagCR0 43 | { 44 | struct 45 | { 46 | uint32_t PE : 1; 47 | uint32_t MP : 1; 48 | uint32_t EM : 1; 49 | uint32_t TS : 1; 50 | uint32_t ET : 1; 51 | uint32_t NE : 1; 52 | uint32_t Reserved_0 : 10; 53 | uint32_t WP : 1; 54 | uint32_t Reserved_1 : 1; 55 | uint32_t AM : 1; 56 | uint32_t Reserved_2 : 10; 57 | uint32_t NW : 1; 58 | uint32_t CD : 1; // 禁用 Cache 59 | uint32_t PG : 1; // 启用分页 60 | }; 61 | uint32_t value; 62 | 63 | tagCR0(uint32_t value) 64 | :value(value) 65 | {} 66 | }; 67 | 68 | union tagCR4 69 | { 70 | struct 71 | { 72 | uint64_t VME : 1; 73 | uint64_t PVI : 1; 74 | uint64_t TSD : 1; 75 | uint64_t DE : 1; 76 | uint64_t PSE : 1; 77 | uint64_t PAE : 1; 78 | uint64_t MCE : 1; 79 | uint64_t PGE : 1; 80 | uint64_t PCE : 1; 81 | uint64_t OSFXSR : 1; 82 | uint64_t OSXMMEXCPT : 1; 83 | uint64_t Reserved_3 : 2; 84 | uint64_t VMXE : 1; 85 | uint64_t SMXE : 1; 86 | uint64_t Reserved_2 : 1; 87 | uint64_t FSGSBASE : 1; 88 | uint64_t PCIDE : 1; // Enables process-context identifiers 89 | uint64_t OSXSAVE : 1; 90 | uint64_t Reserved_1 : 1; 91 | uint64_t SMEP : 1; 92 | uint64_t SMAP : 1; 93 | uint64_t Reserved_0 : 42; 94 | }; 95 | uint64_t value; 96 | 97 | tagCR4(uint64_t value) 98 | :value(value) 99 | {} 100 | }; 101 | 102 | #define PHYSIC_ADDR_MASK 0x7FFFFFFFFF000ui64 103 | #define PHYSIC_ADDR_SHIFT 12 104 | 105 | // Page Table Entry 106 | union PTEntry 107 | { 108 | struct 109 | { 110 | uint64_t Present : 1; // 可用 111 | uint64_t ReadWrite : 1; // 可读写,否则只读 112 | uint64_t User : 1; // 用户模式可访问,否则需要特权 113 | uint64_t PWT : 1; 114 | uint64_t PCD : 1; // 页级禁用 Cache 115 | uint64_t Accessed : 1; // Accessed 116 | uint64_t Dirty : 1; 117 | uint64_t PAT : 1; 118 | uint64_t Global : 1; 119 | uint64_t Ignored_1 : 3; 120 | uint64_t PhysicAlignAddr : 39; 121 | uint64_t Reserved_0 : 2; 122 | uint64_t Ignored_0 : 10; 123 | uint64_t XD : 1; // 禁用执行 124 | }; 125 | uint64_t value; 126 | 127 | void* GetPhysicalAddress() const noexcept 128 | { 129 | return (void*)((PhysicAlignAddr << PHYSIC_ADDR_SHIFT) & PHYSIC_ADDR_MASK); 130 | } 131 | 132 | void SetPhysicalAddress(void* addr) noexcept 133 | { 134 | PhysicAlignAddr = (uint64_t(addr) & PHYSIC_ADDR_MASK) >> PHYSIC_ADDR_SHIFT; 135 | } 136 | }; 137 | 138 | static_assert(sizeof(PTEntry) == 8, "size of PTEntry must be 8."); 139 | 140 | typedef PTEntry PageTable[512]; 141 | 142 | #define PT_ADDR_MASK 0x7FFFFFFFFF000ui64 143 | #define PT_ADDR_SHIFT 12 144 | 145 | // Page Directory Entry 146 | union PDEntry 147 | { 148 | struct 149 | { 150 | uint64_t Present : 1; // 可用 151 | uint64_t ReadWrite : 1; // 可读写,否则只读 152 | uint64_t User : 1; // 用户模式可访问,否则需要特权 153 | uint64_t PWT : 1; 154 | uint64_t PCD : 1; // 页级禁用 Cache 155 | uint64_t Accessed : 1; // Accessed 156 | uint64_t Ignored_2 : 1; 157 | uint64_t PS : 1; 158 | uint64_t Ignored_1 : 4; 159 | uint64_t PTAlignAddr : 39; 160 | uint64_t Reserved_0 : 2; 161 | uint64_t Ignored_0 : 10; 162 | uint64_t XD : 1; // 禁用执行 163 | }; 164 | uint64_t value; 165 | 166 | PageTable& GetPageTableAddress() const noexcept 167 | { 168 | PTEntry* addr = (PTEntry*)((PTAlignAddr << PT_ADDR_SHIFT) & PT_ADDR_MASK); 169 | return reinterpret_cast(*addr); 170 | } 171 | 172 | void SetPageTableAddress(const PageTable& addr) noexcept 173 | { 174 | const PTEntry* value = addr; 175 | PTAlignAddr = (uint64_t(value) & PT_ADDR_MASK) >> PT_ADDR_SHIFT; 176 | } 177 | }; 178 | 179 | static_assert(sizeof(PDEntry) == 8, "size of PDEntry must be 8."); 180 | 181 | typedef PDEntry PageDirectory[512]; 182 | 183 | #define PD_ADDR_MASK 0x7FFFFFFFFF000ui64 184 | #define PD_ADDR_SHIFT 12 185 | 186 | // Page Directory Pointer Table Entry 187 | union PDPTEntry 188 | { 189 | struct 190 | { 191 | uint64_t Present : 1; // 可用 192 | uint64_t ReadWrite : 1; // 可读写,否则只读 193 | uint64_t User : 1; // 用户模式可访问,否则需要特权 194 | uint64_t PWT : 1; 195 | uint64_t PCD : 1; // 页级禁用 Cache 196 | uint64_t A : 1; // Accessed 197 | uint64_t Ignored_2 : 1; 198 | uint64_t PS : 1; 199 | uint64_t Ignored_1 : 4; 200 | uint64_t PDAlignAddr : 19; 201 | uint64_t Reserved_0 : 2; 202 | uint64_t Ignored_0 : 10; 203 | uint64_t XD : 1; // 禁用执行 204 | }; 205 | uint64_t value; 206 | 207 | PageDirectory& GetPageDirectoryAddress() const noexcept 208 | { 209 | PDEntry* addr = (PDEntry*)((PDAlignAddr << PD_ADDR_SHIFT) & PD_ADDR_MASK); 210 | return reinterpret_cast(*addr); 211 | } 212 | 213 | void SetPageDirectoryAddress(const PageDirectory& addr) noexcept 214 | { 215 | const PDEntry* value = addr; 216 | PDAlignAddr = (uint64_t(value) & PD_ADDR_MASK) >> PD_ADDR_SHIFT; 217 | } 218 | }; 219 | 220 | static_assert(sizeof(PDPTEntry) == 8, "size of PDPTEntry must be 8."); 221 | 222 | typedef PDPTEntry PDPTable[512]; 223 | 224 | #define PDPT_ADDR_MASK 0x7FFFFFFFFF000ui64 225 | #define PDPT_ADDR_SHIFT 12 226 | 227 | union PML4Entry 228 | { 229 | struct 230 | { 231 | uint64_t Present : 1; // 可用 232 | uint64_t ReadWrite : 1; // 可读写,否则只读 233 | uint64_t User : 1; // 用户模式可访问,否则需要特权 234 | uint64_t PWT : 1; 235 | uint64_t PCD : 1; // 页级禁用 Cache 236 | uint64_t A : 1; // Accessed 237 | uint64_t Ignored_2 : 1; 238 | uint64_t PS_Reserved : 1; 239 | uint64_t Ignored_1 : 4; 240 | uint64_t PDPTAlignAddr : 39; 241 | uint64_t Reserved_0 : 2; 242 | uint64_t Ignored_0 : 10; 243 | uint64_t XD : 1; // 禁用执行 244 | }; 245 | uint64_t value; 246 | 247 | PDPTable& GetPDPTableAddress() const noexcept 248 | { 249 | auto addr = (PDPTEntry*)((PDPTAlignAddr << PDPT_ADDR_SHIFT) & PDPT_ADDR_MASK); 250 | return reinterpret_cast(*addr); 251 | } 252 | 253 | void SetPDPTableAddress(const PDPTable& addr) noexcept 254 | { 255 | const PDPTEntry* value = addr; 256 | PDPTAlignAddr = (uint64_t(value) & PDPT_ADDR_MASK) >> PDPT_ADDR_SHIFT; 257 | } 258 | }; 259 | 260 | typedef PML4Entry PML4Table[512]; 261 | 262 | static_assert(sizeof(tagMSR_IA32_EFER) == 8, "size of tagMSR_IA32_EFER must be 8."); 263 | static_assert(sizeof(tagCR0) == 4, "size of tagCR0 must be 4."); 264 | static_assert(sizeof(tagCR4) == 8, "size of tagCR4 must be 8."); 265 | static_assert(sizeof(PML4Entry) == 8, "size of PML4Entry must be 8."); 266 | 267 | enum : uint64_t 268 | { 269 | PTEntryManageSize = 4 * 1024, // 4 KB 270 | PDEntryManageSize = 512 * PTEntryManageSize, // 2 MB 271 | PDPEntryManageSize = 512 * PDEntryManageSize, // 1 GB 272 | PML4EntryManageSize = 512 * PDPEntryManageSize, // 512 GB, 273 | PML4TableManageSize = 512 * PML4EntryManageSize // 256 TB 274 | }; 275 | 276 | #define CR3_PML4_MASK 0xFFFFFFFFFF000ui64 277 | 278 | inline void EnableIA32ePaging(const PML4Table& pml4Table) 279 | { 280 | const PML4Entry* addr = pml4Table; 281 | uint64_t cr3 = __readcr3(); 282 | cr3 &= ~CR3_PML4_MASK; 283 | cr3 |= ((uint64_t)addr) & CR3_PML4_MASK; 284 | // 将页表存入 cr3 285 | __writecr3(cr3); 286 | 287 | // 启用分页 288 | tagCR0 cr0 = __readcr0(); 289 | cr0.PG = 1; 290 | __writecr0(cr0.value); 291 | 292 | // 启用 PAE 293 | tagCR4 cr4 = __readcr4(); 294 | cr4.PAE = 1; 295 | __writecr4(cr4.value); 296 | 297 | // 启用 IA32e 分页 298 | tagMSR_IA32_EFER ia32Efer = __readmsr(MSR_IA32_EFER); 299 | ia32Efer.LME = 1; 300 | __writemsr(MSR_IA32_EFER, ia32Efer.value); 301 | } 302 | 303 | #endif 304 | #pragma pack(pop) 305 | } 306 | } -------------------------------------------------------------------------------- /Src/Tomato/System/TMTCRT/TMTCRT.Kernel/TMTCRT.Kernel.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {BDA96904-85BB-4F2A-BF7A-659F0D5ACD8D} 23 | Win32Proj 24 | TMTCRTKernel 25 | 8.1 26 | 27 | 28 | 29 | StaticLibrary 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | StaticLibrary 36 | true 37 | v140 38 | Unicode 39 | 40 | 41 | StaticLibrary 42 | false 43 | v140 44 | true 45 | Unicode 46 | 47 | 48 | StaticLibrary 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | $(SolutionDir)Build\$(Platform)\$(Configuration)\lib\ 75 | $(Platform)\$(Configuration)\ 76 | 77 | 78 | $(SolutionDir)Build\$(Platform)\$(Configuration)\lib\ 79 | $(Platform)\$(Configuration)\ 80 | 81 | 82 | $(SolutionDir)Build\$(Platform)\$(Configuration)\lib\ 83 | 84 | 85 | $(SolutionDir)Build\$(Platform)\$(Configuration)\lib\ 86 | 87 | 88 | 89 | Create 90 | Level3 91 | Disabled 92 | WIN32;CRT_KERNEL;_DEBUG;_LIB;%(PreprocessorDefinitions) 93 | false 94 | false 95 | Default 96 | false 97 | MultiThreadedDebug 98 | 99 | 100 | Windows 101 | true 102 | 103 | 104 | 105 | 106 | Create 107 | Level3 108 | Disabled 109 | WIN32;CRT_KERNEL;_DEBUG;_LIB;%(PreprocessorDefinitions) 110 | false 111 | false 112 | Default 113 | false 114 | MultiThreadedDebug 115 | 116 | 117 | Windows 118 | true 119 | 120 | 121 | 122 | 123 | Level3 124 | Create 125 | MaxSpeed 126 | true 127 | true 128 | WIN32;CRT_KERNEL;NDEBUG;_LIB;%(PreprocessorDefinitions) 129 | false 130 | false 131 | false 132 | MultiThreadedDebug 133 | 134 | 135 | Windows 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | Level3 144 | Create 145 | MaxSpeed 146 | true 147 | true 148 | WIN32;CRT_KERNEL;NDEBUG;_LIB;%(PreprocessorDefinitions) 149 | false 150 | false 151 | false 152 | MultiThreadedDebug 153 | 154 | 155 | Windows 156 | true 157 | true 158 | true 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /Src/Boot/Bootloader/Paging.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // Bootloader 分页 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-19 6 | #include "stdafx.h" 7 | #include "bootloader.h" 8 | 9 | using namespace Tomato::OS; 10 | 11 | static_assert(EFI_PAGE_SIZE == PTEntryManageSize, "EFI_PAGE_SIZE must be equal to PTEntryManageSize."); 12 | 13 | PML4Table* AllocatePML4Table(EFI_HANDLE ImageHandle) 14 | { 15 | // 512 项 PML4 Entry 映射 256 TB,每项 512 GB 16 | enum { 17 | PML4Size = sizeof(PML4Table), 18 | PML4PageCount = PML4Size / EFI_PAGE_SIZE 19 | }; 20 | PML4Table* pml4Addr; 21 | EXIT_IF_NOT_SUCCESS(gBS->AllocatePages(AllocateAnyPages, KernelPagingDataType, 22 | PML4PageCount, (EFI_PHYSICAL_ADDRESS*)&pml4Addr), ImageHandle, L"Cannot allocate PML4 Table.\r\n"); 23 | SetMem(pml4Addr, PML4Size, 0); 24 | return pml4Addr; 25 | } 26 | 27 | PDPTable* AllocatePDPTable(EFI_HANDLE ImageHandle) 28 | { 29 | // 512 项 Page Directory Pointer Entry 映射 512 GB,每项 1 GB 30 | enum { 31 | PDPSize = sizeof(PDPTable), 32 | PDPPageCount = PDPSize / EFI_PAGE_SIZE 33 | }; 34 | PDPTable* pdpAddr; 35 | EXIT_IF_NOT_SUCCESS(gBS->AllocatePages(AllocateAnyPages, KernelPagingDataType, 36 | PDPPageCount, (EFI_PHYSICAL_ADDRESS*)&pdpAddr), ImageHandle, L"Cannot allocate PDP Table.\r\n"); 37 | SetMem(pdpAddr, PDPSize, 0); 38 | return pdpAddr; 39 | } 40 | 41 | PageDirectory* AllocatePageDirectory(EFI_HANDLE ImageHandle) 42 | { 43 | // 512 项 Page Directory Entry 映射 1 GB,每项 2 MB 44 | enum { 45 | PDSize = sizeof(PageDirectory), 46 | PDPageCount = PDSize / EFI_PAGE_SIZE 47 | }; 48 | PageDirectory* pdAddr; 49 | EXIT_IF_NOT_SUCCESS(gBS->AllocatePages(AllocateAnyPages, KernelPagingDataType, 50 | PDPageCount, (EFI_PHYSICAL_ADDRESS*)&pdAddr), ImageHandle, L"Cannot allocate Page Directory.\r\n"); 51 | SetMem(pdAddr, PDSize, 0); 52 | return pdAddr; 53 | } 54 | 55 | PageTable* AllocatePageTable(EFI_HANDLE ImageHandle) 56 | { 57 | // 512 项 Page Table Entry 映射 2 MB,每项 4 KB 58 | enum { 59 | PTSize = sizeof(PageTable), 60 | PTPageCount = PTSize / EFI_PAGE_SIZE 61 | }; 62 | PageTable* ptAddr; 63 | EXIT_IF_NOT_SUCCESS(gBS->AllocatePages(AllocateAnyPages, KernelPagingDataType, 64 | PTPageCount, (EFI_PHYSICAL_ADDRESS*)&ptAddr), ImageHandle, L"Cannot allocate Page Table.\r\n"); 65 | SetMem(ptAddr, PTSize, 0); 66 | return ptAddr; 67 | } 68 | 69 | // 映射前 1 GB 70 | // 实际映射物理内存的 64 MB 71 | void MappingLow1GB(EFI_HANDLE ImageHandle, PDPTable& pdpTable) 72 | { 73 | enum : uint64_t { 74 | PML4EIndex = uint64_t(64 * 1024 * 1024) / PML4EntryManageSize, 75 | PML4ERest = uint64_t(64 * 1024 * 1024) % PML4EntryManageSize, 76 | PDPEIndex = PML4ERest / PDPEntryManageSize, 77 | PDPERest = PML4ERest % PDPEntryManageSize, 78 | PDEIndex = 0, 79 | PDEEndIndex = PDPERest / PDEntryManageSize 80 | }; 81 | 82 | auto& pageDir = *AllocatePageDirectory(ImageHandle); 83 | auto& pageDirRef = pdpTable[PDPEIndex]; 84 | pageDirRef.Present = TRUE; 85 | pageDirRef.ReadWrite = TRUE; 86 | pageDirRef.SetPageDirectoryAddress(pageDir); 87 | 88 | uint8_t* physicalAddr = 0; 89 | for (size_t i = 0; i < PDEEndIndex; i++) 90 | { 91 | auto& pageDirEntry = pageDir[i]; 92 | auto& pageTable = *AllocatePageTable(ImageHandle); 93 | 94 | for (auto& ptEntry : pageTable) 95 | { 96 | ptEntry.Present = TRUE; 97 | ptEntry.ReadWrite = TRUE; 98 | ptEntry.SetPhysicalAddress(physicalAddr); 99 | 100 | physicalAddr += PTEntryManageSize; 101 | } 102 | pageDirEntry.Present = TRUE; 103 | pageDirEntry.ReadWrite = TRUE; 104 | pageDirEntry.SetPageTableAddress(pageTable); 105 | } 106 | } 107 | 108 | void MappingKernelAddress(EFI_HANDLE ImageHandle, EFI_PHYSICAL_ADDRESS kernelMemBuffer, 109 | EFI_IMAGE_SECTION_HEADER* section, UINTN sectionCount, PDPTable& pdpTable) 110 | { 111 | enum : uint64_t { 112 | KernelPML4EIndex = KernelImageBase / PML4EntryManageSize, 113 | KernelPML4ERest = KernelImageBase % PML4EntryManageSize, 114 | KernelPDPEIndex = KernelPML4ERest / PDPEntryManageSize, 115 | KernelPDPERest = KernelPML4ERest % PDPEntryManageSize, 116 | KernelPDEIndex = KernelPDPERest / PDEntryManageSize, 117 | KernelPDERest = KernelPDPERest % PDEntryManageSize, 118 | KernelPTEIndex = KernelPDERest / PTEntryManageSize, 119 | KernelPTERest = KernelPDERest % PTEntryManageSize 120 | }; 121 | 122 | auto& kernelPageDir = *AllocatePageDirectory(ImageHandle); 123 | auto& kernelPageDirRef = pdpTable[KernelPDPEIndex]; 124 | kernelPageDirRef.Present = TRUE; 125 | kernelPageDirRef.ReadWrite = TRUE; 126 | kernelPageDirRef.SetPageDirectoryAddress(kernelPageDir); 127 | 128 | uint8_t* physicalAddr = (uint8_t*)kernelMemBuffer; 129 | for (size_t i = 0; i < sectionCount; i++) 130 | { 131 | auto& curSection = section[i]; 132 | if (curSection.SizeOfRawData) 133 | { 134 | auto dataSize = AlignSize(curSection.Misc.VirtualSize, EFI_PAGE_SIZE); 135 | 136 | // 起始 Page Table Index 137 | auto curPTIndex = curSection.VirtualAddress / PDEntryManageSize; 138 | auto restToMap = dataSize; 139 | uint8_t* startVirtualAddress = (uint8_t*)(KernelPDPEIndex * PDPEntryManageSize + 140 | curPTIndex * PDEntryManageSize); 141 | 142 | for (; restToMap; curPTIndex++) 143 | { 144 | auto& pageTableRef = kernelPageDir[curPTIndex]; 145 | // 如果未分配则分配页表 146 | if (!pageTableRef.Present) 147 | { 148 | pageTableRef.SetPageTableAddress(*AllocatePageTable(ImageHandle)); 149 | pageTableRef.Present = TRUE; 150 | pageTableRef.ReadWrite = TRUE; 151 | } 152 | PageTable& pageTable = pageTableRef.GetPageTableAddress(); 153 | auto curPEIndex = (curSection.VirtualAddress % PDEntryManageSize) 154 | / PTEntryManageSize; 155 | auto curVirtualAddress = startVirtualAddress + curPEIndex * PTEntryManageSize; 156 | 157 | 158 | MPrint(L"P: %lX, V: %lX\n", physicalAddr, curVirtualAddress); 159 | for (size_t j = curPEIndex; j < sizeof(pageTable) / sizeof(pageTable[0]); j++) 160 | { 161 | auto& ptEntry = pageTable[j]; 162 | ptEntry.SetPhysicalAddress(physicalAddr); 163 | ptEntry.Present = TRUE; 164 | ptEntry.ReadWrite = TRUE; 165 | 166 | physicalAddr += EFI_PAGE_SIZE; 167 | curVirtualAddress += PTEntryManageSize; 168 | restToMap -= PTEntryManageSize; 169 | if (!restToMap)break; 170 | } 171 | } 172 | } 173 | } 174 | } 175 | 176 | void Bootloader::MappingFrameBuffer(PDPTable& pdpTable) 177 | { 178 | auto frameBufferBase = gop->Mode->FrameBufferBase; 179 | auto PML4EIndex = frameBufferBase / PML4EntryManageSize; 180 | auto PML4ERest = frameBufferBase % PML4EntryManageSize; 181 | auto PDPEIndex = PML4ERest / PDPEntryManageSize; 182 | auto PDPERest = PML4ERest % PDPEntryManageSize; 183 | auto PDEIndex = PDPERest / PDEntryManageSize; 184 | auto PDERest = PDPERest % PDEntryManageSize; 185 | auto PTEIndex = PDERest / PTEntryManageSize; 186 | auto PTERest = PDERest % PTEntryManageSize; 187 | auto restToMap = AlignSize(PTERest + gop->Mode->FrameBufferSize, PTEntryManageSize); 188 | 189 | uint8_t* physicalAddr = (uint8_t*)frameBufferBase - PTERest; 190 | for (size_t i = PDPEIndex; restToMap; i++) 191 | { 192 | auto& pageDirRef = pdpTable[i]; 193 | // 不存在页目录则分配 194 | if (!pageDirRef.Present) 195 | { 196 | pageDirRef.SetPageDirectoryAddress(*AllocatePageDirectory(imageHandle)); 197 | pageDirRef.Present = TRUE; 198 | pageDirRef.ReadWrite = TRUE; 199 | } 200 | auto& pageDir = pageDirRef.GetPageDirectoryAddress(); 201 | for (size_t j = PDEIndex; j < 512 && restToMap; j++) 202 | { 203 | auto& pageTableRef = pageDir[j]; 204 | // 不存在页表则分配 205 | if (!pageTableRef.Present) 206 | { 207 | auto ptr = AllocatePageTable(imageHandle); 208 | pageTableRef.SetPageTableAddress(*ptr); 209 | pageTableRef.Present = TRUE; 210 | pageTableRef.ReadWrite = TRUE; 211 | } 212 | auto& pageTable = pageTableRef.GetPageTableAddress(); 213 | for (size_t k = PTEIndex; k < 512 && restToMap; k++) 214 | { 215 | auto& ptEntry = pageTable[k]; 216 | ptEntry.SetPhysicalAddress(physicalAddr); 217 | ptEntry.Present = TRUE; 218 | ptEntry.PCD = TRUE; 219 | ptEntry.ReadWrite = TRUE; 220 | 221 | physicalAddr += EFI_PAGE_SIZE; 222 | restToMap -= PTEntryManageSize; 223 | } 224 | PTEIndex = 0; 225 | } 226 | PDEIndex = 0; 227 | } 228 | } 229 | 230 | // 启用分页 231 | void Bootloader::EnablePaging() 232 | { 233 | EnableIA32ePaging(*pml4Table); 234 | } 235 | 236 | void Bootloader::PreparePaging() 237 | { 238 | // 分配 PML4Table 239 | auto& pml4Table = *AllocatePML4Table(imageHandle); 240 | // 分配 PDPTable 241 | auto& pdpTable = *AllocatePDPTable(imageHandle); 242 | // 映射前 1 GB 243 | MappingLow1GB(imageHandle, pdpTable); 244 | // 映射视频缓冲 245 | MappingFrameBuffer(pdpTable); 246 | // 映射内核所在的 1 GB 247 | MappingKernelAddress(imageHandle, kernelMemBuffer, sectionStart, sectionCount, pdpTable); 248 | 249 | // 映射前 512 GB 250 | auto& pdpTableRef = pml4Table[0]; 251 | pdpTableRef.SetPDPTableAddress(pdpTable); 252 | pdpTableRef.Present = TRUE; 253 | pdpTableRef.ReadWrite = TRUE; 254 | 255 | this->pml4Table = &pml4Table; 256 | } -------------------------------------------------------------------------------- /Src/Boot/Bootloader/Bootloader.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Tomato OS 3 | // Bootloader 4 | // (c) 2015 SunnyCase 5 | // 创建日期:2015-4-18 6 | #include "stdafx.h" 7 | #include "bootloader.h" 8 | 9 | static const wchar_t KernelFilePath[] = LR"(Tomato\System\OSKernel.exe)"; 10 | 11 | EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) 12 | { 13 | Bootloader loader(ImageHandle); 14 | loader.Boot(); 15 | 16 | return EFI_SUCCESS; 17 | } 18 | 19 | KernelFile::KernelFile(KernelFile && file) 20 | :imageHandle(file.imageHandle), kernelFileBuffer(file.kernelFileBuffer) 21 | { 22 | file.kernelFileBuffer = nullptr; 23 | } 24 | 25 | KernelFile::~KernelFile() 26 | { 27 | if (kernelFileBuffer) 28 | FreePool(kernelFileBuffer); 29 | } 30 | 31 | void KernelFile::LoadKernelFile() 32 | { 33 | EFI_LOADED_IMAGE* loadedImage; 34 | EFI_FILE_IO_INTERFACE* volume; 35 | // 获取 Loader 所在的卷 36 | gBS->HandleProtocol(imageHandle, &gEfiLoadedImageProtocolGuid, (void**)&loadedImage); 37 | gBS->HandleProtocol(loadedImage->DeviceHandle, &gEfiSimpleFileSystemProtocolGuid, (void**)&volume); 38 | 39 | EFI_FILE_HANDLE rootFS, fileHandle; 40 | volume->OpenVolume(volume, &rootFS); 41 | // 读取文件 42 | EXIT_IF_NOT_SUCCESS(rootFS->Open(rootFS, &fileHandle, (CHAR16*)KernelFilePath, EFI_FILE_MODE_READ, 0), 43 | imageHandle, L"Cannot Open Tomato Kernel File.\r\n"); 44 | 45 | UINT8* kernelBuffer = (UINT8*)AllocatePool(KernelPoolSize); 46 | EXIT_IF_NOT_SUCCESS(fileHandle->Read(fileHandle, &KernelPoolSize, kernelBuffer), 47 | imageHandle, L"Cannot Read Tomato Kernel File.\r\n"); 48 | fileHandle->Close(fileHandle); 49 | 50 | kernelFileBuffer = kernelBuffer; 51 | } 52 | 53 | KernelEntryPoint KernelFile::GetEntryPoint() 54 | { 55 | auto dosHeader = (EFI_IMAGE_DOS_HEADER*)kernelFileBuffer; 56 | auto* ntHeaders = (EFI_IMAGE_NT_HEADERS64*)(kernelFileBuffer + dosHeader->e_lfanew); 57 | return (KernelEntryPoint)(ntHeaders->OptionalHeader.ImageBase + 58 | ntHeaders->OptionalHeader.AddressOfEntryPoint); 59 | } 60 | 61 | static wchar_t *OsLoaderMemoryTypeDesc[EfiMaxMemoryType] = { 62 | L"reserved ", 63 | L"LoaderCode", 64 | L"LoaderData", 65 | L"BS_code ", 66 | L"BS_data ", 67 | L"RT_code ", 68 | L"RT_data ", 69 | L"available ", 70 | L"Unusable ", 71 | L"ACPI_recl ", 72 | L"ACPI_NVS ", 73 | L"MemMapIO ", 74 | L"MemPortIO ", 75 | L"PAL_code " 76 | }; 77 | 78 | void Bootloader::Boot() 79 | { 80 | MPrint(L"Loading Tomato OS...\r\n"); 81 | 82 | SetGraphicsMode(); 83 | KernelEntryPoint entryPoint; 84 | { 85 | auto file = LoadKernel(); 86 | entryPoint = file.GetEntryPoint(); 87 | PrepareKernel(file); 88 | } 89 | PreparePaging(); 90 | InitializeKernelEntryParams(); 91 | PrepareVirtualMemoryMapping(); 92 | EnablePaging(); 93 | 94 | RunKernel(entryPoint); 95 | } 96 | 97 | EFI_MEMORY_DESCRIPTOR* GetMemoryMap(UINTN& entries, UINTN& mapKey, UINTN& descriptorSize, UINT32& descriptorVersion) 98 | { 99 | UINTN totalSize = 0; 100 | EFI_MEMORY_DESCRIPTOR* descriptor; 101 | gBS->GetMemoryMap(&totalSize, nullptr, &mapKey, &descriptorSize, &descriptorVersion); 102 | descriptor = (EFI_MEMORY_DESCRIPTOR*)AllocatePool(totalSize); 103 | gBS->GetMemoryMap(&totalSize, descriptor, &mapKey, &descriptorSize, &descriptorVersion); 104 | entries = totalSize / descriptorSize; 105 | return descriptor; 106 | } 107 | 108 | void Bootloader::PrintMemoryMap() 109 | { 110 | UINTN entries, mapKey, descriptorSize; 111 | UINT32 descriptorVersion; 112 | 113 | EFI_MEMORY_DESCRIPTOR* descriptor = GetMemoryMap(entries, mapKey, descriptorSize, descriptorVersion); 114 | 115 | MPrint(L" Type Start Address End Address Virtual Address \n"); 116 | MPrint(L" ========== ================ ================ ================\n"); 117 | EFI_MEMORY_DESCRIPTOR* MemoryMapEntry = descriptor; 118 | for (UINTN i = 0; i < entries; i++) { 119 | MPrint(L" %s %lX %lX %lX\n", 120 | MemoryMapEntry->Type == KernelPoolType ? L"KernelPool" : MemoryMapEntry->Type == KernelPagingDataType ? L"KernelPage" : OsLoaderMemoryTypeDesc[MemoryMapEntry->Type], 121 | MemoryMapEntry->PhysicalStart, 122 | MemoryMapEntry->PhysicalStart + LShiftU64(MemoryMapEntry->NumberOfPages, EFI_PAGE_SHIFT) - 1, 123 | MemoryMapEntry->VirtualStart); 124 | MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR(MemoryMapEntry, descriptorSize); 125 | } 126 | FreePool(descriptor); 127 | } 128 | 129 | bool KernelFile::ValidateKernel() 130 | { 131 | auto* dosHeader = (EFI_IMAGE_DOS_HEADER*)kernelFileBuffer; 132 | if (dosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) 133 | return FALSE; 134 | auto* ntHeaders = (EFI_IMAGE_NT_HEADERS64*)(kernelFileBuffer + dosHeader->e_lfanew); 135 | if (ntHeaders->Signature != EFI_IMAGE_NT_SIGNATURE) 136 | return FALSE; 137 | return TRUE; 138 | } 139 | 140 | KernelFile Bootloader::LoadKernel() 141 | { 142 | KernelFile file(imageHandle); 143 | 144 | file.LoadKernelFile(); 145 | return file; 146 | } 147 | 148 | void Bootloader::RunKernel(KernelEntryPoint entryPoint) 149 | { 150 | entryPoint(params); 151 | } 152 | 153 | enum 154 | { 155 | DESIRED_HREZ = 800, 156 | DESIRED_VREZ = 600, 157 | DESIRED_PIXEL_FORMAT = EFI_GRAPHICS_PIXEL_FORMAT::PixelBlueGreenRedReserved8BitPerColor 158 | }; 159 | 160 | void Bootloader::InitializeKernelEntryParams() 161 | { 162 | /*EfiGetSystemConfigurationTable(&, (void**)¶ms.AcpiTable); 163 | EfiGetSystemConfigurationTable(&SMBIOSTableGuid, (void**)¶ms.SmbiosTable);*/ 164 | params.RT = gRT; 165 | params.FrameBufferBase = gop->Mode->FrameBufferBase; 166 | params.FrameWidth = DESIRED_HREZ; 167 | params.FrameHeight = DESIRED_VREZ; 168 | params.FrameBufferSize = gop->Mode->FrameBufferSize; 169 | } 170 | 171 | UINTN GetAllSectionsMemoryPages(EFI_IMAGE_SECTION_HEADER* first, UINTN count) 172 | { 173 | UINTN size = 0; 174 | for (UINTN i = 0; i < count; i++, first++) 175 | size += AlignSize(first->Misc.VirtualSize, EFI_PAGE_SIZE); 176 | return size / EFI_PAGE_SIZE; 177 | } 178 | 179 | void Bootloader::PrepareVirtualMemoryMapping() 180 | { 181 | UINTN entries, mapKey, descriptorSize; 182 | UINT32 descriptorVersion; 183 | 184 | EFI_MEMORY_DESCRIPTOR* descriptor = GetMemoryMap(entries, mapKey, descriptorSize, descriptorVersion); 185 | gBS->ExitBootServices(imageHandle, mapKey); 186 | 187 | EFI_MEMORY_DESCRIPTOR* memoryMapEntry = descriptor; 188 | for (UINTN i = 0; i < entries; i++) 189 | { 190 | if (memoryMapEntry->Attribute & EFI_MEMORY_RUNTIME) 191 | { 192 | memoryMapEntry->VirtualStart = memoryMapEntry->PhysicalStart; 193 | } 194 | memoryMapEntry = NEXT_MEMORY_DESCRIPTOR(memoryMapEntry, descriptorSize); 195 | } 196 | 197 | EFI_STATUS status = gRT->SetVirtualAddressMap(entries * descriptorSize, descriptorSize, 198 | EFI_MEMORY_DESCRIPTOR_VERSION, descriptor); 199 | if (EFI_ERROR(status)) 200 | gRT->ResetSystem(EfiResetWarm, EFI_LOAD_ERROR, 62, (CHAR16*)L"Setting Memory mapping failed."); 201 | 202 | params.MemoryDescriptor = descriptor; 203 | params.MemoryDescriptorSize = descriptorSize; 204 | params.MemoryDescriptorEntryCount = entries; 205 | } 206 | 207 | void Bootloader::SetGraphicsMode() 208 | { 209 | EFI_HANDLE* handleBuffer; 210 | UINTN handleCount = 0; 211 | UINTN sizeOfInfo; 212 | EFI_GRAPHICS_OUTPUT_MODE_INFORMATION* gopModeInfo; 213 | gBS->LocateHandleBuffer(ByProtocol, &gEfiGraphicsOutputProtocolGuid, nullptr, &handleCount, &handleBuffer); 214 | gBS->HandleProtocol(handleBuffer[0], &gEfiGraphicsOutputProtocolGuid, (void**)&gop); 215 | 216 | size_t modeIndex = 0; 217 | for (;; modeIndex++) { 218 | gop->QueryMode(gop, modeIndex, &sizeOfInfo, &gopModeInfo); 219 | if (gopModeInfo->HorizontalResolution == DESIRED_HREZ && 220 | gopModeInfo->VerticalResolution == DESIRED_VREZ && 221 | gopModeInfo->PixelFormat == DESIRED_PIXEL_FORMAT) 222 | break; 223 | } 224 | gop->SetMode(gop, modeIndex); 225 | 226 | MPrint(L"Change Graphics Mode: %dx%d\n", DESIRED_HREZ, DESIRED_VREZ); 227 | } 228 | 229 | void Bootloader::PrepareKernel(KernelFile& file) 230 | { 231 | if (file.ValidateKernel()) 232 | { 233 | auto kernelImageBase = file.GetKernelFileBuffer(); 234 | auto* dosHeader = (EFI_IMAGE_DOS_HEADER*)kernelImageBase; 235 | auto ntHeaders = (EFI_IMAGE_NT_HEADERS64*)(kernelImageBase + dosHeader->e_lfanew); 236 | 237 | sectionStart = (EFI_IMAGE_SECTION_HEADER*)(((UINT8*)ntHeaders) + sizeof(EFI_IMAGE_NT_HEADERS64) 238 | - sizeof(EFI_IMAGE_OPTIONAL_HEADER64) + ntHeaders->FileHeader.SizeOfOptionalHeader); 239 | sectionCount = ntHeaders->FileHeader.NumberOfSections; 240 | UINTN sectionAlign = ntHeaders->OptionalHeader.SectionAlignment; 241 | UINTN fileAlign = ntHeaders->OptionalHeader.FileAlignment; 242 | 243 | UINTN memAllocPages = GetAllSectionsMemoryPages(sectionStart, sectionCount); 244 | EXIT_IF_NOT_SUCCESS(gBS->AllocatePages(AllocateAnyPages, KernelPoolType, memAllocPages, 245 | &kernelMemBuffer), imageHandle, L"Cannot allocate Kernel Memory.\r\n"); 246 | 247 | EFI_IMAGE_SECTION_HEADER* section = sectionStart; 248 | UINT8* memBuffer = (UINT8*)kernelMemBuffer; 249 | MPrint(L" Name Virtual Address Raw Address Raw Size Mem Size\n"); 250 | for (UINTN i = 0; i < sectionCount; i++, section++) 251 | { 252 | BOOLEAN dataInFile = section->PointerToRawData != 0; 253 | UINT8* sectionData = kernelImageBase + section->PointerToRawData; 254 | UINTN memAllocSize = AlignSize(section->Misc.VirtualSize, EFI_PAGE_SIZE); 255 | 256 | if (memAllocSize) 257 | { 258 | if (dataInFile) 259 | CopyMem(memBuffer, sectionData, section->SizeOfRawData); 260 | memBuffer += memAllocSize; 261 | } 262 | MPrint(L" "); 263 | AsciiPrint((CHAR8*)section->Name); 264 | MPrint(L" %lX %lX %lX %lX\r\n", section->VirtualAddress, section->PointerToRawData, 265 | section->SizeOfRawData, memAllocSize); 266 | } 267 | } 268 | else 269 | EXIT_IF_NOT_SUCCESS(EFI_LOAD_ERROR, imageHandle, L"Invalid Tomato Kernel Image.\r\n"); 270 | } -------------------------------------------------------------------------------- /Src/Tomato/System/BootVideo/BootVideo.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {1E5A446D-7442-4D55-8F1E-EE51522B0FEB} 23 | Win32Proj 24 | BootVideo 25 | 8.1 26 | 27 | 28 | 29 | StaticLibrary 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | StaticLibrary 36 | true 37 | v140 38 | Unicode 39 | 40 | 41 | StaticLibrary 42 | false 43 | v140 44 | true 45 | Unicode 46 | 47 | 48 | StaticLibrary 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | $(SolutionDir)Build\$(Platform)\$(Configuration)\Tomato\System\ 74 | $(Platform)\$(Configuration)\ 75 | 76 | 77 | $(SolutionDir)Build\$(Platform)\$(Configuration)\Tomato\System\ 78 | $(Platform)\$(Configuration)\ 79 | 80 | 81 | $(SolutionDir)Build\$(Platform)\$(Configuration)\Tomato\System\ 82 | 83 | 84 | $(SolutionDir)Build\$(Platform)\$(Configuration)\Tomato\System\ 85 | 86 | 87 | 88 | Use 89 | Level3 90 | Disabled 91 | _DEBUG;_LIB;%(PreprocessorDefinitions) 92 | false 93 | Default 94 | false 95 | false 96 | MultiThreadedDebug 97 | 98 | 99 | Windows 100 | true 101 | 102 | 103 | true 104 | 105 | 106 | 107 | 108 | Use 109 | Level3 110 | Disabled 111 | _DEBUG;_LIB;%(PreprocessorDefinitions) 112 | false 113 | Default 114 | false 115 | AssemblyAndSourceCode 116 | false 117 | MultiThreadedDebug 118 | 119 | 120 | Windows 121 | true 122 | 123 | 124 | true 125 | 126 | 127 | 128 | 129 | Level3 130 | Use 131 | MaxSpeed 132 | true 133 | true 134 | NDEBUG;_LIB;%(PreprocessorDefinitions) 135 | false 136 | false 137 | false 138 | MultiThreadedDebug 139 | 140 | 141 | Windows 142 | true 143 | true 144 | true 145 | 146 | 147 | true 148 | 149 | 150 | 151 | 152 | Level3 153 | Use 154 | MaxSpeed 155 | true 156 | true 157 | NDEBUG;_LIB;%(PreprocessorDefinitions) 158 | false 159 | false 160 | false 161 | MultiThreadedDebug 162 | 163 | 164 | Windows 165 | true 166 | true 167 | true 168 | 169 | 170 | true 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | Create 188 | Create 189 | Create 190 | Create 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /Src/Boot/Bootloader/Bootloader.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {28B7C1E8-BD49-48E7-AC26-C5AE7A8ADAE2} 23 | Win32Proj 24 | Bootloader 25 | 8.1 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | Application 36 | true 37 | v140 38 | Unicode 39 | 40 | 41 | Application 42 | false 43 | v140 44 | true 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | D:\Software\Development\SDKs\UDK2014\MdePkg\Include;D:\Software\Development\SDKs\UDK2014\MdePkg\Include\X64;$(IncludePath) 75 | $(SolutionDir)Build\$(Platform)\$(Configuration)\EFI\Boot\ 76 | $(Platform)\$(Configuration)\ 77 | bootx64 78 | .efi 79 | D:\Software\Development\SDKs\UDK2014\Build\NT32X64\DEBUG_VS2013\X64\MdePkg;$(LibraryPath) 80 | 81 | 82 | true 83 | D:\Software\Development\SDKs\UDK2014\MdePkg\Include;D:\Software\Development\SDKs\UDK2014\MdePkg\Include\X64;$(IncludePath) 84 | $(SolutionDir)Build\$(Platform)\$(Configuration)\EFI\Boot\ 85 | bootx64 86 | .efi 87 | D:\Software\Development\SDKs\UDK2014\Build\NT32X64\DEBUG_VS2013\X64\MdePkg;$(LibraryPath) 88 | 89 | 90 | false 91 | D:\Software\Development\SDKs\UDK2014\MdePkg\Include;D:\Software\Development\SDKs\UDK2014\MdePkg\Include\X64;$(IncludePath) 92 | $(SolutionDir)Build\$(Platform)\$(Configuration)\EFI\Boot\ 93 | $(Platform)\$(Configuration)\ 94 | bootx64 95 | .efi 96 | D:\Software\Development\SDKs\UDK2014\Build\NT32X64\DEBUG_VS2013\X64\MdePkg;$(LibraryPath) 97 | 98 | 99 | false 100 | D:\Software\Development\SDKs\UDK2014\MdePkg\Include;D:\Software\Development\SDKs\UDK2014\MdePkg\Include\X64;$(IncludePath) 101 | $(SolutionDir)Build\$(Platform)\$(Configuration)\EFI\Boot\ 102 | bootx64 103 | .efi 104 | D:\Software\Development\SDKs\UDK2014\Build\NT32X64\DEBUG_VS2013\X64\MdePkg;$(LibraryPath) 105 | 106 | 107 | 108 | Create 109 | Level3 110 | Disabled 111 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 112 | false 113 | false 114 | AssemblyAndSourceCode 115 | Default 116 | Default 117 | true 118 | 119 | 120 | EFI Application 121 | true 122 | Library\UefiLib\UefiLib\OUTPUT\UEfiLib.lib;Library\BaseLib\BaseLib\OUTPUT\BaseLib.lib;Library\UefiBootServicesTableLib\UefiBootServicesTableLib\OUTPUT\UefiBootServicesTableLib.lib;Library\UefiRuntimeServicesTableLib\UefiRuntimeServicesTableLib\OUTPUT\UefiRuntimeServicesTableLib.lib;Library\UefiRuntimeLib\UefiRuntimeLib\OUTPUT\UefiRuntimeLib.lib;Library\UefiMemoryAllocationLib\UefiMemoryAllocationLib\OUTPUT\UefiMemoryAllocationLib.lib;Library\BasePrintLib\BasePrintLib\OUTPUT\BasePrintLib.lib;Library\BaseMemoryLibOptPei\BaseMemoryLibOptPei\OUTPUT\BaseMemoryLibOptPei.lib;Library\BaseDebugLibNull\BaseDebugLibNull\OUTPUT\BaseDebugLibNull.lib 123 | true 124 | UefiMain 125 | false 126 | false 127 | false 128 | 129 | 130 | 131 | 132 | Create 133 | Level3 134 | Disabled 135 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 136 | false 137 | false 138 | AssemblyAndSourceCode 139 | Default 140 | Default 141 | true 142 | 143 | 144 | EFI Application 145 | true 146 | Library\UefiLib\UefiLib\OUTPUT\UEfiLib.lib;Library\BaseLib\BaseLib\OUTPUT\BaseLib.lib;Library\UefiBootServicesTableLib\UefiBootServicesTableLib\OUTPUT\UefiBootServicesTableLib.lib;Library\UefiRuntimeServicesTableLib\UefiRuntimeServicesTableLib\OUTPUT\UefiRuntimeServicesTableLib.lib;Library\UefiRuntimeLib\UefiRuntimeLib\OUTPUT\UefiRuntimeLib.lib;Library\UefiMemoryAllocationLib\UefiMemoryAllocationLib\OUTPUT\UefiMemoryAllocationLib.lib;Library\BasePrintLib\BasePrintLib\OUTPUT\BasePrintLib.lib;Library\BaseMemoryLibOptPei\BaseMemoryLibOptPei\OUTPUT\BaseMemoryLibOptPei.lib;Library\BaseDebugLibNull\BaseDebugLibNull\OUTPUT\BaseDebugLibNull.lib 147 | true 148 | UefiMain 149 | false 150 | false 151 | false 152 | 153 | 154 | 155 | 156 | Level3 157 | Create 158 | MaxSpeed 159 | true 160 | true 161 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 162 | false 163 | false 164 | AssemblyAndSourceCode 165 | Default 166 | true 167 | 168 | 169 | EFI Application 170 | No 171 | true 172 | true 173 | Library\UefiLib\UefiLib\OUTPUT\UEfiLib.lib;Library\BaseLib\BaseLib\OUTPUT\BaseLib.lib;Library\UefiBootServicesTableLib\UefiBootServicesTableLib\OUTPUT\UefiBootServicesTableLib.lib;Library\UefiRuntimeServicesTableLib\UefiRuntimeServicesTableLib\OUTPUT\UefiRuntimeServicesTableLib.lib;Library\UefiRuntimeLib\UefiRuntimeLib\OUTPUT\UefiRuntimeLib.lib;Library\UefiMemoryAllocationLib\UefiMemoryAllocationLib\OUTPUT\UefiMemoryAllocationLib.lib;Library\BasePrintLib\BasePrintLib\OUTPUT\BasePrintLib.lib;Library\BaseMemoryLibOptPei\BaseMemoryLibOptPei\OUTPUT\BaseMemoryLibOptPei.lib;Library\BaseDebugLibNull\BaseDebugLibNull\OUTPUT\BaseDebugLibNull.lib 174 | true 175 | UefiMain 176 | false 177 | false 178 | false 179 | 180 | 181 | 182 | 183 | Level3 184 | Create 185 | MaxSpeed 186 | true 187 | true 188 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 189 | false 190 | false 191 | AssemblyAndSourceCode 192 | Default 193 | true 194 | 195 | 196 | EFI Application 197 | No 198 | true 199 | true 200 | Library\UefiLib\UefiLib\OUTPUT\UEfiLib.lib;Library\BaseLib\BaseLib\OUTPUT\BaseLib.lib;Library\UefiBootServicesTableLib\UefiBootServicesTableLib\OUTPUT\UefiBootServicesTableLib.lib;Library\UefiRuntimeServicesTableLib\UefiRuntimeServicesTableLib\OUTPUT\UefiRuntimeServicesTableLib.lib;Library\UefiRuntimeLib\UefiRuntimeLib\OUTPUT\UefiRuntimeLib.lib;Library\UefiMemoryAllocationLib\UefiMemoryAllocationLib\OUTPUT\UefiMemoryAllocationLib.lib;Library\BasePrintLib\BasePrintLib\OUTPUT\BasePrintLib.lib;Library\BaseMemoryLibOptPei\BaseMemoryLibOptPei\OUTPUT\BaseMemoryLibOptPei.lib;Library\BaseDebugLibNull\BaseDebugLibNull\OUTPUT\BaseDebugLibNull.lib 201 | true 202 | UefiMain 203 | false 204 | false 205 | false 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | -------------------------------------------------------------------------------- /Src/Tomato/System/OSKernel/OSKernel.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {04FC833C-8561-487F-8A2F-BD5A26D3DF8A} 23 | Win32Proj 24 | OSKernel 25 | 8.1 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | Application 36 | true 37 | v140 38 | Unicode 39 | 40 | 41 | Application 42 | false 43 | v140 44 | true 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | $(SolutionDir)Build\$(Platform)\$(Configuration)\Tomato\System\ 75 | $(Platform)\$(Configuration)\ 76 | D:\Software\Development\SDKs\EFI_Toolkit_2.0\include\efi;D:\Software\Development\SDKs\EFI_Toolkit_2.0\include\efi\em64t;$(VC_IncludePath);$(UniversalCRT_IncludePath);$(WindowsSDK_IncludePath); 77 | 78 | 79 | true 80 | $(SolutionDir)Build\$(Platform)\$(Configuration)\Tomato\System\ 81 | D:\Software\Development\SDKs\UDK2014\MdePkg\Include;D:\Software\Development\SDKs\UDK2014\MdePkg\Include\X64;$(VC_IncludePath);$(UniversalCRT_IncludePath);$(WindowsSDK_IncludePath); 82 | 83 | 84 | false 85 | $(SolutionDir)Build\$(Platform)\$(Configuration)\Tomato\System\ 86 | $(Platform)\$(Configuration)\ 87 | D:\Software\Development\SDKs\EFI_Toolkit_2.0\include\efi;D:\Software\Development\SDKs\EFI_Toolkit_2.0\include\efi\em64t;$(VC_IncludePath);$(UniversalCRT_IncludePath);$(WindowsSDK_IncludePath); 88 | 89 | 90 | false 91 | $(SolutionDir)Build\$(Platform)\$(Configuration)\Tomato\System\ 92 | D:\Software\Development\SDKs\EFI_Toolkit_2.0\include\efi;D:\Software\Development\SDKs\EFI_Toolkit_2.0\include\efi\em64t;$(VC_IncludePath);$(UniversalCRT_IncludePath);$(WindowsSDK_IncludePath); 93 | 94 | 95 | 96 | Use 97 | Level3 98 | Disabled 99 | CRT_KERNEL;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 100 | false 101 | Default 102 | false 103 | AssemblyAndSourceCode 104 | false 105 | MultiThreadedDebug 106 | 107 | 108 | Native 109 | true 110 | KernelMain 111 | true 112 | 113 | false 114 | false 115 | 0x140000000 116 | .pdata=.rdata 117 | 118 | 119 | 120 | 121 | Use 122 | Level3 123 | Disabled 124 | CRT_KERNEL;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 125 | false 126 | Default 127 | false 128 | AssemblyAndSourceCode 129 | false 130 | MultiThreadedDebug 131 | 132 | 133 | Native 134 | true 135 | KernelMain 136 | true 137 | 138 | false 139 | false 140 | 0x140000000 141 | .pdata=.rdata 142 | 143 | 144 | 145 | 146 | Level3 147 | Use 148 | MaxSpeed 149 | true 150 | true 151 | CRT_KERNEL;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 152 | false 153 | false 154 | AssemblyAndSourceCode 155 | false 156 | MultiThreadedDebug 157 | 158 | 159 | Native 160 | true 161 | true 162 | true 163 | KernelMain 164 | true 165 | 166 | false 167 | false 168 | 0x140000000 169 | .pdata=.rdata 170 | 171 | 172 | 173 | 174 | Level3 175 | Use 176 | MaxSpeed 177 | true 178 | true 179 | CRT_KERNEL;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 180 | false 181 | false 182 | AssemblyAndSourceCode 183 | false 184 | MultiThreadedDebug 185 | 186 | 187 | Native 188 | true 189 | true 190 | true 191 | KernelMain 192 | true 193 | 194 | false 195 | false 196 | 0x140000000 197 | .pdata=.rdata 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | Create 221 | Create 222 | Create 223 | Create 224 | 225 | 226 | 227 | 228 | {1e5a446d-7442-4d55-8f1e-ee51522b0feb} 229 | 230 | 231 | {bda96904-85bb-4f2a-bf7a-659f0d5acd8d} 232 | 233 | 234 | 235 | 236 | false 237 | false 238 | Document 239 | false 240 | false 241 | false 242 | false 243 | false 244 | false 245 | ml64 /c %(Identity) 246 | Compiling Assembly ... 247 | %(Filename).obj 248 | ml64 /c %(Identity) 249 | Compiling Assembly ... 250 | %(Filename).obj 251 | ml64 /c %(Identity) 252 | Compiling Assembly ... 253 | %(Filename).obj 254 | ml64 /c %(Identity) 255 | Compiling Assembly ... 256 | %(Filename).obj 257 | 258 | 259 | 260 | 261 | 262 | --------------------------------------------------------------------------------