I'm trying to make a small OS. So I wrote my bootloader that change to 32 protected mode and loads the kernel.
But when I try to print a string to the screen it only prints the first two characters and that's it. And when I try to print only single chars it works fine...
The OSDev wiki says that it is due to .rodata section missing in the linker script, but I do have on my script so I either didn't set it up correctly or I did something else wrong.
link.ld
OUTPUT_FORMAT("binary")
ENTRY(_start)
SECTIONS
{
. = 0x1000;
.text BLOCK(4K) : ALIGN(4K)
{
*(.text.prologue)
*(.text)
}
.rodata BLOCK(4K) : ALIGN(4K)
{
*(.rodata*)
}
.data BLOCK(4K) : ALIGN(4K)
{
*(.data)
}
.bss BLOCK(4K) : ALIGN(4K)
{
*(.bss)
}
end = .;
}
kernel.c
void main(){
volatile char* video_memory = (volatile char*)0xb8000;
const char* str = "hello, world!\0";
while(*str != 0){
*video_memory++ = *str++;
*video_memory++ = 0x0a;
}
}
As I said, when I run this it only prints "he" in light green and that's it.
The video mode is vga 80x25 text mode.
------------------------ EDIT --------------------------------
I tried this linker script that I found online and it worked!
ENTRY(_start) OUTPUT_FORMAT("binary")
phys = 0x001000;
SECTIONS
{
. = phys;
.entry : { __entry_start = .; *(.entry) }
.text : { __text_start = .; *(.text) }
.data : { __data_start = .; *(.data) }
.rodata : { __rodata_start = .; *(.rodata) }
.bss : { __bss_start = .; *(.bss) }
__end = .;
}
But I don't know why this one worked and the other one didn't, so can anyone explain it to me?