Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

debug.h

Go to the documentation of this file.
00001 // See the end of this file for license information.
00002 
00003 #ifndef TORSION_DEBUG_H
00004 #define TORSION_DEBUG_H
00005 
00006 #include "asm.h"
00007 
00008 const unsigned BOCHS_DEBUG_PORT = 0xe9;
00009 
00010 inline void
00011 dprint(char* str) {
00012   for ( ; *str != '\0'; str++)
00013     outb(*str, BOCHS_DEBUG_PORT);
00014   outb(0xa, BOCHS_DEBUG_PORT);
00015 }
00016 
00017 inline void
00018 dprint(unsigned number) {
00019   char buffer[9];
00020           // start at the end of 8-char
00021           // string and go backwards
00022   for (int index = 7; index >= 0; index--) {
00023     unsigned char one_digit = number & 0xf;
00024     if (one_digit < 10)
00025       one_digit += 0x30;    // convert a number to ascii (0-9)
00026     else
00027       one_digit += 0x57;    // convert a letter to ascii (a-f)
00028     buffer[index] = one_digit;
00029 
00030     number >>= 4;
00031   }
00032   buffer[8] = '\0';
00033 
00034   dprint(buffer);
00035 }
00036 
00037 inline void
00038 dprint(void* pointer) {
00039   dprint((unsigned)pointer);
00040 }
00041 
00042 inline void
00043 hexdump(void* address, Size bytes) {
00044   unsigned count = (bytes + 3) / 4;
00045   unsigned* typed_address = (unsigned*)address;
00046   for (unsigned i = 0; i < count; ++i, ++typed_address) {
00047     dprint(*typed_address);
00048   }
00049 }
00050 
00051 #endif
00052 
00053 /* Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman
00054  *
00055  * This program is free software; you can redistribute it and/or modify it
00056  * under the terms of the GNU General Public License as published by the
00057  * Free Software Foundation; either version 2 of the License, or (at your
00058  * option) any later version.
00059  * 
00060  * This program is distributed in the hope that it will be useful, but
00061  * WITHOUT ANY WARRANTY; without even the implied warranty of
00062  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00063  * General Public License for more details (in the COPYING file).
00064  * 
00065  * You should have received a copy of the GNU General Public License along
00066  * with this program; if not, write to the Free Software Foundation, Inc.,
00067  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00068  */

Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman