OSDev.org
https://forum.osdev.org/

[Solved] I can't read from video memory.
https://forum.osdev.org/viewtopic.php?f=1&t=56246
Page 1 of 1

Author:  tn [ Fri Apr 22, 2022 10:22 am ]
Post subject:  [Solved] I can't read from video memory.

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:
    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:
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.

Author:  Octocontrabass [ Fri Apr 22, 2022 12:00 pm ]
Post subject:  Re: I can't read from video memory.

tn wrote:
Code:
    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:
write_string(0x1F, "hello world", 0);

If this code doesn't work, you most likely have a problem with your bootloader or linker script.

Author:  tn [ Fri Apr 22, 2022 12:54 pm ]
Post subject:  Re: I can't read from video memory.

I'm sorry, but probably we don't understand each other, beacouse these two lines doesnt work:
Code:
    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.

Author:  Octocontrabass [ Fri Apr 22, 2022 12:58 pm ]
Post subject:  Re: I can't read from video memory.

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:
write_string(0x1F, "hello world", 0);

If this line doesn't work, the problem is most likely in your bootloader or your linker script.

Author:  tn [ Fri Apr 22, 2022 1:05 pm ]
Post subject:  Re: I can't read from video memory.

No, this line you wrote don't work.

these are lines in makefile, where I link kernel:
Code:
kernel.bin: kernel-entry.o kernel.o
        ld -m elf_i386 -o $@ -Ttext 0x1000 $^ --oformat binary

Author:  Octocontrabass [ Fri Apr 22, 2022 1:10 pm ]
Post subject:  Re: I can't read from video memory.

It looks like your bootloader does not load your kernel correctly.

Make sure your bootloader loads enough sectors from the disk.

Author:  tn [ Fri Apr 22, 2022 1:16 pm ]
Post subject:  Re: I can't read from video memory.

Thank's, you're right. My bootloader loaded only 2 sectors and not the whole kernel.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/