OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:49 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [Solved] I can't read from video memory.
PostPosted: Fri Apr 22, 2022 10:22 am 
Offline

Joined: Fri Apr 22, 2022 10:01 am
Posts: 7
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.


Last edited by tn on Fri Apr 22, 2022 1:19 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: I can't read from video memory.
PostPosted: Fri Apr 22, 2022 12:00 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.


Top
 Profile  
 
 Post subject: Re: I can't read from video memory.
PostPosted: Fri Apr 22, 2022 12:54 pm 
Offline

Joined: Fri Apr 22, 2022 10:01 am
Posts: 7
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.


Top
 Profile  
 
 Post subject: Re: I can't read from video memory.
PostPosted: Fri Apr 22, 2022 12:58 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.


Top
 Profile  
 
 Post subject: Re: I can't read from video memory.
PostPosted: Fri Apr 22, 2022 1:05 pm 
Offline

Joined: Fri Apr 22, 2022 10:01 am
Posts: 7
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


Top
 Profile  
 
 Post subject: Re: I can't read from video memory.
PostPosted: Fri Apr 22, 2022 1:10 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
It looks like your bootloader does not load your kernel correctly.

Make sure your bootloader loads enough sectors from the disk.


Top
 Profile  
 
 Post subject: Re: I can't read from video memory.
PostPosted: Fri Apr 22, 2022 1:16 pm 
Offline

Joined: Fri Apr 22, 2022 10:01 am
Posts: 7
Thank's, you're right. My bootloader loaded only 2 sectors and not the whole kernel.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Amazonbot [bot] and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group