SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

001 /* Copyright (C) 2004  David Decotigny
002 
003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any later version.
007    
008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details.
012    
013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA. 
017 */
018 #include <hwcore/ioports.h>
019 #include <sos/klibc.h>
020 
021 #include "bochs.h"
022 
023 /* This is a special hack that is only useful when running the
024    operating system under the Bochs emulator.  */
025 #define SOS_BOCHS_IOPORT 0xe9
026 
027 sos_ret_t sos_bochs_setup(void)
028 {
029   return SOS_OK;
030 }
031 
032 #define _putchar(chr) \
033     outb((chr), SOS_BOCHS_IOPORT)
034 
035 sos_ret_t sos_bochs_putchar(char c)
036 {
037   _putchar(c);
038 
039   return SOS_OK;
040 }
041 
042 sos_ret_t sos_bochs_putstring(const char* str)
043 {
044   for ( ; str && (*str != '\0') ; str++)
045     _putchar(*str);
046 
047   return SOS_OK;
048 }
049 
050 sos_ret_t sos_bochs_puthex(unsigned val, int nbytes)
051 {
052   unsigned c;
053 
054 #define BOCHS_PRTHEX(q) \
055   ({ unsigned char r; if ((q) >= 10) r='a'+(q)-10; \
056      else r='0'+(q); _putchar(r); })
057 
058   switch (nbytes)
059     {
060     case 4:
061       c = (val >> 24) & 0xff;
062       BOCHS_PRTHEX((c >> 4)&0xf);
063       BOCHS_PRTHEX(c&0xf);
064     case 3:
065       c = (val >> 16) & 0xff;
066       BOCHS_PRTHEX((c >> 4)&0xf);
067       BOCHS_PRTHEX(c&0xf);
068     case 2:
069       c = (val >> 8) & 0xff;
070       BOCHS_PRTHEX((c >> 4)&0xf);
071       BOCHS_PRTHEX(c&0xf);
072     case 1:
073       c = val & 0xff;
074       BOCHS_PRTHEX((c >> 4)&0xf);
075       BOCHS_PRTHEX(c&0xf);
076     }
077 
078   return SOS_OK;
079 }
080 
081 
082 sos_ret_t sos_bochs_hexdump(const void* addr, int nbytes)
083 {
084   int offs;
085   for (offs = 0 ; offs < nbytes ; offs++)
086     {
087       const unsigned char *c;
088       
089       if ((offs % 16) == 0)
090         {
091           sos_bochs_putstring("0x");
092           sos_bochs_puthex(offs, 4);
093         }
094       
095       if ((offs % 8) == 0)
096         sos_bochs_putstring("   ");
097 
098       c = (const unsigned char*)(addr + offs);
099       sos_bochs_puthex(*c, 1);
100       sos_bochs_putstring(" ");
101       
102       if (((offs + 1) % 16) == 0)
103         sos_bochs_putstring("\n");
104     }
105 
106   if (offs % 16)
107     sos_bochs_putstring("\n");
108 
109   return SOS_OK;
110 }
111 
112 
113 sos_ret_t sos_bochs_printf(const char *format, /* args */...)
114 {
115   char buff[256];
116   va_list ap;
117   
118   va_start(ap, format);
119   vsnprintf(buff, sizeof(buff), format, ap);
120   va_end(ap);
121   
122   return sos_bochs_putstring(buff);
123 }

source navigation ] diff markup ] identifier search ] general search ]