Got some problems while running the kernel
Posted: Tue Feb 04, 2014 2:29 am
I'm just trying to build the os these few months
This is the kernel.c of my os and kstdio.c which provide the kprint functions
but some string is not printed out like this:
The last line is "\n->--------->" but it can't show the whole string
Whats things I did wrong ?
This is the kernel.c of my os and kstdio.c which provide the kprint functions
Code: Select all
#include "kernel.h"
#include "kstdio.h"
#include "io.h"
#define WHITE_TXT 0x0B //white on black text
#define GRAY_TXT 0x07 //gray on black text
#define SRC_HEIGHT 640
#define SRC_WIDTH 480
#define COM_DATE "31/01/2014" //Compiling Date
int k_main(void)
{
kclrscr();
kprint("MMMMMMMMMMMMMYYYYYYYYYY Operating System\nProtected Mode process ...\n");
kprint("First prototype - Sebastian Ko \n");
kprint("\nDate : ");kprint(COM_DATE);kprint("\n");
kprintc("\nNO \\t or value type \n",GRAY_TXT);
kprint("Register checking ... ");
if(reg() == 0)kprintc("OK\n",GRAY_TXT);
else kprintc("Fail\n",GRAY_TXT);
kprint("\n->--------->");
}
int reg()
{
int no = 100; //Test asm output
__asm__ __volatile__("movl %0, %%ebx" :: "r" (no): "%ebx"); //add to ebx
no = 0;
__asm__ __volatile__("movl %%ebx, %0" :"=r"(no):: "%ebx"); //get back
if(no == 100)return 0;
return 1;
}
Code: Select all
#include "kstdio.h"
#include "kernel.h"
/*********************
Printing Method
*********************/
unsigned int line = 0; //Line in screen (Text)
unsigned int text_pos = 0; //Text position
//Easiest print method
void kprint(char *message){kprintc(message,0x0B);};
void kprintc(char *message,unsigned int text_color) //Print with change default color
{
char *vidmem = (char *) 0xb8000; //define video memory
unsigned int i = 0; //define memory position
i=((line*80*2)+(text_pos*2)); //Memory MUST be line * colume * TxtSpace (160 Means Over Screen of line,line++)
while(*message!=0)
{
if(line > CONSOLE_MAX_LINE)line = 0;
//\n \r \t is 1 char
if(*message == '\n') //Check for a new line
{
text_pos = 0; //reset text position
line++;
i=(line*80*2);
message++;
}else if(*message == '\r'){ //Return to head from line
text_pos = 0; //reset text position
i = (line*80*2);
message++;
}else{ //print Message (Char)
vidmem[i]=*message;
message++;
i++;
vidmem[i]=text_color;
i++;
text_pos++;
}
}
};
void kclrscr() // clear the entire text screen
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
while(i < (80*CONSOLE_MAX_LINE*2))
{
vidmem[i]=' ';
i++;
vidmem[i]=0x00;
i++;
}
line = 0;
};
Whats things I did wrong ?