Reputation: 468
I'm currently writing a custom kernel. I've remarked that none of my declared global variables gets initialized to the correct values. Here's an example :
#include <tty.h>
#include <gdt.h>
#include <idt.h>
uint8_t name = 0x45;
void kernel_main() {
terminal_init();
terminal_clear();
terminal_write_string("\nWelcome to los kernel.\n\n");
terminal_write_string("(Kernel info) : TTY Loaded\n");
gdt_reload();
terminal_write_string("(Kernel info) : GDT installed\n");
idt_install();
terminal_write_string("(Kernel info) : IDT installed\n");
terminal_write_hex(name);
}
Last line is expected to print the hex "0x45" but I get "0x0". The same happens when I try to get string from global string array.
Here are my gcc compilation flags -ffreestanding -m32 -fno-pie -Wall -Wextra -g -I$(KERNEL_INC_DIR) -masm=intel -std=gnu17
What can I do please? Regards
Edit 1 The same happens here :
/* To print the message which defines every exception */
const char* _messages[] = {
"Division By Zero",
"Debug",
"Non Maskable Interrupt",
"Breakpoint",
"Into Detected Overflow",
"Out of Bounds",
"Invalid Opcode",
"No Coprocessor",
"Double Fault",
"Coprocessor Segment Overrun",
"Bad TSS",
"Segment Not Present",
"Stack Fault",
"General Protection Fault",
"Page Fault",
"Unknown Interrupt",
"Coprocessor Fault",
"Alignment Check",
"Machine Check",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved"
};
void isr_handler(ISRStack stack) {
terminal_write_string("Interrupt ");
terminal_write_hex(stack.id);
terminal_write_string(" : ");
terminal_write_string(_messages[stack.id]);
terminal_write_string("\n");
// Hang if it is an exception
if (stack.id < 32) while (1);
}
Unless I put the _messages
array declaration in local scope, it just get filled with 0 when I check it with gdb.
Upvotes: 0
Views: 119
Reputation: 620
As discussed in the comments above:
You are using your own bootloader. In it you specify how many sectors have to be loaded from disk. When you aren't loading enough sectors it could be that only a partial kernel is ran. If you're lucky not much crashes (As in your situation) since the .text section is completely copied. If you're unlucky you get into a bootloop. Your exact problem is that you're not loading the .data section completely from disk. Good luck developing your kernel :D
Upvotes: 1