Browse Source

フレームバッファ 割り込みの実装

master
Chiharu Shirasaka 1 year ago
parent
commit
6159cb9d27
  1. 1
      .gitignore
  2. 10
      README.md
  3. 17
      fb.c
  4. 14
      fb.h
  5. 513
      font.h
  6. 48
      gdt.c
  7. 1
      gdt.h
  8. 29
      int_handler.s
  9. 122
      interrupt.c
  10. 1
      interrupt.h
  11. 10
      io.c
  12. 4
      io.h
  13. 88
      main.c
  14. 5
      sprinkleos.dec
  15. 35
      sprinkleos.dsc
  16. 23
      sprinkleos.inf
  17. 76
      text.c
  18. 6
      text.h

1
.gitignore

@ -0,0 +1 @@
.vscode/settings.json

10
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を上手いこと起動

17
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;
}

14
fb.h

@ -0,0 +1,14 @@
#include <Protocol/GraphicsOutput.h>
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);

513
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}};

48
gdt.c

@ -0,0 +1,48 @@
#include <Library/BaseLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiLib.h>
#include <Uefi.h>
#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");
}

1
gdt.h

@ -0,0 +1 @@
void GDT_init();

29
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

122
interrupt.c

@ -0,0 +1,122 @@
#include <Library/BaseLib.h>
#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);
}

1
interrupt.h

@ -0,0 +1 @@
void interrupt_init();

10
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));
}

4
io.h

@ -0,0 +1,4 @@
#include <Uefi.h>
#include <Uefi/UefiSpec.h>
UINT8 mapped_io_read(UINT16 addr);
void mapped_io_write(UINT16 addr, UINT8 data);

88
main.c

@ -0,0 +1,88 @@
#include <Library/BaseMemoryLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
/*
#include <Pi/PiMultiPhase.h>
#include <Protocol/MpService.h>
*/
#include <Uefi.h>
#include <Uefi/UefiSpec.h>
#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;
}

5
sprinkleos.dec

@ -0,0 +1,5 @@
[Defines]
DEC_SPECIFICATION = 0x00010005
PACKAGE_NAME = sprinkleos
PACKAGE_GUID = c6ef5994-becc-4b31-8bb9-9746211704b9
PACKAGE_VERSION = 0.1

35
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

23
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

76
text.c

@ -0,0 +1,76 @@
#include "text.h"
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
#include <Protocol/SimpleFileSystem.h>
#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++;
}
}

6
text.h

@ -0,0 +1,6 @@
#include <Protocol/SimpleFileSystem.h>
#include <Uefi.h>
#include <Uefi/UefiSpec.h>
// extern char keycode[];
void textout(UINT8 code);
Loading…
Cancel
Save