VGA doesn't print

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.
Post Reply
shervingav
Posts: 11
Joined: Sun May 11, 2014 6:19 am
Location: Iran

VGA doesn't print

Post by shervingav »

ok, so i coded my semi-working os with getting help from bare bones and Brandon F. 's kernel tutorial and i have a little problem,
my problem is that when i run my kernel.iso (in qemu) the os is supposed to clear the screen and print the char 'C' to the screen on 0xb8000,
but when i run it, nothing happens and i have a blinking cursor, and when i hold Alt+Ctrl+2 and when i type xp from 0xb8000 to 0xb8009
i see the following:

Code: Select all

xp 0xb8000 
00000000000b8000: 0x07200720
xp 0xb8001 
00000000000b8001: 0x20072007
xp 0xb8002 
00000000000b8002: 0x07200720
xp 0xb8003 
00000000000b8003: 0x20072007
xp 0xb8004 
00000000000b8004: 0x07200720
xp 0xb8005 
00000000000b8005: 0x20072007
xp 0xb8006 
00000000000b8006: 0x07200720
xp 0xb8007 
00000000000b8007: 0x20072007
xp 0xb8008
00000000000b8008: 0x07200720
xp 0xb8009 
00000000000b8009: 0x20072007
and after a minute or so when i check them again, all of them are set to 0.
these are the code i use for vga:

Code: Select all

void kmain(void)
{
	init_video();
	putch('C');
        for (;;);
}
and this is my vga structure:

Code: Select all

struct {
	uint16 *textmemptr;
	uint16 attrib;
	uint16 csr_x ,csr_y;
}VGA;
and these are my putch() and init_video() functions

Code: Select all

void scroll()
{
    uint16 blank, temp;
    blank = 0x20 | (VGA.attrib << 8);
    if(VGA.csr_y >= 25)
    {
        temp = VGA.csr_y - 25 + 1;
        memcpyw (VGA.textmemptr, VGA.textmemptr + temp * 80, (25 - temp) * 80 * 2);
        memsetw (VGA.textmemptr + (25 - temp) * 80, blank, 80);
        VGA.csr_y = 25 - 1;
    }
}
void move_csr()
{
    uint8 temp;
    temp = VGA.csr_y * 80 + VGA.csr_x;
    outportb(0x3D4, 14);
    outportb(0x3D5, temp >> 8);
    outportb(0x3D4, 15);
    outportb(0x3D5, temp);
}

void cls()
{
    uint16 blank;
    int i;
    blank = 0x20 | (VGA.attrib << 8);
    for(i = 0; i < 25; i++)
        memsetw (VGA.textmemptr + i * 80, blank, 80);
    VGA.csr_x = 0;
    VGA.csr_y = 0;
    move_csr();
}

void putch(uint8 c)
{
    uint16 *where;
    uint16 att = VGA.attrib << 8;
    if(c == 0x08)
    {
        if(VGA.csr_x != 0) VGA.csr_x--;
    }
    else if(c == 0x09)
    {
        VGA.csr_x = (VGA.csr_x + 8) & ~(8 - 1);
    }
    else if(c == '\r')
    {
        VGA.csr_x = 0;
    }
    else if(c == '\n')
    {
        VGA.csr_x = 0;
        VGA.csr_y++;
    }
    else if(c >= ' ')
    {
        where = VGA.textmemptr + (VGA.csr_y * 80 + VGA.csr_x);
        *where = c | att;
        VGA.csr_x++;
    }
    if(VGA.csr_x >= 80)
    {
        VGA.csr_x = 0;
        VGA.csr_y++;
    }

    scroll();
    move_csr();
}
void init_video()
{
    VGA.textmemptr = (uint16 *)0xb8000;
    VGA.attrib = 0x0F;
	VGA.csr_x = 0;
	VGA.csr_y = 0;
	cls();
}
"Sometimes it is the people who no one imagines anything of, who do the things that no one can IMAGINE."
_Alan Turing
User avatar
ScropTheOSAdventurer
Member
Member
Posts: 86
Joined: Sun Aug 25, 2013 5:47 pm
Location: Nebraska, USA

Re: VGA doesn't print

Post by ScropTheOSAdventurer »

A disassembly of your putch function could be helpful. In addition, could you provide your mem* functions? Your letters might be getting erased by a mem* function being bad.
"Procrastination is the art of keeping up with yesterday."
no92
Member
Member
Posts: 307
Joined: Wed Oct 30, 2013 1:57 pm
Libera.chat IRC: no92
Location: Germany
Contact:

Re: VGA doesn't print

Post by no92 »

Looks okay for me, do you get any warnings thrown by gcc/clang?

BTW, there's no need in looping in the main C sources, as this is done by assembly:

Code: Select all

jmp $
shervingav
Posts: 11
Joined: Sun May 11, 2014 6:19 am
Location: Iran

Re: VGA doesn't print

Post by shervingav »

ScropTheOSAdventurer wrote:A disassembly of your putch function could be helpful. In addition, could you provide your mem* functions? Your letters might be getting erased by a mem* function being bad.
ok my mem functions are as follows:

Code: Select all

uint8 *memcpy(uint8 *dest, const uint8 *src, int count)
{
    int i = 0;
start_cpy:
    *(dest+i) = *(src+i);
    i = i + 1;
    if (i < count)
       goto start_cpy;
    return dest;
}
uint16 *memcpyw(uint16 *dest, const uint16 *src, int count)
{
    int i = 0;
start_cpy1:
    *(dest+i) = *(src+i);
    i = i + 1;
    if (i < count)
       goto start_cpy1;
    return dest;
}

uint8 *memset(uint8 *dest, uint8 val, int count)
{
    int i = 0;
start_set:
    *(dest+i) = val;
    i = i + 1;
    if (i < count)
	goto start_set;
    return dest;
}

uint16 *memsetw(uint16 *dest, uint16 val, int count)
{
    int i = 0;
start_set1:
    dest[i] = val;
    i = i + 1;
    if (i < count)
	goto start_set1;
    return dest;
}
A disassembly of your putch function could be helpful.
I am a beginner and i dont know how to disassmble my putch func + what does disassemble mean?? reversing the code from bin to asm??
Looks okay for me, do you get any warnings thrown by gcc/clang?
no i dont.
Last edited by shervingav on Tue May 27, 2014 3:04 am, edited 2 times in total.
"Sometimes it is the people who no one imagines anything of, who do the things that no one can IMAGINE."
_Alan Turing
shervingav
Posts: 11
Joined: Sun May 11, 2014 6:19 am
Location: Iran

Re: VGA doesn't print

Post by shervingav »

I have encountered another problem:
in start.asm there was this code(just a part of it):

Code: Select all

global _start
_start:
    mov esp, _sys_stack
	mov dx,0x3c0 ;for setting the text mode : 80x25
	mov al,0x10 ;for setting the text mode : 80x25
	out dx,al ;for setting the text mode : 80x25
	mov al,0x0c ;for setting the text mode : 80x25
	out dx,al ;for setting the text mode : 80x25
    jmp stublet
and when i removed the part for setting the text mode my os just crashes!! why??
"Sometimes it is the people who no one imagines anything of, who do the things that no one can IMAGINE."
_Alan Turing
shervingav
Posts: 11
Joined: Sun May 11, 2014 6:19 am
Location: Iran

Re: VGA doesn't print

Post by shervingav »

HAHAHAHAHHAHAHAHAHA!
i solved it. my file architectures where not right my nasm was 64 bit and that messed up my kernel.
ty all.
"Sometimes it is the people who no one imagines anything of, who do the things that no one can IMAGINE."
_Alan Turing
Post Reply