My environment: A home rolled bootloader, MinGW's GCC and ld (compiling the C++ kernel into a PE format), and nasm (assembling my stage2 into elf format). Running inside of VirtualBox.
My problem: In my kernel, I am trying to write text to the screen by writing to video memory. I can do this in a kputch function, and my kcls function also works. But when I try to pass a C-style string into a kprintf function, my kernel won't boot - it'll load into memory (as far as I can tell), but nothing will execute.
Here's the code from the kernel, and my linker.ld file. I'll be more than happy to upload my stage2 code as well if needed.
kernel.cpp
Code: Select all
extern "C" {void kmain();}
void kputch(const char str);
void kprintf(const char* strptr);
void kcls();
void kmain()
{
kcls();
kputch('A');
//kprintf("Hello World."); // *****Uncomment this to break the kernel
}
void kputch(const char chr)
{
char* vramptr = (char*)0xB8000;
*vramptr = chr;
vramptr++;
*vramptr = 0x7;
}
void kprintf(const char* strptr)
{
while (*strptr != 0)
{
kputch(*strptr);
strptr++;
}
}
Code: Select all
OUTPUT_FORMAT("pe-i386")
ENTRY(KSTART)
SECTIONS
{
.text 0x100000 : {
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data : {
data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
Thank you for any advice you can offer me!