diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6f9a44 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/settings.json diff --git a/README.md b/README.md index cedf6af..2aa7c91 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,13 @@ * https://www.slideshare.net/uchan_nos/uefielf * 最新情報処理概論 改訂版 P.96~P.98 * 平成30年度キタミ式応用情報技術者 P.268~P.333 + +# ビルド方法 +```git clone https://github.com/tianocore/edk2.git``` +```cd edk2``` +```git clone https://gitlab.pepepper.cf/ecri/sprinkleos.git``` +```. edksetup.sh``` +```make -C BaseTools/Source/C``` +target.txtのACTIVE_PLATFORMをsprinkleos/sprinkleos.dscに TARGET_ARCHをX64に TOOL_CHAIN_TAGをGCC5に +```build``` +出来上がったBuild/SprinkleOSX64/DEBUG_GCC5/X64/sprinkleos.efiを上手いこと起動 \ No newline at end of file diff --git a/fb.c b/fb.c new file mode 100644 index 0000000..f75dbd9 --- /dev/null +++ b/fb.c @@ -0,0 +1,17 @@ +#include "fb.h" +struct FrameBuffer buffer; +void FrameBuffer_init( + EFI_GRAPHICS_OUTPUT_PROTOCOL *gop) { // Initialize framebuffer struct + buffer.BaseAddress = gop->Mode->FrameBufferBase; + buffer.Size = gop->Mode->FrameBufferSize; + buffer.HorizontalRes = gop->Mode->Info->HorizontalResolution; + buffer.VerticalRes = gop->Mode->Info->VerticalResolution; + buffer.PixelFormat = gop->Mode->Info->PixelFormat; +} + +void RGBtoPixel(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *pixel, + UINT32 RGB) { // 0xaaaaaa format RGB to BGR Pixel format + pixel->Blue = RGB & 0xff; + pixel->Green = (RGB >> 8) & 0xff; + pixel->Red = (RGB >> 16) & 0xff; +} \ No newline at end of file diff --git a/fb.h b/fb.h new file mode 100644 index 0000000..5d7ae8b --- /dev/null +++ b/fb.h @@ -0,0 +1,14 @@ +#include + +struct FrameBuffer { + EFI_PHYSICAL_ADDRESS BaseAddress; + UINTN Size; + UINT32 HorizontalRes; + UINT32 VerticalRes; + EFI_GRAPHICS_PIXEL_FORMAT PixelFormat; +}; + +extern struct FrameBuffer buffer; + +void FrameBuffer_init(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop); +void RGBtoPixel(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *pixel, UINT32 RGB); \ No newline at end of file diff --git a/font.h b/font.h new file mode 100644 index 0000000..2d0569f --- /dev/null +++ b/font.h @@ -0,0 +1,513 @@ +char font[256][13] = { // from mplus_f12r.bdf + {0x00, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x20, 0x70, 0xF8, 0x70, 0x20, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x54, 0xA8, 0x54, 0xA8, 0x54, 0xA8, 0x54, 0xA8, 0x54, 0xA8, 0x54, + 0xA8}, + {0x00, 0x88, 0x88, 0xF8, 0x88, 0x88, 0x00, 0xF8, 0x20, 0x20, 0x20, 0x20, + 0x00}, + {0x00, 0xF8, 0x80, 0xF8, 0x80, 0x80, 0x00, 0xF8, 0x80, 0xF8, 0x80, 0x80, + 0x00}, + {0x00, 0xF8, 0x88, 0x80, 0x88, 0xF8, 0x00, 0xF8, 0x88, 0xF8, 0x90, 0x88, + 0x00}, + {0x00, 0x80, 0x80, 0x80, 0x80, 0xF8, 0x00, 0xF8, 0x80, 0xF8, 0x80, 0x80, + 0x00}, + {0x00, 0x60, 0x90, 0x90, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x20, 0x20, 0xF8, 0x20, 0x20, 0x00, 0x00, 0xF8, 0x00, + 0x00}, + {0x00, 0x88, 0xC8, 0xA8, 0x98, 0x88, 0x00, 0x80, 0x80, 0x80, 0x80, 0xF8, + 0x00}, + {0x00, 0x88, 0x88, 0x88, 0x90, 0xE0, 0x00, 0xF8, 0x20, 0x20, 0x20, 0x20, + 0x00}, + {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xE0, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x20, 0x20, 0x20, 0x20, + 0x20}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x20, 0x20, 0x20, 0x20, + 0x20}, + {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3C, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xFC, 0x20, 0x20, 0x20, 0x20, + 0x20}, + {0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, + 0x00}, + {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3C, 0x20, 0x20, 0x20, 0x20, + 0x20}, + {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xE0, 0x20, 0x20, 0x20, 0x20, + 0x20}, + {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xFC, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x20, 0x20, 0x20, 0x20, + 0x20}, + {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20}, + {0x00, 0x00, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x00, 0xF8, 0x00, + 0x00}, + {0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x10, 0x20, 0x40, 0x00, 0xF8, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x50, 0x50, 0x50, 0x90, 0x90, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x10, 0x10, 0xF8, 0x20, 0xF8, 0x40, 0x40, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x30, 0x48, 0x40, 0x40, 0xF0, 0x40, 0x40, 0x60, 0x98, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x70, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x20, 0x00, + 0x00}, + {0x00, 0x50, 0x50, 0x50, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x50, 0x50, 0xF8, 0x50, 0x50, 0x50, 0xF8, 0x50, 0x50, 0x00, + 0x00}, + {0x00, 0x00, 0x20, 0x78, 0xA0, 0xA0, 0x70, 0x28, 0x28, 0xF0, 0x20, 0x00, + 0x00}, + {0x00, 0x00, 0x40, 0xA0, 0x48, 0x10, 0x20, 0x40, 0x90, 0x28, 0x10, 0x00, + 0x00}, + {0x00, 0x00, 0x60, 0x90, 0x90, 0x60, 0x48, 0xA8, 0x90, 0x90, 0x68, 0x00, + 0x00}, + {0x00, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x20, 0x40, 0x40, 0x40, 0x40, 0x40, 0x20, 0x20, 0x10, + 0x00}, + {0x00, 0x40, 0x20, 0x20, 0x10, 0x10, 0x10, 0x10, 0x10, 0x20, 0x20, 0x40, + 0x00}, + {0x00, 0x00, 0x00, 0x20, 0xA8, 0x70, 0x20, 0x70, 0xA8, 0x20, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0xF8, 0x20, 0x20, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x70, 0x20, 0x40, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x70, 0x20, 0x00, + 0x00}, + {0x00, 0x00, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x80, + 0x00}, + {0x00, 0x00, 0x70, 0x88, 0x88, 0x98, 0xA8, 0xC8, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x20, 0x60, 0xA0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x88, 0x88, 0x08, 0x10, 0x20, 0x40, 0x80, 0xF8, 0x00, + 0x00}, + {0x00, 0x00, 0xF8, 0x08, 0x10, 0x20, 0x70, 0x08, 0x08, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x30, 0x30, 0x50, 0x50, 0x90, 0x90, 0xF8, 0x10, 0x10, 0x00, + 0x00}, + {0x00, 0x00, 0xF8, 0x80, 0x80, 0xF0, 0x08, 0x08, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x30, 0x40, 0x80, 0xF0, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0xF8, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x40, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x88, 0x88, 0x50, 0x20, 0x50, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x78, 0x08, 0x10, 0x60, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x20, 0x70, 0x20, 0x00, 0x20, 0x70, 0x20, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x20, 0x70, 0x20, 0x00, 0x20, 0x70, 0x20, 0x40, + 0x00}, + {0x00, 0x00, 0x08, 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x08, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x88, 0x88, 0x08, 0x10, 0x20, 0x20, 0x00, 0x20, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x88, 0xB8, 0xA8, 0xA8, 0xA8, 0xB8, 0x80, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x20, 0x20, 0x50, 0x50, 0x50, 0xF8, 0x88, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x00, 0xF0, 0x88, 0x88, 0x88, 0xF0, 0x88, 0x88, 0x88, 0xF0, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x88, 0x80, 0x80, 0x80, 0x80, 0x80, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0xE0, 0x90, 0x88, 0x88, 0x88, 0x88, 0x88, 0x90, 0xE0, 0x00, + 0x00}, + {0x00, 0x00, 0xF8, 0x80, 0x80, 0x80, 0xF0, 0x80, 0x80, 0x80, 0xF8, 0x00, + 0x00}, + {0x00, 0x00, 0xF8, 0x80, 0x80, 0x80, 0xF0, 0x80, 0x80, 0x80, 0x80, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x88, 0x80, 0x80, 0xB8, 0x88, 0x88, 0x88, 0x78, 0x00, + 0x00}, + {0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0xF8, 0x88, 0x88, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x88, 0x90, 0xA0, 0xC0, 0xC0, 0xA0, 0x90, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xF8, 0x00, + 0x00}, + {0x00, 0x00, 0x88, 0xD8, 0xA8, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x00, 0x88, 0xC8, 0xA8, 0x98, 0x88, 0x88, 0x88, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0xF0, 0x88, 0x88, 0x88, 0xF0, 0x80, 0x80, 0x80, 0x80, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x10, + 0x0C}, + {0x00, 0x00, 0xF0, 0x88, 0x88, 0x88, 0xF0, 0xA0, 0x90, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x88, 0x80, 0x80, 0x70, 0x08, 0x08, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0xF8, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x00}, + {0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x50, 0x50, 0x50, 0x20, 0x20, 0x00, + 0x00}, + {0x00, 0x00, 0xA8, 0xA8, 0xA8, 0xA8, 0xA8, 0xA8, 0x50, 0x50, 0x50, 0x00, + 0x00}, + {0x00, 0x00, 0x88, 0x88, 0x50, 0x50, 0x20, 0x50, 0x50, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x00, 0x88, 0x88, 0x50, 0x50, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x00}, + {0x00, 0x00, 0xF8, 0x08, 0x10, 0x10, 0x20, 0x40, 0x40, 0x80, 0xF8, 0x00, + 0x00}, + {0x00, 0x70, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x70, + 0x00}, + {0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, + 0x00}, + {0x00, 0x70, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x70, + 0x00}, + {0x00, 0x20, 0x50, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, + 0x00}, + {0x00, 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x08, 0x78, 0x88, 0x88, 0x78, 0x00, + 0x00}, + {0x00, 0x00, 0x80, 0x80, 0x80, 0xF0, 0x88, 0x88, 0x88, 0x88, 0xF0, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x88, 0x80, 0x80, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x08, 0x08, 0x08, 0x78, 0x88, 0x88, 0x88, 0x88, 0x78, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x88, 0xF8, 0x80, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x18, 0x20, 0x20, 0x20, 0xF8, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x88, 0x88, 0x88, 0x78, 0x08, 0x88, + 0x70}, + {0x00, 0x00, 0x80, 0x80, 0x80, 0xB0, 0xC8, 0x88, 0x88, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x20, 0x00, 0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, + 0x00}, + {0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0xE0}, + {0x00, 0x00, 0x80, 0x80, 0x80, 0x90, 0xA0, 0xC0, 0xA0, 0x90, 0x88, 0x00, + 0x00}, + {0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xA8, 0xA8, 0xA8, 0xA8, 0xA8, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0xC8, 0x88, 0x88, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x88, 0x88, 0x88, 0xF0, 0x80, 0x80, + 0x80}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x88, 0x88, 0x88, 0x78, 0x08, 0x08, + 0x08}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0xC8, 0x80, 0x80, 0x80, 0x80, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x88, 0x70, 0x08, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x40, 0x40, 0x40, 0xF0, 0x40, 0x40, 0x40, 0x48, 0x30, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x98, 0x68, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x50, 0x50, 0x20, 0x20, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0xA8, 0xA8, 0xA8, 0xA8, 0x50, 0x50, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x50, 0x20, 0x20, 0x50, 0x88, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x78, 0x08, 0x88, + 0x70}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x10, 0x20, 0x40, 0x80, 0xF8, 0x00, + 0x00}, + {0x00, 0x18, 0x20, 0x20, 0x20, 0x20, 0xC0, 0x20, 0x20, 0x20, 0x20, 0x18, + 0x00}, + {0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x00}, + {0x00, 0xC0, 0x20, 0x20, 0x20, 0x20, 0x18, 0x20, 0x20, 0x20, 0x20, 0xC0, + 0x00}, + {0x00, 0x00, 0x68, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x00}, + {0x00, 0x00, 0x20, 0x20, 0x70, 0xA8, 0xA0, 0xA0, 0xA0, 0x78, 0x20, 0x00, + 0x00}, + {0x00, 0x00, 0x30, 0x48, 0x40, 0x40, 0xF0, 0x40, 0x40, 0x60, 0x98, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x88, 0x70, 0x50, 0x50, 0x70, 0x88, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x88, 0x88, 0x50, 0x50, 0xF8, 0x20, 0xF8, 0x20, 0x20, 0x00, + 0x00}, + {0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x00}, + {0x00, 0x60, 0x90, 0x80, 0x40, 0xA0, 0x90, 0x50, 0x20, 0x10, 0x90, 0x60, + 0x00}, + {0x00, 0x00, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0xF8, 0x88, 0x70, 0x40, 0x40, 0x40, 0x70, 0x88, 0xF8, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x08, 0x78, 0x88, 0x78, 0x00, 0xF8, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x08, 0x10, 0x28, 0x50, 0xA0, 0x50, 0x28, 0x10, 0x08, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x08, 0x08, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0xF8, 0x88, 0x70, 0x50, 0x60, 0x50, 0x50, 0x88, 0xF8, 0x00, + 0x00}, + {0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x60, 0x90, 0x90, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x20, 0x20, 0xF8, 0x20, 0x20, 0x00, 0x00, 0xF8, 0x00, + 0x00}, + {0x00, 0x60, 0x90, 0x10, 0x20, 0x40, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0xF0, 0x10, 0x60, 0x10, 0x90, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x98, 0xE8, 0x80, + 0x80}, + {0x00, 0x00, 0x78, 0xE8, 0xE8, 0xE8, 0xE8, 0x68, 0x28, 0x28, 0x28, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x70, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, + 0x40}, + {0x00, 0x20, 0x60, 0xA0, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x60, 0x90, 0x90, 0x90, 0x60, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x80, 0x40, 0xA0, 0x50, 0x28, 0x50, 0xA0, 0x40, 0x80, 0x00, + 0x00}, + {0x00, 0x00, 0x40, 0xC0, 0x40, 0x40, 0x50, 0x30, 0x50, 0x78, 0x10, 0x00, + 0x00}, + {0x00, 0x00, 0x40, 0xC0, 0x40, 0x40, 0x50, 0x28, 0x08, 0x10, 0x38, 0x00, + 0x00}, + {0x00, 0x00, 0xE0, 0x20, 0x40, 0x20, 0xD0, 0x30, 0x50, 0x78, 0x10, 0x00, + 0x00}, + {0x00, 0x00, 0x20, 0x00, 0x20, 0x20, 0x40, 0x80, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x20, 0x10, 0x00, 0x20, 0x20, 0x50, 0x50, 0xF8, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0x20, 0x20, 0x50, 0x50, 0xF8, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x30, 0x48, 0x00, 0x20, 0x20, 0x50, 0x50, 0xF8, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x68, 0xB0, 0x00, 0x20, 0x20, 0x50, 0x50, 0xF8, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x50, 0x50, 0x00, 0x20, 0x20, 0x50, 0x50, 0xF8, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x30, 0x48, 0x48, 0x30, 0x20, 0x50, 0x50, 0xF8, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x00, 0xF8, 0xA0, 0xA0, 0xA0, 0xF8, 0xA0, 0xA0, 0xA0, 0xB8, 0x00, + 0x00}, + {0x00, 0x00, 0x70, 0x88, 0x80, 0x80, 0x80, 0x80, 0x80, 0x88, 0x70, 0x20, + 0x40}, + {0x00, 0x20, 0x10, 0x00, 0xF8, 0x80, 0x80, 0xF0, 0x80, 0x80, 0xF8, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0xF8, 0x80, 0x80, 0xF0, 0x80, 0x80, 0xF8, 0x00, + 0x00}, + {0x00, 0x30, 0x48, 0x00, 0xF8, 0x80, 0x80, 0xF0, 0x80, 0x80, 0xF8, 0x00, + 0x00}, + {0x00, 0x50, 0x50, 0x00, 0xF8, 0x80, 0x80, 0xF0, 0x80, 0x80, 0xF8, 0x00, + 0x00}, + {0x00, 0x20, 0x10, 0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, + 0x00}, + {0x00, 0x30, 0x48, 0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, + 0x00}, + {0x00, 0x50, 0x50, 0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0xF0, 0x48, 0x48, 0x48, 0xE8, 0x48, 0x48, 0x48, 0xF0, 0x00, + 0x00}, + {0x00, 0x68, 0xB0, 0x00, 0x88, 0xC8, 0xA8, 0x98, 0x88, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x20, 0x10, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x30, 0x48, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x68, 0xB0, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x50, 0x50, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x88, 0x50, 0x20, 0x50, 0x88, 0x00, 0x00, 0x00, + 0x00}, + {0x00, 0x08, 0x70, 0x98, 0xA8, 0xA8, 0xA8, 0xA8, 0xA8, 0xC8, 0x70, 0x80, + 0x00}, + {0x00, 0x20, 0x10, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x30, 0x48, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x50, 0x50, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0x88, 0x88, 0x50, 0x50, 0x20, 0x20, 0x20, 0x00, + 0x00}, + {0x00, 0x80, 0x80, 0xF0, 0x88, 0x88, 0x88, 0xF0, 0x80, 0x80, 0x80, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x70, 0x88, 0x88, 0xF0, 0x88, 0x88, 0x88, 0xF0, 0x80, + 0x80}, + {0x00, 0x20, 0x10, 0x00, 0x00, 0x70, 0x08, 0x78, 0x88, 0x88, 0x78, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0x00, 0x70, 0x08, 0x78, 0x88, 0x88, 0x78, 0x00, + 0x00}, + {0x00, 0x30, 0x48, 0x00, 0x00, 0x70, 0x08, 0x78, 0x88, 0x88, 0x78, 0x00, + 0x00}, + {0x00, 0x68, 0xB0, 0x00, 0x00, 0x70, 0x08, 0x78, 0x88, 0x88, 0x78, 0x00, + 0x00}, + {0x00, 0x50, 0x50, 0x00, 0x00, 0x70, 0x08, 0x78, 0x88, 0x88, 0x78, 0x00, + 0x00}, + {0x00, 0x30, 0x48, 0x30, 0x00, 0x70, 0x08, 0x78, 0x88, 0x88, 0x78, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x28, 0xF8, 0xA0, 0xA0, 0xF8, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x88, 0x80, 0x80, 0x88, 0x70, 0x20, + 0x40}, + {0x00, 0x20, 0x10, 0x00, 0x00, 0x70, 0x88, 0xF8, 0x80, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0x00, 0x70, 0x88, 0xF8, 0x80, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x30, 0x48, 0x00, 0x00, 0x70, 0x88, 0xF8, 0x80, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x50, 0x50, 0x00, 0x00, 0x70, 0x88, 0xF8, 0x80, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x20, 0x10, 0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, + 0x00}, + {0x00, 0x30, 0x48, 0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, + 0x00}, + {0x00, 0x50, 0x50, 0x00, 0x00, 0x60, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, + 0x00}, + {0x00, 0x40, 0x38, 0xE0, 0x10, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x68, 0xB0, 0x00, 0x00, 0xB0, 0xC8, 0x88, 0x88, 0x88, 0x88, 0x00, + 0x00}, + {0x00, 0x20, 0x10, 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x30, 0x48, 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x68, 0xB0, 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x50, 0x50, 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x20, 0x20, 0x00, 0xF8, 0x00, 0x20, 0x20, 0x00, 0x00, + 0x00}, + {0x00, 0x00, 0x00, 0x00, 0x08, 0x70, 0x98, 0xA8, 0xA8, 0xC8, 0x70, 0x80, + 0x00}, + {0x00, 0x20, 0x10, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x98, 0x68, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x98, 0x68, 0x00, + 0x00}, + {0x00, 0x30, 0x48, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x98, 0x68, 0x00, + 0x00}, + {0x00, 0x50, 0x50, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x98, 0x68, 0x00, + 0x00}, + {0x00, 0x10, 0x20, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x78, 0x08, 0x88, + 0x70}, + {0x00, 0x00, 0x00, 0x80, 0x80, 0xF0, 0x88, 0x88, 0x88, 0xF0, 0x80, 0x80, + 0x80}, + {0x00, 0x50, 0x50, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x78, 0x08, 0x88, + 0x70}}; \ No newline at end of file diff --git a/gdt.c b/gdt.c new file mode 100644 index 0000000..fc8d529 --- /dev/null +++ b/gdt.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include + +#include "io.h" + +UINT64 SegmentDescriptors[] = { + 0x0000000000000000, // NULL Descriptor + 0x00AF9A000000FFFF, // BaseAddress 0 Granularity 1 + // SegmentSize 1048575*4069=4294963200(4GB) Segment Present + // Plivilege 0 Code Segment Read+Exec + 0x00CF93000000FFFF // BaseAddress 0 Granularity 1 + // SegmentSize 1048575*4069=4294963200(4GB) Segment + // Present Plivilege 0 Data Segment Read+Write +}; +IA32_DESCRIPTOR Descriptor; + +void sendparallelstub(UINT8 byte) { + mapped_io_write(0x378, byte); + UINT8 control = mapped_io_read(0x37a); + mapped_io_write(0x37a, control | 1); + int a; + for (int i = 0; i < 200; i++) a += control; + mapped_io_write(0x37a, control); +} + +void GDT_init() { + Descriptor.Limit = (UINT16)(sizeof(UINT64) * 3 - 1); + Descriptor.Base = (UINT32)(UINTN)(VOID *)SegmentDescriptors; + AsmWriteGdtr(&Descriptor); + asm volatile( + "mov $16, %ax\n" + "mov %ax, %ss\n" + "mov %ax, %ds\n" + "mov %ax, %es\n" + "mov %ax, %fs\n" + "mov %ax, %gs\n" + "sub $16,%rsp\n" + "leaq end(%rip),%rax\n" + "mov %rax,(%rsp)\n" + "mov $8,%ax\n" + "mov %ax,4(%rsp)\n" + "ljmp *(%rsp)\n" + "end:\n" + "add $16,%rsp"); +} \ No newline at end of file diff --git a/gdt.h b/gdt.h new file mode 100644 index 0000000..e9f575e --- /dev/null +++ b/gdt.h @@ -0,0 +1 @@ +void GDT_init(); \ No newline at end of file diff --git a/int_handler.s b/int_handler.s new file mode 100644 index 0000000..b5ce07c --- /dev/null +++ b/int_handler.s @@ -0,0 +1,29 @@ +.global null_handler + +null_handler: + hlt + jmp null_handler + +.global kbd_handler + +kbd_handler: + push %rax + push %rcx + push %rdx + push %rsi + push %rdi + push %r8 + push %r9 + push %r10 + push %r11 + call keyboard_int_proc + pop %r11 + pop %r10 + pop %r9 + pop %r8 + pop %rdi + pop %rsi + pop %rdx + pop %rcx + pop %rax + iretq \ No newline at end of file diff --git a/interrupt.c b/interrupt.c new file mode 100644 index 0000000..7e9c4f6 --- /dev/null +++ b/interrupt.c @@ -0,0 +1,122 @@ +#include + +#include "io.h" +#include "text.h" +#define SPECIAL_SHIFT_L 0b00000001 +#define SPECIAL_SHIFT_R 0b00000010 +#define SPECIAL_CTRL_L 0b00000100 +#define SPECIAL_CTRL_R 0b00001000 +#define SPECIAL_ALT_L 0b00010000 +#define SPECIAL_ALT_R 0b00100000 +#define SPECIAL_SUPER_L 0b01000000 +#define SPECIAL_SUPER_R 0b10000000 + +void null_handler(); +void kbd_handler(); +IA32_IDT_GATE_DESCRIPTOR descriptors[256]; + +void descriptor_init() { + for (int i = 0; i < 256; i++) { + descriptors[i].Bits.Selector = 0x08; + descriptors[i].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32; + descriptors[i].Bits.OffsetLow = (UINT32)(UINTN)(VOID *)null_handler; + descriptors[i].Bits.OffsetHigh = + (UINT32)((UINTN)(VOID *)null_handler >> 16); + descriptors[i].Bits.OffsetUpper = + (UINT32)((UINTN)(VOID *)null_handler >> 32); + } // null descriptor set +} + +void set_handler(int num, UINTN handler) { + descriptors[num].Bits.OffsetLow = (UINT32)handler; + descriptors[num].Bits.OffsetHigh = (UINT32)(handler >> 16); + descriptors[num].Bits.OffsetUpper = (UINT32)(handler >> 32); +} + +void master_pic_init() { + mapped_io_write(0x0020, 0x11); // ICW1 + mapped_io_write(0x0021, 32); // ICW2 + mapped_io_write(0x0021, 0x04); // ICW3 + mapped_io_write(0x0021, 0x01); // ICW4 + mapped_io_write(0x0021, 0xFF); // OCW1 +} + +void slave_pic_init() { + mapped_io_write(0x00A0, 0x11); + mapped_io_write(0x00A1, 40); + mapped_io_write(0x00A1, 0x02); + mapped_io_write(0x00A1, 0x01); + mapped_io_write(0x00A1, 0xff); +} + +void unmask_interrupt(UINT8 interrupt_num) { + if (interrupt_num < 40) { + UINT8 mask = mapped_io_read(0x0021); + mapped_io_write(0x0021, mask & ~(1 << (interrupt_num - 32))); + } else { + UINT8 mask = mapped_io_read(0x00A1); + mapped_io_write(0x00A1, mask & ~(1 << (interrupt_num - 40))); + } +} + +void end_of_interrupt(UINT8 interrupt_num) { + if (interrupt_num < 40) { + mapped_io_write(0x0020, 0x60 | (interrupt_num - 32)); + } else { + mapped_io_write(0x00A0, 0x60 | (interrupt_num - 40)); + } +} + +void interrupt_init() { + IA32_DESCRIPTOR Descriptor; + descriptor_init(); + set_handler(33, (UINTN)(VOID *)kbd_handler); + Descriptor.Limit = (UINT16)(sizeof(descriptors) - 1); + Descriptor.Base = (UINT32)(UINTN)(VOID *)descriptors; + AsmWriteIdtr(&Descriptor); + EnableInterrupts(); + master_pic_init(); + slave_pic_init(); + unmask_interrupt(33); +} + +void keyboard_int_proc() { + UINT8 data; + // static char keyboard_special_keys = 0; + data = mapped_io_read(0x64); + if ((data & 0b00000001) == 0) // output buffer is not full + goto eoi; + data = mapped_io_read(0x60); + /* + if (data & 0b10000000){ // key is broken + switch (data & 0b01111111) { + case 44: + keyboard_special_keys &= ~SPECIAL_SHIFT_L; + return; + case 57: + keyboard_special_keys &= ~SPECIAL_SHIFT_R; + return; + case 58: + keyboard_special_keys &= ~SPECIAL_CTRL_L; + return; + case 64: + keyboard_special_keys &= ~SPECIAL_CTRL_R; + return; + case 60: + keyboard_special_keys &= ~SPECIAL_ALT_L; + return; + case 62: + keyboard_special_keys &= ~SPECIAL_ALT_R; + return; + case : + keyboard_special_keys &= ~SPECIAL_CTRL_L; + return; + default: + return; + } + } + */ + textout('0'); +eoi: + end_of_interrupt(33); +} \ No newline at end of file diff --git a/interrupt.h b/interrupt.h new file mode 100644 index 0000000..db2cbe2 --- /dev/null +++ b/interrupt.h @@ -0,0 +1 @@ +void interrupt_init(); \ No newline at end of file diff --git a/io.c b/io.c new file mode 100644 index 0000000..91b1c0a --- /dev/null +++ b/io.c @@ -0,0 +1,10 @@ +#include "io.h" +UINT8 mapped_io_read(UINT16 addr) { + UINT8 data; + asm volatile("inb %1,%0" : "=a"(data) : "d"(addr)); + return data; +} + +void mapped_io_write(UINT16 addr, UINT8 data) { + asm volatile("outb %0,%1" ::"a"(data), "d"(addr)); +} diff --git a/io.h b/io.h new file mode 100644 index 0000000..35968ab --- /dev/null +++ b/io.h @@ -0,0 +1,4 @@ +#include +#include +UINT8 mapped_io_read(UINT16 addr); +void mapped_io_write(UINT16 addr, UINT8 data); \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 0000000..9c6fbbf --- /dev/null +++ b/main.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include +/* +#include +#include +*/ + +#include +#include + +#include "fb.h" +#include "gdt.h" +#include "interrupt.h" +#include "text.h" + +EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable) { + EFI_STATUS Status; + EFI_GRAPHICS_OUTPUT_PROTOCOL *gop; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fsp; + // EFI_MP_SERVICES_PROTOCOL *mps; + + SystemTable->BootServices->SetWatchdogTimer( + 0, 0, 0, NULL); // Disable watch dog timer + + Status = SystemTable->BootServices->LocateProtocol( + &gEfiGraphicsOutputProtocolGuid, NULL, + (VOID **)&gop); // Get GOP Protocol + if (EFI_ERROR(Status)) { + Print(L"Error:Failed to locate EFI Graphics Output Protocol - %r", + Status); + return Status; + } + + Status = SystemTable->BootServices->LocateProtocol( + &gEfiSimpleFileSystemProtocolGuid, NULL, (VOID **)&fsp); + if (EFI_ERROR(Status)) { + Print(L"Error:Failed to locate EFI Simple FileSystem Protocol - %r", + Status); + return Status; + } + + /* + Status = SystemTable->BootServices->LocateProtocol( + &gEfiMpServiceProtocolGuid, NULL, + (VOID **)&mps); // Get MultiProcessor Protocol + if (EFI_ERROR(Status)) { + Print(L"Error:Failed to locate EFI MP Services Protocol - %r", + Status); return Status; + } + */ + + FrameBuffer_init(gop); + UINTN MemoryMapSize = 1, MapKey, DescriptorSize; + UINT32 DescriptorVersion; + do { + EFI_MEMORY_DESCRIPTOR *mem_desc = + (EFI_MEMORY_DESCRIPTOR *)AllocatePool(MemoryMapSize); + Status = SystemTable->BootServices->GetMemoryMap( + &MemoryMapSize, mem_desc, &MapKey, &DescriptorSize, + &DescriptorVersion); + if (EFI_ERROR(Status)) continue; + Status = + SystemTable->BootServices->ExitBootServices(ImageHandle, MapKey); + } while (EFI_ERROR(Status)); + GDT_init(); + interrupt_init(); + for (int y = 0; y < buffer.VerticalRes; y++) { + for (int x = 0; x < buffer.HorizontalRes; x++) { + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *pixel = + (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)buffer.BaseAddress + + (buffer.HorizontalRes * y) + x; + RGBtoPixel(pixel, 0xFF0000); + } + } + textout('A'); + textout('p'); + textout('p'); + textout('l'); + textout('e'); + while (1) asm volatile("hlt"); + return Status; +} \ No newline at end of file diff --git a/sprinkleos.dec b/sprinkleos.dec new file mode 100644 index 0000000..04f89d2 --- /dev/null +++ b/sprinkleos.dec @@ -0,0 +1,5 @@ +[Defines] + DEC_SPECIFICATION = 0x00010005 + PACKAGE_NAME = sprinkleos + PACKAGE_GUID = c6ef5994-becc-4b31-8bb9-9746211704b9 + PACKAGE_VERSION = 0.1 \ No newline at end of file diff --git a/sprinkleos.dsc b/sprinkleos.dsc new file mode 100644 index 0000000..262c516 --- /dev/null +++ b/sprinkleos.dsc @@ -0,0 +1,35 @@ +[Defines] + PLATFORM_NAME = sprinkleos + PLATFORM_GUID = a285f937-1da6-4f62-ba24-a5b8ec562189 + PLATFORM_VERSION = 0.1 + DSC_SPECIFICATION = 0x00010005 + OUTPUT_DIRECTORY = Build/SprinkleOS$(ARCH) + SUPPORTED_ARCHITECTURES = X64 + BUILD_TARGETS = DEBUG|RELEASE|NOOPT + + DEFINE DEBUG_ENABLE_OUTPUT = FALSE + +[LibraryClasses] + # Entry point + UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf + + # Common Libraries + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf + !if $(DEBUG_ENABLE_OUTPUT) + DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf + DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf + !else ## DEBUG_ENABLE_OUTPUT + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf + !endif ## DEBUG_ENABLE_OUTPUT + + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + +[Components] + sprinkleos/sprinkleos.inf \ No newline at end of file diff --git a/sprinkleos.inf b/sprinkleos.inf new file mode 100644 index 0000000..017a210 --- /dev/null +++ b/sprinkleos.inf @@ -0,0 +1,23 @@ +[Defines] + INF_VERSION = 0x00010006 + BASE_NAME = sprinkleos + FILE_GUID = 26213998-6ebc-422b-b917-a396a364fb81 + MODULE_TYPE = UEFI_APPLICATION + VERSION_STRING = 0.1 + ENTRY_POINT = UefiMain + +[Sources] + main.c + fb.c + gdt.c + interrupt.c + io.c + text.c + int_handler.s + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + UefiLib + UefiApplicationEntryPoint \ No newline at end of file diff --git a/text.c b/text.c new file mode 100644 index 0000000..b38780f --- /dev/null +++ b/text.c @@ -0,0 +1,76 @@ +#include "text.h" + +#include +#include +#include + +#include "fb.h" +#include "font.h" +/* +char keycode[] = { +0x0, +}; +*/ +/* +void textinit(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fsp) { + EFI_FILE_PROTOCOL *root, *file; + + EFI_STATUS Status = fsp->OpenVolume(fsp, &root); + if (EFI_ERROR(Status)) { + Print(L"Error:Failed to open root filesystem - %r", Status); + return; + } + + Status = root->Open(root, &file, L"font.bdf", EFI_FILE_MODE_READ, + EFI_FILE_READ_ONLY); + if (EFI_ERROR(Status)) { + Print(L"Error:Failed to open font file - %r", Status); + return; + } + UINTN buf_size = 1; + char* fontfiledata = AllocateRuntimeZeroPool(buf_size); + if (!fontfiledata) { + Print(L"Error:Failed to allocate font memory"); + return; + } + + Status = file->Read(file, &buf_size, (VOID*)fontfiledata); + if (Status == EFI_BUFFER_TOO_SMALL) { + FreePool(fontfiledata); + fontfiledata = AllocateRuntimeZeroPool(buf_size); + if (!fontfiledata) { + Print(L"Error:Failed to allocate font memory"); + return; + } + Status = file->Read(file, &buf_size, (VOID*)fontfiledata); + if (EFI_ERROR(Status)) { + Print(L"Error:Failed to read font file - %r", Status); + return; + } + } else if (EFI_ERROR(Status)) { + Print(L"Error:Failed to read font file - %r", Status); + return; + } + file->Close(file); + root->Close(root); +}*/ + +void textout(UINT8 code) { + static UINTN x = 0, y = 0; + for (int row = 0; row < 13; row++) { + for (int column = 0; column < 8; column++) { + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *pixel = + (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)buffer.BaseAddress + + y * 13 * buffer.HorizontalRes + row * buffer.HorizontalRes + + 8 * x + column; + if ((font[code][row] >> (7 - column)) & 0x1) + RGBtoPixel(pixel, 0x00FF00); + } + } + if (x < (buffer.HorizontalRes / 8) - 1) + x++; + else if (y < buffer.VerticalRes / 13) { + x = 0; + y++; + } +} \ No newline at end of file diff --git a/text.h b/text.h new file mode 100644 index 0000000..605f875 --- /dev/null +++ b/text.h @@ -0,0 +1,6 @@ +#include +#include +#include +// extern char keycode[]; + +void textout(UINT8 code); \ No newline at end of file