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 ]

Diff markup

Differences between /drivers/bochs.c (Article 5) and /drivers/bochs.c (Article 1)


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

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