File: biosdev.cc

package info (click to toggle)
bochs 2.3-2etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 14,116 kB
  • ctags: 16,927
  • sloc: cpp: 130,524; ansic: 18,822; sh: 7,922; makefile: 3,836; yacc: 1,056; asm: 463; perl: 381; lex: 280; csh: 3
file content (237 lines) | stat: -rw-r--r-- 8,159 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/////////////////////////////////////////////////////////////////////////
// $Id: biosdev.cc,v 1.10 2005/10/23 13:23:49 vruppert Exp $
/////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2002  MandrakeSoft S.A.
//
//    MandrakeSoft S.A.
//    43, rue d'Aboukir
//    75002 Paris - France
//    http://www.linux-mandrake.com/
//    http://www.mandrakesoft.com/
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA


// Here are the virtual ports use to display messages from the bioses :
//
//  0x0400 : rombios Panic port with line number
//  0x0401 : rombios Panic port with message, panic flag or line number
//  0x0402 : rombios Info port with message
//  0x0403 : rombios Debug port with message
//
//  0x0500 : vgabios Info port with message
//  0x0501 : vgabios Panic port with line number
//  0x0502 : vgabios Panic port with message, panic flag or line number
//  0x0503 : vgabios Debug port with message


// Define BX_PLUGGABLE in files that can be compiled into plugins.  For
// platforms that require a special tag on exported symbols, BX_PLUGGABLE 
// is used to know when we are exporting symbols and when we are importing.
#define BX_PLUGGABLE

#include "iodev.h"

bx_biosdev_c *theBiosDevice;

  int
libbiosdev_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[])
{
  theBiosDevice = new bx_biosdev_c ();
  bx_devices.pluginBiosDevice = theBiosDevice;
  BX_REGISTER_DEVICE_DEVMODEL(plugin, type, theBiosDevice, BX_PLUGIN_BIOSDEV);
  return(0); // Success
}

  void
libbiosdev_LTX_plugin_fini(void)
{
}

logfunctions  *bioslog;
logfunctions  *vgabioslog;

bx_biosdev_c::bx_biosdev_c(void)
{
  bioslog = new logfunctions();
  bioslog->put("BIOS");
  bioslog->settype(BIOSLOG);
  s.bios_message_i = 0;
  s.bios_panic_flag = 0;

  vgabioslog = new logfunctions();
  vgabioslog->put("VBIOS");
  vgabioslog->settype(BIOSLOG);
  s.vgabios_message_i = 0;
  s.vgabios_panic_flag = 0;
}

bx_biosdev_c::~bx_biosdev_c(void)
{
    if ( bioslog != NULL )
    {
        delete bioslog;
        bioslog = NULL;
    }

    if ( vgabioslog != NULL )
    {
        delete vgabioslog;
        vgabioslog = NULL;
    }
}

  void
bx_biosdev_c::init(void)
{
  DEV_register_iowrite_handler(this, write_handler, 0x0400, "Bios Panic Port 1", 3);
  DEV_register_iowrite_handler(this, write_handler, 0x0401, "Bios Panic Port 2", 3);
  DEV_register_iowrite_handler(this, write_handler, 0x0402, "Bios Info Port", 1);
  DEV_register_iowrite_handler(this, write_handler, 0x0403, "Bios Debug Port", 1);

  DEV_register_iowrite_handler(this, write_handler, 0x0500, "VGABios Info Port", 1);
  DEV_register_iowrite_handler(this, write_handler, 0x0501, "VGABios Panic Port 1", 3);
  DEV_register_iowrite_handler(this, write_handler, 0x0502, "VGABios Panic Port 2", 3);
  DEV_register_iowrite_handler(this, write_handler, 0x0503, "VGABios Debug Port", 1);
}

  void
bx_biosdev_c::reset(unsigned type)
{
}

  // static IO port write callback handler
  // redirects to non-static class handler to avoid virtual functions

  void
bx_biosdev_c::write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
{
#if !BX_USE_BIOS_SMF
  bx_biosdev_c *class_ptr = (bx_biosdev_c *) this_ptr;

  class_ptr->write(address, value, io_len);
}

  void
bx_biosdev_c::write(Bit32u address, Bit32u value, unsigned io_len)
{
#else
  UNUSED(this_ptr);
#endif  // !BX_USE_BIOS_SMF
  UNUSED(io_len);


  switch (address) {
    // 0x400-0x401 are used as panic ports for the rombios
    case 0x0401:
      if (value==0) {
        // The next message sent to the info port will cause a panic
        BX_BIOS_THIS s.bios_panic_flag = 1;
        break;
      } else if (BX_BIOS_THIS s.bios_message_i > 0) {
        // if there are bits of message in the buffer, print them as the
        // panic message.  Otherwise fall into the next case.
        if (BX_BIOS_THIS s.bios_message_i >= BX_BIOS_MESSAGE_SIZE)
          BX_BIOS_THIS s.bios_message_i = BX_BIOS_MESSAGE_SIZE-1;
        BX_BIOS_THIS s.bios_message[ BX_BIOS_THIS s.bios_message_i] = 0;
        BX_BIOS_THIS s.bios_message_i = 0;
        bioslog->panic("%s", BX_BIOS_THIS s.bios_message);
        break;
      }
    case 0x0400:
      if (value > 0) {
        bioslog->panic("BIOS panic at rombios.c, line %d", value);
      }
      break;

    // 0x0402 is used as the info port for the rombios
    // 0x0403 is used as the debug port for the rombios
    case 0x0402:
    case 0x0403:
      BX_BIOS_THIS s.bios_message[BX_BIOS_THIS s.bios_message_i] =
        (Bit8u) value;
      BX_BIOS_THIS s.bios_message_i ++;
      if ( BX_BIOS_THIS s.bios_message_i >= BX_BIOS_MESSAGE_SIZE ) {
        BX_BIOS_THIS s.bios_message[ BX_BIOS_MESSAGE_SIZE - 1] = 0;
        BX_BIOS_THIS s.bios_message_i = 0;
        if (address==0x403)
          bioslog->ldebug("%s", BX_BIOS_THIS s.bios_message);
        else
          bioslog->info("%s", BX_BIOS_THIS s.bios_message);
      } else if ((value & 0xff) == '\n') {
        BX_BIOS_THIS s.bios_message[ BX_BIOS_THIS s.bios_message_i - 1 ] = 0;
        BX_BIOS_THIS s.bios_message_i = 0;
        if (BX_BIOS_THIS s.bios_panic_flag==1)
          bioslog->panic("%s", BX_BIOS_THIS s.bios_message);
        else if (address==0x403)
          bioslog->ldebug("%s", BX_BIOS_THIS s.bios_message);
        else
          bioslog->info("%s", BX_BIOS_THIS s.bios_message);
        BX_BIOS_THIS s.bios_panic_flag = 0;
      }
      break;

    // 0x501-0x502 are used as panic ports for the vgabios
    case 0x0502:
      if (value==0) {
        BX_BIOS_THIS s.vgabios_panic_flag = 1;
        break;
      } else if (BX_BIOS_THIS s.vgabios_message_i > 0) {
        // if there are bits of message in the buffer, print them as the
        // panic message.  Otherwise fall into the next case.
        if (BX_BIOS_THIS s.vgabios_message_i >= BX_BIOS_MESSAGE_SIZE)
          BX_BIOS_THIS s.vgabios_message_i = BX_BIOS_MESSAGE_SIZE-1;
        BX_BIOS_THIS s.vgabios_message[ BX_BIOS_THIS s.vgabios_message_i] = 0;
        BX_BIOS_THIS s.vgabios_message_i = 0;
        vgabioslog->panic("%s", BX_BIOS_THIS s.vgabios_message);
        break;
      }
    case 0x0501:
      if (value > 0) {
        vgabioslog->panic("VGABIOS panic at vgabios.c, line %d", value);
      }
      break;

    // 0x0500 is used as the message port for the vgabios
    case 0x0500:
    case 0x0503:
      BX_BIOS_THIS s.vgabios_message[BX_BIOS_THIS s.vgabios_message_i] =
        (Bit8u) value;
      BX_BIOS_THIS s.vgabios_message_i ++;
      if ( BX_BIOS_THIS s.vgabios_message_i >= BX_BIOS_MESSAGE_SIZE ) {
        BX_BIOS_THIS s.vgabios_message[ BX_BIOS_MESSAGE_SIZE - 1] = 0;
        BX_BIOS_THIS s.vgabios_message_i = 0;
        if (address==0x503)
          vgabioslog->ldebug("%s", BX_BIOS_THIS s.vgabios_message);
        else
          vgabioslog->info("%s", BX_BIOS_THIS s.vgabios_message);
      } else if ((value & 0xff) == '\n') {
        BX_BIOS_THIS s.vgabios_message[ BX_BIOS_THIS s.vgabios_message_i - 1 ] = 0;
        BX_BIOS_THIS s.vgabios_message_i = 0;
        if (BX_BIOS_THIS s.vgabios_panic_flag==1)
          vgabioslog->panic("%s", BX_BIOS_THIS s.vgabios_message);
        else if (address==0x503)
          vgabioslog->ldebug("%s", BX_BIOS_THIS s.vgabios_message);
        else
          vgabioslog->info("%s", BX_BIOS_THIS s.vgabios_message);
        BX_BIOS_THIS s.vgabios_panic_flag = 0;
      }
      break;

    default:
      break;
  }
}