Page 1 of 1

qemu vga prrinting character problem in different .o file

Posted: Mon Apr 21, 2014 4:37 am
by 0xnlbs
HI! All
I came from application programming using C/C++ (never coded an OS kernel or bootloader or any such low level work before)

I was following the guide http://www.cs.bham.ac.uk/~exr/lectures/ ... os-dev.pdf
and http://www.osdever.net/bkerndev/Docs/title.htm and osdev.org for sure

The bootloader is working. Though I didn't understad why code and data segment starts fom the same address in GDT
I've a kmain function that is being called after it enters in 32 bit mode. from inside kmain I can print to video memory on 0xb8000 with no issues.

I made another .c for portio(port_byte_in, port_byte_out, port_word_in, port_word_out) and screen(screen_clear, screen_putc ....)

when I call these

Code: Select all

screen_putc
from kmain it doesn't work sometimes when there is some function call inside scren_putcor when there is any assignment operation in some specific block . I couldn't figure out exactly what causes it not to work.

by doesn't work I mean the character is printed in 32 bit protected mode for once and again it goes back to the black screen of qemu. and shows what I've printed in 16 bit mode using BIOS interrupts

Code: Select all

void screen_cursor_update(unsigned char row, unsigned char col){

}

void screen_putc(unsigned char data, unsigned char color){
	unsigned char* vmem = global_vga_mem;

	if(0x08 == data){
		--global_vga_cursor_x;
	}else if(0x0d == data){
		global_vga_cursor_x = 0;
	}else if(0x0a == data){
		global_vga_cursor_x = 0;
		++global_vga_cursor_y;
	}else{
		*(vmem++) = data;
		*(vmem++) = color;
		++global_vga_cursor_x;
		if(global_vga_cursor_x >= MAX_COLS){
			++global_vga_cursor_y;
		}
	}
	screen_cursor_update(global_vga_cursor_x, global_vga_cursor_y);
}
here If I just comment screen_cursor_update which is an empty function. it works in qemu and displays the character and stays there. but If I uncomment it displays the character once and then comes back

UPDATE

But If I move these functions to the same object file. e.g. If I just copy the contents of screen.c in kernel.c above kmain it works perfectly

Re: qemu vga prrinting character problem in different .o fil

Posted: Mon Apr 21, 2014 6:14 am
by Combuster
Mixing tutorials is generally a bad idea. The bigger problem is however that mr. Lecturer doesn't even sketch on how to use a toolchain properly, nor point out the pitfalls you can typically find in your bootloader. Therefore, the end result is only functional by accident.

I suggest you read at least the FAQ and the Posting Checklist, as they cover at least some of your problems. Thereafter, it might be a good idea to use GRUB as your bootloader and use the Bare Bones tutorial as a starting point without having to deal with all the omissions waiting for a chance to break your code.

Re: qemu vga prrinting character problem in different .o fil

Posted: Mon Apr 21, 2014 11:31 am
by 0xnlbs
I am not mixing different guides. I am just reading all notes. I am following the pdf link only.

But the problem I see appears only when I mix multiple .o files. If I write all functions in same .o it works fine.

This is what I have in my Makefile.

Code: Select all

kernel.bin: kernel_entry.o portio.o screen.o kernel.o
	ld -o $@ -Ttext 0x1000 --oformat binary $^ -melf_i386 
Is the linking process wrong ?

Re: qemu vga prrinting character problem in different .o fil

Posted: Mon Apr 21, 2014 11:43 am
by Combuster
0xnlbs wrote:Is the linking process wrong ?
Combuster wrote:I suggest you read at least the FAQ and the Posting Checklist,
Reading helps :wink:


But seriously, while the guide is certainly educational (as in, it's not wrong and it's got many of the things you should know sometime), the result is far from production worthy. You can either switch to something that is (link already posted), or have fun figuring out all possible causes of bugs on your own. Basically, sticking with a fundamentally flawed starting point is not going to be helpful if what you really want is to just see it work.