Page 1 of 1

[Solved] I can't read from video memory.

Posted: Fri Apr 22, 2022 10:22 am
by tn
I have my os with custom bootloader. When I try to read from video memory (0xb8000) in vga 80x25 mode, it will not work.
Main function:

Code: Select all

    char string[] = "hello world";
    write_string(0x1F, string, 0);
[b]    char first_char = get_one_char(0);
    char second_char = get_one_char(2)[/b]

Code: Select all

void write_string(int color, char *string, int offset)
{
    int i = 0;
    while(string[i] != 0){
        write_char(color, string[i], offset);
        i++;
        offset +=2;
    }
}
char get_one_char(int offset){
    volatile char *vid = (volatile char *) 0xb8000;
    return vid[offset];

}
On the screen, there isn't any text, but if I remove these two lines, everything is normal.

I'm testing it in Qemu.


I'm sorry for my bad english.

Re: I can't read from video memory.

Posted: Fri Apr 22, 2022 12:00 pm
by Octocontrabass
tn wrote:

Code: Select all

    char string[] = "hello world";
    write_string(0x1F, string, 0);
Is there a reason why you can't pass a string literal to write_string? Like this:

Code: Select all

write_string(0x1F, "hello world", 0);
If this code doesn't work, you most likely have a problem with your bootloader or linker script.

Re: I can't read from video memory.

Posted: Fri Apr 22, 2022 12:54 pm
by tn
I'm sorry, but probably we don't understand each other, beacouse these two lines doesnt work:

Code: Select all

    char first_char = get_one_char(0);
    char second_char = get_one_char(2);
Without these lines my code work perfectly, but with it it doesn't. Without it it write "Hello world" and with it the screen is black and start blinking.

Anyways, thank's for your help.

Re: I can't read from video memory.

Posted: Fri Apr 22, 2022 12:58 pm
by Octocontrabass
I understand that those two lines don't work. The problem is not in the code you posted.

I am asking if this line works:

Code: Select all

write_string(0x1F, "hello world", 0);
If this line doesn't work, the problem is most likely in your bootloader or your linker script.

Re: I can't read from video memory.

Posted: Fri Apr 22, 2022 1:05 pm
by tn
No, this line you wrote don't work.

these are lines in makefile, where I link kernel:

Code: Select all

kernel.bin: kernel-entry.o kernel.o
        ld -m elf_i386 -o $@ -Ttext 0x1000 $^ --oformat binary

Re: I can't read from video memory.

Posted: Fri Apr 22, 2022 1:10 pm
by Octocontrabass
It looks like your bootloader does not load your kernel correctly.

Make sure your bootloader loads enough sectors from the disk.

Re: I can't read from video memory.

Posted: Fri Apr 22, 2022 1:16 pm
by tn
Thank's, you're right. My bootloader loaded only 2 sectors and not the whole kernel.