Please help with vsprintf & putch

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
nutraageous

Please help with vsprintf & putch

Post 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.
mystran

Re:Please help with vsprintf & putch

Post 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().
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Please help with vsprintf & putch

Post 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 ....
nutraageous

Re:Please help with vsprintf & putch

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Please help with vsprintf & putch

Post 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 ...
Post Reply