diff --git a/Makefile b/Makefile index 13e7c50..34f1279 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,8 @@ KERNEL_CPP = kernel/entry.cpp kernel/main.cpp kernel/serial.cpp kernel/fs.cpp \ kernel/interrupt/gdt.cpp kernel/interrupt/idt.cpp \ kernel/interrupt/pic.cpp kernel/interrupt/pit.cpp \ graphics/context.cpp graphics/draw.cpp \ - fonts/pixel_font.cpp + fonts/pixel_font.cpp \ + desktop/prepare.cpp KERNEL_ASM = kernel/scheduler/context_switch.S kernel/interrupt/isr.S kernel/interrupt/idt_helpers.S KERNEL_OBJ = $(KERNEL_CPP:%.cpp=build/%.o) $(KERNEL_ASM:%.S=build/%.o) @@ -47,7 +48,8 @@ all: _bd $(EFI_OBJ) $(BOOT_OBJ) $(KERNEL_OBJ) @echo "Done." _bd: - @mkdir -p build/graphics build/kernel build/fonts build/kernel/memory \ + @mkdir -p build/graphics build/kernel build/fonts build/desktop \ + build/kernel/memory \ build/kernel/scheduler build/kernel/interrupt \ build/efi/lib build/efi/lib/x86_64 build/efi/lib/runtime build/efi/gnuefi @@ -117,6 +119,10 @@ build/fonts/%.o: fonts/%.cpp | _bd @echo "Compile CPP $<" @g++ $(KERNEL_CXXFLAGS) -c $< -o $@ +build/desktop/%.o: desktop/%.cpp | _bd + @echo "Compile CPP $<" + @g++ $(KERNEL_CXXFLAGS) -c $< -o $@ + vdir: all @mkdir -p vdir/EFI/BOOT @cp build/BOOTX64.EFI vdir/EFI/BOOT diff --git a/desktop/prepare.cpp b/desktop/prepare.cpp new file mode 100644 index 0000000..054e201 --- /dev/null +++ b/desktop/prepare.cpp @@ -0,0 +1,9 @@ +#include + +void prepare(UINT32 width, UINT32 height, COLOR_RGB color) { + for (UINT32 i = 0; i < height; i++) { + for (UINT32 j = 0; j < width; j++) { + draw_pixel(i, j, color); + } + } +} \ No newline at end of file diff --git a/fonts/pixel_font.cpp b/fonts/pixel_font.cpp index 188dee3..aac5224 100644 --- a/fonts/pixel_font.cpp +++ b/fonts/pixel_font.cpp @@ -12,7 +12,7 @@ void pf_reset_position(void) { pf_y = 1; } -void pf_print_char(char c, unsigned int basex, unsigned int basey, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { +void pf_print_char(char c, unsigned int basex, unsigned int basey, COLOR_RGB color) { for (unsigned int y = 0; y < 16; y++) { unsigned char data = hankaku_pixels[c][y]; for (int x = 7; x >= 0; x--) { @@ -31,7 +31,7 @@ void pf_print_char(char c, unsigned int basex, unsigned int basey, EFI_GRAPHICS_ } } -void pf_print(const char* text, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { +void pf_print(const char* text, COLOR_RGB color) { for (unsigned int i = 0; i < strlen(text); i++) { char c = text[i]; if (c == '\n') { diff --git a/graphics/context.cpp b/graphics/context.cpp index c90894a..29c8d5a 100644 --- a/graphics/context.cpp +++ b/graphics/context.cpp @@ -1,4 +1,5 @@ #include +#include gfx_context g_gfx; @@ -6,10 +7,10 @@ void gfx_init(EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP) { g_gfx.GOP = GOP; g_gfx.hr = GOP->Mode->Info->HorizontalResolution; g_gfx.vr = GOP->Mode->Info->VerticalResolution; - g_gfx.base = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) GOP->Mode->FrameBufferBase; + g_gfx.base = (COLOR_RGB *) GOP->Mode->FrameBufferBase; } void gfx_clear(void) { - EFI_GRAPHICS_OUTPUT_BLT_PIXEL black = {0, 0, 0, 0}; + COLOR_RGB black = {0, 0, 0, 0}; g_gfx.GOP->Blt(g_gfx.GOP, &black, EfiBltVideoFill, 0, 0, 0, 0, g_gfx.hr, g_gfx.vr, 0); } \ No newline at end of file diff --git a/graphics/draw.cpp b/graphics/draw.cpp index 0fa9a20..c6cf664 100644 --- a/graphics/draw.cpp +++ b/graphics/draw.cpp @@ -1,7 +1,7 @@ #include -void draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color) { - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *p = g_gfx.base + (g_gfx.hr * y) + x; +void draw_pixel(unsigned int x, unsigned int y, COLOR_RGB color) { + COLOR_RGB *p = g_gfx.base + (g_gfx.hr * y) + x; p->Blue = color.Blue; p->Green = color.Green; diff --git a/include/common.h b/include/common.h index 11a9603..f158365 100644 --- a/include/common.h +++ b/include/common.h @@ -1,6 +1,7 @@ #pragma once #define ASM asm volatile +#define COLOR_RGB EFI_GRAPHICS_OUTPUT_BLT_PIXEL static unsigned int strlen(const char* arr) { // 获取string长度 int i = 0; diff --git a/include/desktop/prepare.h b/include/desktop/prepare.h new file mode 100644 index 0000000..4214902 --- /dev/null +++ b/include/desktop/prepare.h @@ -0,0 +1,3 @@ +#pragma once + +void prepare(UINT32 width, UINT32 height, COLOR_RGB color = {144, 238, 145}); \ No newline at end of file diff --git a/include/fonts/pixel_font.h b/include/fonts/pixel_font.h index 353328e..ca362cb 100644 --- a/include/fonts/pixel_font.h +++ b/include/fonts/pixel_font.h @@ -1,8 +1,9 @@ #pragma once #include +#include void pf_print_char(char c, unsigned int basex, unsigned int basey, - EFI_GRAPHICS_OUTPUT_BLT_PIXEL color = {255, 255, 255, 255}); // Pixel Font 打印字符 -void pf_print(const char* text, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color = {255, 255, 255, 255}); // Pixel Font 打印string -void pf_reset_position(void); // 重设Pixel Font Cursor位置 \ No newline at end of file + COLOR_RGB color = {255, 255, 255, 255}); // Pixel Font 打印字符 +void pf_print(const char* text, COLOR_RGB color = {255, 255, 255, 255}); // Pixel Font 打印string +void pf_reset_position(void); // 重设Pixel Font Cursor位置 \ No newline at end of file diff --git a/include/graphics/context.h b/include/graphics/context.h index 90166c7..8433e8c 100644 --- a/include/graphics/context.h +++ b/include/graphics/context.h @@ -3,12 +3,13 @@ // 这个文件存在的目的是让graphics的draw功能不用每次传 GOP hr vr base #include +#include struct gfx_context { EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP; unsigned int hr; unsigned int vr; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *base; + COLOR_RGB *base; }; extern gfx_context g_gfx; diff --git a/include/graphics/draw.h b/include/graphics/draw.h index 5b08c9e..d1f2a4a 100644 --- a/include/graphics/draw.h +++ b/include/graphics/draw.h @@ -3,4 +3,6 @@ #include #include -void draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color); // 画像素 \ No newline at end of file +#define COLOR_RGB EFI_GRAPHICS_OUTPUT_BLT_PIXEL + +void draw_pixel(unsigned int x, unsigned int y, COLOR_RGB color); // 画像素 \ No newline at end of file diff --git a/include/fs.h b/include/kernel/fs.h similarity index 100% rename from include/fs.h rename to include/kernel/fs.h diff --git a/include/gdt.h b/include/kernel/gdt.h similarity index 100% rename from include/gdt.h rename to include/kernel/gdt.h diff --git a/include/idt.h b/include/kernel/idt.h similarity index 100% rename from include/idt.h rename to include/kernel/idt.h diff --git a/include/pic.h b/include/kernel/pic.h similarity index 100% rename from include/pic.h rename to include/kernel/pic.h diff --git a/include/pit.h b/include/kernel/pit.h similarity index 100% rename from include/pit.h rename to include/kernel/pit.h diff --git a/include/scheduler.h b/include/kernel/scheduler.h similarity index 100% rename from include/scheduler.h rename to include/kernel/scheduler.h diff --git a/include/serial.h b/include/kernel/serial.h similarity index 100% rename from include/serial.h rename to include/kernel/serial.h diff --git a/kernel/fs.cpp b/kernel/fs.cpp index 87eaed1..e93589b 100644 --- a/kernel/fs.cpp +++ b/kernel/fs.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include diff --git a/kernel/interrupt/gdt.cpp b/kernel/interrupt/gdt.cpp index f74da9a..fbd504d 100644 --- a/kernel/interrupt/gdt.cpp +++ b/kernel/interrupt/gdt.cpp @@ -1,6 +1,6 @@ -#include +#include #include -#include +#include static gdt_entry g_gdt[7]; // 5 segments + TSS (2 entries) static gdt_ptr g_gdt_ptr; diff --git a/kernel/interrupt/idt.cpp b/kernel/interrupt/idt.cpp index 70ae035..a31a565 100644 --- a/kernel/interrupt/idt.cpp +++ b/kernel/interrupt/idt.cpp @@ -1,7 +1,7 @@ -#include +#include #include -#include -#include +#include +#include // Defined in isr.S — 256 ISR stubs extern "C" void* isr_stub_table[256]; diff --git a/kernel/interrupt/pic.cpp b/kernel/interrupt/pic.cpp index 6fb5d27..dc40ea2 100644 --- a/kernel/interrupt/pic.cpp +++ b/kernel/interrupt/pic.cpp @@ -1,6 +1,6 @@ -#include +#include #include -#include +#include static inline void outb(UINT16 port, UINT8 val) { ASM("outb %0, %1" : : "a"(val), "Nd"(port)); diff --git a/kernel/interrupt/pit.cpp b/kernel/interrupt/pit.cpp index 1389506..955bc7a 100644 --- a/kernel/interrupt/pit.cpp +++ b/kernel/interrupt/pit.cpp @@ -1,7 +1,7 @@ -#include +#include #include -#include -#include +#include +#include static inline void outb(UINT16 port, UINT8 val) { ASM("outb %0, %1" : : "a"(val), "Nd"(port)); diff --git a/kernel/main.cpp b/kernel/main.cpp index bbea2fb..97af6be 100644 --- a/kernel/main.cpp +++ b/kernel/main.cpp @@ -2,16 +2,17 @@ #include #include #include -#include +#include #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include extern EFI_SYSTEM_TABLE *ST; @@ -131,6 +132,8 @@ extern "C" void kernel_main() { pf_print("Welcome to Sylva OS!\n"); serial_write(" Kernel prepared well.\n"); + prepare((UINT32) g_gfx.vr, (UINT32) g_gfx.hr); + // --- Interrupt infrastructure --- serial_write("Sylva: init GDT...\n"); gdt_init(); diff --git a/kernel/memory/heap.cpp b/kernel/memory/heap.cpp index 5053c7c..92e000a 100644 --- a/kernel/memory/heap.cpp +++ b/kernel/memory/heap.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include struct heap_block { UINTN size; // includes header; bit 0 = 1 used, 0 free diff --git a/kernel/memory/pmm.cpp b/kernel/memory/pmm.cpp index 85ae72a..1ff308f 100644 --- a/kernel/memory/pmm.cpp +++ b/kernel/memory/pmm.cpp @@ -1,5 +1,5 @@ #include -#include +#include extern EFI_SYSTEM_TABLE *ST; diff --git a/kernel/scheduler/scheduler.cpp b/kernel/scheduler/scheduler.cpp index 09a8b64..bce0504 100644 --- a/kernel/scheduler/scheduler.cpp +++ b/kernel/scheduler/scheduler.cpp @@ -1,10 +1,10 @@ -#include -#include -#include +#include +#include +#include #include #include #include -#include +#include // Assembly: context_switch(UINT64* old_rsp, UINT64 new_rsp) extern "C" void context_switch(UINT64* old_rsp, UINT64 new_rsp); diff --git a/kernel/serial.cpp b/kernel/serial.cpp index 4681623..6a327a4 100644 --- a/kernel/serial.cpp +++ b/kernel/serial.cpp @@ -1,4 +1,4 @@ -#include +#include extern EFI_SYSTEM_TABLE *ST;