kstdio.c

00001 /***************************************************************************
00002                           kstdio.c  -  description
00003                              -------------------
00004     begin                : Sat Dec 13 2003
00005     copyright            : (C) 2003 by Dynacube Team
00006     email                : mdshah82@yahoo.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 //Master Header
00019 #include "core/kmaster.h"
00020 
00021 //Generic dlib (Dynacube Lib)
00022 #include "common/string.h"
00023 #include "common/stdarg.h"
00024 #include "common/stdlib.h"
00025 #include "proc/proc.h"
00026 
00027 int row = 0;
00028 int col = 0;
00029 int grow = 0;
00030 int gcol = 0;
00031 
00032 DD gcls_delay = 0x1FFF; //The delay for gcls - to handle GUI Dbgr
00033 
00034 #define NEED_DBG 1
00035 #undef NEED_DBG
00036 
00037 
00038   void printRegs(REGS* regs)
00039   {
00040                 #ifdef __DEBUG__
00041 
00042     printf("\nprintRegs");
00043     printf("\n cur_pid %d int %x ecode %x",cur_pid,regs->which_int,regs->err_code);
00044     printf("\ncs %x ds %x eip %x",regs->cs,regs->ds,regs->eip);
00045     printf("\nes %x fs %x gs %x",regs->es,regs->fs,regs->gs);
00046     printf("\neflag %x u_esp %x u_ss %x",regs->eflags,regs->user_esp, regs->user_ss);
00047     printf("\n_esp %x _ss %x",regs->_esp, regs->_ss);
00048     printf("\nesi %x edi %x",regs->esi,regs->edi);
00049 
00050     #endif
00051   }
00052 
00053 void cls()
00054 {
00055  #ifdef __DEBUG__       
00056  unsigned char *vidmem = (unsigned char *)0xB8000;
00057  long size = COLSIZE * ROWSIZE * 2;
00058 
00059  #ifdef NEED_DBG
00060  if(graphics)
00061  {
00062   gcls();
00063   return;
00064  }
00065  #endif
00066 
00067  while(size >= 0)
00068  {
00069    *(vidmem+size) = ' ';
00070     size-=2;
00071  }
00072  row=0;
00073  col=0;
00074 
00075  #endif
00076 }
00077 
00078 void kprint(char *str)
00079 {
00080   #ifdef __DEBUG__
00081   unsigned char *vidmem = (unsigned char *)0xB8000;
00082   char ch;
00083   int i;
00084 
00085   #if NEED_DBG
00086   if(chkGraphicsInited())
00087     {
00088       gprint(str);
00089       return;
00090     }
00091   #endif
00092 
00093   if(row > ROWSIZE)
00094   {
00095         row = 0;
00096         col = 0;
00097           cls();
00098   }
00099 
00100   vidmem += row*2*COLSIZE+2*col;
00101 
00102   while(*str != '\0')
00103   {
00104         ch = *str++;
00105 
00106         switch(ch)
00107         {
00108          case '\n':
00109                 row++;
00110                 col = 0;
00111                 vidmem = (unsigned char *)0xB8000 + row*2*COLSIZE;
00112                 break;
00113 
00114          case '\t':
00115                 for(i=0;i<TABSIZE;i++)
00116                 {
00117                  *vidmem++ = ' ';
00118                  *vidmem++ = 0x0A;
00119                  col++;
00120                 }
00121                 break;
00122 
00123          default:
00124                 *vidmem++ = ch;
00125                 *vidmem++ = 0x0A;
00126                 col++;
00127                 break;
00128         }
00129 
00130     if(col > COLSIZE)
00131     {
00132         row++;
00133         col = 0;
00134     }
00135 
00136   }
00137 
00138   updateCursor();
00139   #endif
00140 }
00141 
00142 void gcls()
00143 {
00144   #ifdef __DEBUG__
00145     delay(gcls_delay);
00146         grow = 0;
00147         gcol = 0;
00148           rect(DEBUGGER_X,0,400,600);
00149   #endif
00150 }
00151 
00152 void gprint(char *str)
00153 {
00154   #ifdef __DEBUG__      
00155   static DB count = 0;
00156   char ch;
00157   int i;
00158 
00159   if(!graphics)
00160       return;
00161 
00162   if(grow > GROWSIZE)
00163   {
00164     gcls();
00165   }
00166 
00167   while(*str != '\0')
00168   {
00169         ch = *str++;
00170 
00171 
00172         switch(ch)
00173         {
00174          case '\n':
00175                         grow++;
00176                         gcol = 0;
00177                         break;
00178 
00179          case '\t':
00180                         for(i=0;i<TABSIZE;i++)
00181                         {
00182                drawChar(DEBUGGER_X+DEBUGGER_OFFSET+gcol*7,grow*9,0);
00183                  gcol++;
00184                         }
00185                         break;
00186 
00187          default:
00188             drawChar(DEBUGGER_X+DEBUGGER_OFFSET+gcol*7,grow*9,ch);
00189                 gcol++;
00190                         break;
00191         }
00192 
00193     if(gcol > GCOLSIZE)
00194     {
00195         grow++;
00196         gcol = 0;
00197     }
00198 
00199    }
00200    if(count % 100 ==0)
00201       mvBuf2Svga();
00202    count++;
00203 
00204  #endif
00205 }
00206 
00207 
00208 void kprintln()
00209 {
00210  #ifdef __DEBUG__
00211  if(row > ROWSIZE)
00212  {
00213   cls();
00214   row = 0;
00215  }
00216  else
00217  {
00218   row++;
00219  }
00220  col = 0;
00221  #endif
00222 }
00223 
00224 
00225 extern boolean graphics;
00226 
00227 void panic(DB *info)
00228 {
00229   unsigned char *vidmem = (unsigned char *)0xB8000 + 2*row*COLSIZE + 2*col;
00230   char *str = "PANIC_MODE: System in panic mode";
00231 
00232   //cls();
00233 
00234   if(graphics)
00235   {
00236     drawstring(50,200,str);
00237     drawstring(50,230,info);
00238     mvBuf2Svga();
00239   }
00240 
00241   while(*str != '\0')
00242   {
00243        *vidmem++ = *str++;
00244        *vidmem++ = 0x0C;
00245   }
00246   printf(info);
00247 
00248   for(;;)
00249     ;
00250 }
00251 
00252 void ginfo(DW x, DW y, char *info )
00253 {
00254 //      #ifdef __DEBUG__
00255   if(graphics)
00256   {
00257     drawstring(x,y,info);
00258     mvBuf2Svga();
00259   }
00260 //  #endif
00261 }
00262 
00263 void updateCursor()
00264 {
00265   #ifdef __DEBUG__
00266   DW position=(row*COLSIZE) + col;
00267         outb(0x3D4, 0x0F);
00268         outb(0x3D5, (DB)(position&0xFF));
00269         outb(0x3D4, 0x0E);
00270         outb(0x3D5, (DB)((position>>8)&0xFF));
00271   #endif
00272 }
00273 
00274 
00275 void printf(char fmt[],...)
00276 {
00277   #ifdef __DEBUG__
00278   DB index = 0, len = 0;  
00279   DB temp[MINI_BUFFER]={0};
00280   DB *tmp = NULL;
00281   va_list ap;
00282 
00283   va_start(ap,fmt);
00284 
00285   while(*fmt)
00286   {
00287     if(*fmt == '%')
00288     {
00289       switch(*(fmt+1))
00290       {
00291         case 'd': //Decimal Numbers
00292             tmp = itoa(va_arg(ap,int),10);
00293             len = strlen(tmp);
00294             memcpy(temp+index,tmp,len);
00295             index+=len;
00296             fmt++;
00297             break;
00298 
00299         case 'x': //Decimal Numbers
00300             tmp = itoa(va_arg(ap,int),16);
00301             len = strlen(tmp)+2; //For 0x
00302             memcpy(temp+index,"0x",2);
00303             memcpy(temp+index+2,tmp,len);
00304             index+=len;
00305             fmt++;
00306             break;
00307 
00308        case 'b': //Binary added on 26/12/2003
00309                         tmp = itoa(va_arg(ap,int),2);
00310             len = strlen(tmp)+1; //For b for BINARY
00311             memcpy(temp+index,"b",1);
00312             memcpy(temp+index+1,tmp,len);
00313             index+=len;
00314             fmt++;
00315             break;
00316 
00317         case 's': //char *
00318             tmp = va_arg(ap,char*);
00319             len = strlen(tmp);
00320             memcpy(temp+index,tmp,len);
00321             index+=len;
00322             fmt++;
00323             break;
00324          case 'c' :
00325                         *tmp = va_arg(ap,char);
00326             memcpy(temp+index,tmp,1);
00327             index+=1;
00328             fmt++;
00329             break;
00330 
00331         default:
00332             temp[index++] = '%';
00333             break;
00334       }
00335       fmt++;
00336     }
00337     else
00338       temp[index++] = *fmt++;
00339   }
00340 
00341   kprint(temp);
00342   va_end(ap);
00343 
00344   #endif
00345 }
00346 
00347 
00348 void kprintnum(long num,int base)
00349 {
00350   #ifdef __DEBUG__
00351   switch(base)
00352   {
00353    case 16:
00354         kprint("0x");
00355     kprint(itoa(num,base));
00356         break;
00357 
00358    case 2:
00359         kprint("b");
00360     kprint(itoa(num,base));
00361         break;
00362 
00363    case 10: //For Decimal
00364     kprint(itoa(num,base));
00365         break;
00366 
00367    default:
00368         kprint("\nBase not known\tFile Name : \t");
00369         kprint(__FILE__);
00370         return;
00371         break;
00372   }
00373   #endif
00374 }
00375 
00376 
00377   void putch(char ch)
00378   {
00379     #ifdef __DEBUG__            
00380     unsigned char *vidmem = (unsigned char *)0xB8000;
00381           vidmem += row*2*COLSIZE+2*col;
00382 
00383           *vidmem = ch;
00384           *(vidmem+1) = 0x0A;
00385           col += 1;
00386 
00387           if(col > COLSIZE)
00388           {
00389                         row++;
00390                         col = 0;
00391                 }
00392 
00393                 updateCursor();
00394           #endif
00395   }
00396 
00397 

Generated on Thu Jul 27 23:52:27 2006 for Dynacube by  doxygen 1.4.7