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 6) and /drivers/bochs.c (Article 6.5)


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

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