Page 1 of 1

Please help with vsprintf & putch

Posted: Thu Jul 24, 2003 6:29 pm
by nutraageous
Hello,

Currently I am using Grub to load my kernel from fd0. I was working on trying to get my printf to work but I get no output on the screen. However I was successful in getting output using this:

Code: Select all

   char *vm = (char *) 0x000b8000;
   *vm = 'y';
   *(vm+2) = 'o';
With the following code, however, I was unable to get any output:

kprintf:

Code: Select all

static char printbuf[1024];
static int kprintf(const char *fmt, ...)
{
   va_list args;
   int i;

   va_start(args, fmt);
        vsprintf(printbuf, fmt, args);
   va_end(args);

   while(printbuf[i] != '\0')
       putchar(printbuf[i++]);   
   
   return i;
}
putchar:

Code: Select all

void putchar(char c)
{
   static int xAxis = 0;
   static int yAxis = 0;

        char *gfx = (char *) 0x000b8000;

   if (xAxis > 80)
   {
      xAxis = 0;
     ++yAxis;
        }

   long Offset = ((((yAxis - 1) * 80) + xAxis) * 2);

   gfx[Offset] = c;
        ++xAxis;
}
And the vsprintf was used from the linux 0.01 kernel. Please view it here: http://home.ntelos.net/~nutrageous/vsprintf.c


And in KernelMain I have:

Code: Select all

void KernelMain (struct multibootinfo *mbi)
{
   kprintf("bah bleh blah"); 

/* This works...
*  
*  char *vm = (char *) 0x000b8000;
*  *vm = 'y';
*  *(vm+2) = 'o';
*
*/ 
  while (1);
} 
Any help will be appreciated.

Re:Please help with vsprintf & putch

Posted: Thu Jul 24, 2003 10:52 pm
by mystran
Assuming that there's nothing in the text-mode video memory, you are only copying characters, not attributes.. so it might just as well work, but output black on black which you can't see.

Add something like gfx[Offset + 1] = 0x07; in putchar()..
Also.. you might want to test putchar directly first, in case the problem is with the kprintf().

Re:Please help with vsprintf & putch

Posted: Fri Jul 25, 2003 12:58 am
by Pype.Clicker
also, you should make sure you have your "blah" string in your kernel ... did you get a look at your file using an hex editor ? this is a common error ....

Re:Please help with vsprintf & putch

Posted: Fri Jul 25, 2003 6:03 am
by nutraageous
Thanks guys I discovered my problem to be in the calculations of the offsets. I had a something similar to: (yAxis * 80 * 2) + (xAxis * 2) but the parenthesis were placed differently! :D


Thanks for the help

Re:Please help with vsprintf & putch

Posted: Fri Jul 25, 2003 10:51 am
by Pype.Clicker
hmm, yeah, for sure, initializing Yaxis=0 and then using Yaxis-1 was not a good idea to get the expected result ...