Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
tn
Posts: 7 Joined: Fri Apr 22, 2022 10:01 am
Libera.chat IRC: tn
Post
by tn » Fri Apr 22, 2022 10:22 am
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.
Last edited by
tn on Fri Apr 22, 2022 1:19 pm, edited 1 time in total.
Octocontrabass
Member
Posts: 5563 Joined: Mon Mar 25, 2013 7:01 pm
Post
by Octocontrabass » Fri Apr 22, 2022 12:00 pm
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.
tn
Posts: 7 Joined: Fri Apr 22, 2022 10:01 am
Libera.chat IRC: tn
Post
by tn » Fri Apr 22, 2022 12:54 pm
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.
Octocontrabass
Member
Posts: 5563 Joined: Mon Mar 25, 2013 7:01 pm
Post
by Octocontrabass » Fri Apr 22, 2022 12:58 pm
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.
tn
Posts: 7 Joined: Fri Apr 22, 2022 10:01 am
Libera.chat IRC: tn
Post
by tn » Fri Apr 22, 2022 1:05 pm
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
Octocontrabass
Member
Posts: 5563 Joined: Mon Mar 25, 2013 7:01 pm
Post
by Octocontrabass » Fri Apr 22, 2022 1:10 pm
It looks like your bootloader does not load your kernel correctly.
Make sure your bootloader loads enough sectors from the disk.
tn
Posts: 7 Joined: Fri Apr 22, 2022 10:01 am
Libera.chat IRC: tn
Post
by tn » Fri Apr 22, 2022 1:16 pm
Thank's, you're right. My bootloader loaded only 2 sectors and not the whole kernel.