Add sections debug

This commit is contained in:
Aren Elchinyan 2025-01-16 15:57:55 +03:00
parent 58344a58ba
commit 473a4d8479
9 changed files with 58 additions and 11 deletions

View File

@ -0,0 +1,31 @@
#include "khal.h"
#include <stdint.h>
#include "kstring.h"
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;
int sectons_init() {
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);
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);
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);
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);
memset(&kernel_section_bss_start, 0, &kernel_section_bss_end - &kernel_section_bss_start);
return 1;
}

View File

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

View File

@ -34,11 +34,11 @@ typedef struct {
} reflock_t;
#define NEW_REFLOCK(_on_lock, _on_unlock, _strict, _allow_force) \
{ _on_lock, \
_on_unlock, \
_strict, \
_allow_force, \
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
{ \
_on_lock, _on_unlock, _strict, _allow_force, { \
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
} \
}
void reflock_make(reflock_t *lock);
bool reflock_validate_magic(reflock_t *lock);

View File

@ -4,8 +4,8 @@
#include <stdint.h>
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__)

View File

@ -4,14 +4,18 @@
#include <stdint.h>
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");
int status = multiboot2_init(multiboot2, magic);
sectons_init();
if (status) {
serial_printf("[OK]\n");
} else {

View File

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

View File

@ -83,6 +83,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) {

View File

@ -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);

View File

@ -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 = .;