ソースを参照

feat: load kernel size

greatbridf 2 年 前
コミット
69a9725e1f
4 ファイル変更39 行追加15 行削除
  1. 10 0
      Makefile
  2. 2 0
      include/asm/boot.h
  3. 7 0
      ldscript.ld
  4. 20 15
      src/kernel_main.c

+ 10 - 0
Makefile

@@ -9,10 +9,20 @@ srun: build
 nativerun: build
 	qemu-system-i386 $(QEMU_ARGS) -display none -serial mon:stdio
 
+.PHONY: configure
+configure:
+	cmake -Bbuild -DCMAKE_BUILD_TYPE=Debug
+	cp build/compile_commands.json .
+
 .PHONY: build
 build:
 	cmake --build build --target boot.img
 
+.PHONY: clean
+clean:
+	-rm -rf build
+	-rm compile_commands.json
+
 .PHONY: debug
 debug:
 	gdb --symbols=build/kernel.out --init-eval-command 'target remote:1234' --eval-command 'hbr kernel_main' --eval-command 'c'

+ 2 - 0
include/asm/boot.h

@@ -26,5 +26,7 @@ extern uint8_t asm_e820_mem_map[1024];
 extern uint32_t asm_e820_mem_map_count;
 extern uint32_t asm_e820_mem_map_entry_size;
 
+extern uint32_t kernel_size;
+
 #define e820_mem_map_20 ((struct e820_mem_map_entry_20*)asm_e820_mem_map)
 #define e820_mem_map_24 ((struct e820_mem_map_entry_24*)asm_e820_mem_map)

+ 7 - 0
ldscript.ld

@@ -28,6 +28,9 @@ SECTIONS
 
     .data :
     {
+        kernel_size = .;
+        LONG(ADDR(.kernel_end) - ADDR(.text));
+
         start_ctors = .;
         KEEP(*(.init_array));
         KEEP(*(SORT_BY_INIT_PRIORITY(.init_array*)));
@@ -43,6 +46,10 @@ SECTIONS
         *(.bss*)
     } > WHOLE
 
+    .kernel_end :
+    {
+    } > WHOLE
+
 	/* Stabs debugging sections.  */
     .stab          0 : { *(.stab) }
     .stabstr       0 : { *(.stabstr) }

+ 20 - 15
src/kernel_main.c

@@ -30,6 +30,11 @@ static struct tty* console = NULL;
     snprintf(buf, KERNEL_MAIN_BUF_SIZE, x); \
     tty_print(console, buf)
 
+#define EVE_START(x) printkf(x "... ")
+#define INIT_START(x) EVE_START("initializing " x)
+#define INIT_OK() printkf("ok\n")
+#define INIT_FAILED() printkf("failed\n")
+
 static inline void show_mem_info(char* buf)
 {
     uint32_t mem_size = 0;
@@ -68,6 +73,7 @@ static inline void show_mem_info(char* buf)
                 e820_mem_map_24[i].acpi_extension_attr);
         }
     }
+    printkf("kernel size: %x\n", kernel_size);
 }
 
 static inline void check_a20_status(void)
@@ -104,30 +110,29 @@ void kernel_main(void)
 
     show_mem_info(buf);
 
+    INIT_START("paging");
     init_paging();
-    printkf("Paging enabled\n");
+    INIT_OK();
 
+    INIT_START("SSE");
     asm_enable_sse();
-    printkf("SSE enabled\n");
-
-    {
-        char test_sse[KERNEL_MAIN_BUF_SIZE] = { 0 };
-    }
-    printkf("SSE tested\n");
+    INIT_OK();
 
+    INIT_START("IDT");
     init_idt();
     init_pit();
-    printkf("IDT initialized\n");
+    INIT_OK();
 
-    printkf("initializing heap space... ");
+    INIT_START("heap space");
     if (init_heap() != GB_OK) {
-        printkf("failed\n");
+        INIT_FAILED();
         halt_on_init_error();
     }
-    printkf("ok\n");
+    INIT_OK();
 
+    INIT_START("C++ global objects");
     call_constructors_for_cpp();
-    printkf("C++ global objects constructed\n");
+    INIT_OK();
 
     printkf("Testing k_malloc...\n");
     char* k_malloc_buf = (char*)k_malloc(sizeof(char) * 128);
@@ -136,12 +141,12 @@ void kernel_main(void)
     // vga_printk(k_malloc_buf, 0x0fu);
     k_free(k_malloc_buf);
 
-    printkf("initializing serial ports... ");
+    INIT_START("serial ports");
     int result = init_serial_port(PORT_SERIAL0);
     if (result == 0) {
-        printkf("ok\n");
+        INIT_OK();
     } else {
-        printkf("failed\n");
+        INIT_FAILED();
     }
 
     void* kernel_stack = k_malloc(KERNEL_STACK_SIZE);