i am facing a problem that every time i print text on the screen it is not displayed correctly.
my kernel is in C and i am using GRUB Bootloader
my code:-
kernel.c
Code: Select all
void outportb(unsigned port, unsigned val);
unsigned inportb(unsigned port);
void k_clear_screen();
void update_cursor(int row, int col);
char get_ascii( char sc);
void write_string(int colour, const char *string);
//----------------------------------------------------------------
void kmain()//**main function**
{
k_clear_screen();
update_cursor(0,0);
write_string(7,"Hello World");
}
void write_string(int colour, const char *string)
{
volatile char *video=(volatile char*)0xB8000;
while(*string!=0)
{
*video=*string;
string++;
video++;
*video=colour;
video++;
}
}
//-------------------------------------------------------------------------------------
char get_ascii( char sc){
if(sc==1)
return 27;//esc
else if(sc==2)
return '1';
else if(sc==3)
return '2';
else if(sc==4)
return '3';
else if(sc==5)
return '4';
else if(sc==6)
return '5';
else if(sc==7)
return '6';
else if(sc==8)
return '7';
else if(sc==9)
return '8';
else if(sc==10)
return '9';
else if(sc==11)
return '0';
//-----------------------------
return 0;
}
void update_cursor(int row, int col)
{
unsigned short position=(row*80) + col;
// cursor LOW port to vga INDEX register
outportb(0x3D4, 0x0F);
outportb(0x3D5, (unsigned char)(position&0xFF));
// cursor HIGH port to vga INDEX register
outportb(0x3D4, 0x0E);
outportb(0x3D5, (unsigned char )((position>>8)&0xFF));
}
void k_clear_screen()
{
char* vidmem = (char*) 0xb8000;
unsigned int i=0;
while(i<(80*2*25))
{
vidmem[i] = ' ';
++i;
vidmem[i] = 0x07;
++i;
};
};
unsigned inportb(unsigned port)
{
unsigned ret_val;
asm volatile ("inb %w1,%b0" : "=a"(ret_val) : "d"(port));
return ret_val;
}
void outportb(unsigned port, unsigned val)
{
asm volatile ("outb %b0,%w1" : : "a"(val), "d"(port));
}
i am using GCC Complier
Kernel format is PE