diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 5a60709..eefcd68 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -24,3 +24,11 @@ jobs: run: make - name: run and test run: make clean && make && make test + - name: Versions + run: | + make -v + gcc -v + clang-format --version + xorriso --version + qemu-system-x86_64 -version + grub-mkrescue --version diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 638ab75..7546b94 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -84,6 +84,14 @@ jobs: make clean make make test + - name: Versions + run: | + make -v + gcc -v + clang-format --version + xorriso --version + qemu-system-x86_64 -version + grub-mkrescue --version - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 diff --git a/kernel/arch/amd64/sections.c b/kernel/arch/amd64/sections.c new file mode 100644 index 0000000..a087b3b --- /dev/null +++ b/kernel/arch/amd64/sections.c @@ -0,0 +1,51 @@ +#include "khal.h" +#include "kstring.h" +#include + +extern uint64_t kernel_section_text_start; +extern uint64_t kernel_section_text_end; +extern uint64_t kernel_section_rodata_start; +extern uint64_t kernel_section_rodata_end; +extern uint64_t kernel_section_data_start; +extern uint64_t kernel_section_data_end; +extern uint64_t kernel_section_bss_start; +extern uint64_t kernel_section_bss_end; + +typedef struct { + uint64_t start; + uint64_t end; +} sections_t; + +sections_t kernel_sections[4]; + +sections_t *sectons_init() { + // Why this halts cpu? + //memset(&kernel_section_bss_start, 0, + // (uint64_t)&kernel_section_bss_end - + // (uint64_t)&kernel_section_bss_start); + serial_printf("\t.text 0x%x-0x%x(%u)\n", &kernel_section_text_start, + &kernel_section_text_end, + &kernel_section_text_end - &kernel_section_text_start); + kernel_sections[0] = + (sections_t){ kernel_section_text_start, kernel_section_text_end }; + + serial_printf("\t.rodata 0x%x-0x%x(%u)\n", &kernel_section_rodata_start, + &kernel_section_rodata_end, + &kernel_section_rodata_end - &kernel_section_rodata_start); + kernel_sections[1] = + (sections_t){ kernel_section_rodata_start, kernel_section_rodata_end }; + + serial_printf("\t.data 0x%x-0x%x(%u)\n", &kernel_section_data_start, + &kernel_section_data_end, + &kernel_section_data_end - &kernel_section_data_start); + kernel_sections[2] = + (sections_t){ kernel_section_data_start, kernel_section_data_end }; + + serial_printf("\t.bss 0x%x-0x%x(%u)\n", &kernel_section_bss_start, + &kernel_section_bss_end, + &kernel_section_bss_end - &kernel_section_bss_start); + kernel_sections[3] = + (sections_t){ kernel_section_bss_start, kernel_section_bss_end }; + + return (sections_t *)&kernel_sections; +} \ No newline at end of file diff --git a/kernel/arch/amd64/serial.c b/kernel/arch/amd64/serial.c index bb7ff4b..1085573 100644 --- a/kernel/arch/amd64/serial.c +++ b/kernel/arch/amd64/serial.c @@ -3,7 +3,8 @@ void serial_write_byte(uint8_t byte) { // Wait until the transmit holding register is empty - while ((inb(0x3f8 + 5) & 0x20) == 0); + while ((inb(0x3f8 + 5) & 0x20) == 0) + ; outb(0x3f8, byte); } diff --git a/kernel/include/sys/panic.h b/kernel/include/sys/panic.h index 68cae99..db6dd91 100644 --- a/kernel/include/sys/panic.h +++ b/kernel/include/sys/panic.h @@ -4,8 +4,8 @@ #include void __attribute__((noreturn)) panic_int(uint8_t int_no, const char *msg); -void __attribute__((noreturn)) panic(const char *msg, const char *func, - const int line); +void __attribute__((noreturn)) +panic(const char *msg, const char *func, const int line); #define PANIC(msg) panic(msg, __func__, __LINE__) diff --git a/kernel/kernel.c b/kernel/kernel.c index d8349e1..531d627 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -4,9 +4,11 @@ #include int multiboot2_init(uint64_t *addr, uint32_t magic); +int sectons_init(); void kernel_main64(uint64_t *multiboot2, uint32_t magic, void *esp, uint64_t base) { + sectons_init(); serial_init(); serial_printf(":D\n"); diff --git a/kernel/klibc/string.c b/kernel/klibc/string.c index 15bf75e..51c0846 100644 --- a/kernel/klibc/string.c +++ b/kernel/klibc/string.c @@ -87,7 +87,8 @@ int memcmp(const void *ptr1, const void *ptr2, size_t count) { size_t __attribute__((pure)) strlen(const char *s) { int i; - for (i = 0; s[i] != '\0'; i++); + for (i = 0; s[i] != '\0'; i++) + ; return i; } diff --git a/kernel/multiboot2.c b/kernel/multiboot2.c index 338aeec..12f8e24 100644 --- a/kernel/multiboot2.c +++ b/kernel/multiboot2.c @@ -108,6 +108,8 @@ void handle_basic_load_base_addr(struct multiboot_tag *tag) { (struct multiboot_tag_load_base_addr *)tag; serial_printf("load_base_size: %u\n", base_addr->size); serial_printf("load_base_addr: 0x%x\n", base_addr->load_base_addr); + serial_printf("Kernel: 0x%x-0x%x\n", base_addr->load_base_addr, + base_addr->load_base_addr + base_addr->size); } void handle_mmap_tag(struct multiboot_tag *tag) { diff --git a/kernel/sys/panic.c b/kernel/sys/panic.c index 04ccc16..d98da8b 100644 --- a/kernel/sys/panic.c +++ b/kernel/sys/panic.c @@ -15,8 +15,8 @@ void __attribute__((noreturn)) panic_int(uint8_t int_no, const char *msg) { for (;;) cpu_halt(); } -void __attribute__((noreturn)) panic(const char *msg, const char *func, - const int line) { +void __attribute__((noreturn)) +panic(const char *msg, const char *func, const int line) { cpu_interrupt_lock_acquire(); serial_printf("\n\rKernel panic - %s in %s:%d\n", msg, func, line); diff --git a/scripts/linker.ld b/scripts/linker.ld index 92a384d..2e0b079 100644 --- a/scripts/linker.ld +++ b/scripts/linker.ld @@ -6,30 +6,38 @@ SECTIONS{ phys = .; .text BLOCK(4K) : ALIGN(4K) { + PROVIDE(kernel_section_text_start = .); *(.multiboot) *(.bootstrap) code = .; *(.text) + PROVIDE(kernel_section_text_end = .); } .rodata BLOCK(4K) : ALIGN(4K) { + PROVIDE(kernel_section_rodata_start = .); *(.rodata) + PROVIDE(kernel_section_rodata_end = .); } .data BLOCK(4K) : ALIGN(4K) { + PROVIDE(kernel_section_data_start = .); data = .; *(.data) *(.symbols) PROVIDE(kernel_symbols_start = .); PROVIDE(kernel_symbols_end = .); + PROVIDE(kernel_section_data_end = .); } .bss BLOCK(4K) : ALIGN(4K) { + PROVIDE(kernel_section_bss_start = .); PROVIDE(bss_start = .); bss = .; *(COMMON) *(.bss) *(.stack) + PROVIDE(kernel_section_bss_end = .); } end = .;