OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [bochs486/] [iodev/] [iodev.h] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/////////////////////////////////////////////////////////////////////////
2
// $Id: iodev.h 11553 2012-11-25 19:06:03Z vruppert $
3
/////////////////////////////////////////////////////////////////////////
4
//
5
//  Copyright (C) 2002-2012  The Bochs Project
6
//
7
//  I/O port handlers API Copyright (C) 2003 by Frank Cornelis
8
//
9
//  This library is free software; you can redistribute it and/or
10
//  modify it under the terms of the GNU Lesser General Public
11
//  License as published by the Free Software Foundation; either
12
//  version 2 of the License, or (at your option) any later version.
13
//
14
//  This library is distributed in the hope that it will be useful,
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
//  Lesser General Public License for more details.
18
//
19
//  You should have received a copy of the GNU Lesser General Public
20
//  License along with this library; if not, write to the Free Software
21
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
22
//
23
/////////////////////////////////////////////////////////////////////////
24
 
25
#ifndef IODEV_H
26
#define IODEV_H
27
 
28
#include "bochs.h"
29
#include "plugin.h"
30
#include "param_names.h"
31
 
32
/* number of IRQ lines supported.  In an ISA PC there are two
33
   PIC chips cascaded together.  each has 8 IRQ lines, so there
34
   should be 16 IRQ's total */
35
#define BX_MAX_IRQS 16
36
 
37
/* size of internal buffer for mouse devices */
38
#define BX_MOUSE_BUFF_SIZE 48
39
 
40
/* maximum size of the ISA DMA buffer */
41
#define BX_DMA_BUFFER_SIZE 512
42
 
43
#define BX_MAX_PCI_DEVICES 20
44
 
45
typedef Bit32u (*bx_read_handler_t)(void *, Bit32u, unsigned);
46
typedef void   (*bx_write_handler_t)(void *, Bit32u, Bit32u, unsigned);
47
 
48
typedef bx_bool (*bx_keyb_enq_t)(void *, Bit8u *);
49
typedef void (*bx_mouse_enq_t)(void *, int, int, int, unsigned, bx_bool);
50
typedef void (*bx_mouse_enabled_changed_t)(void *, bx_bool);
51
 
52
#if BX_USE_DEV_SMF
53
#  define BX_DEV_SMF  static
54
#  define BX_DEV_THIS bx_devices.
55
#else
56
#  define BX_DEV_SMF
57
#  define BX_DEV_THIS this->
58
#endif
59
 
60
//////////////////////////////////////////////////////////////////////
61
// bx_devmodel_c declaration
62
//////////////////////////////////////////////////////////////////////
63
 
64
// This class defines virtual methods that are common to all devices.
65
// Child classes do not need to implement all of them, because in this
66
// definition they are defined as empty, as opposed to being pure
67
// virtual (= 0).
68
class BOCHSAPI bx_devmodel_c : public logfunctions {
69
  public:
70
  virtual ~bx_devmodel_c() {}
71
  virtual void init(void) {}
72
  virtual void reset(unsigned type) {}
73
  virtual void register_state(void) {}
74
  virtual void after_restore_state(void) {}
75
#if BX_DEBUGGER
76
  virtual void debug_dump(int argc, char **argv) {}
77
#endif
78
};
79
 
80
//////////////////////////////////////////////////////////////////////
81
// declare stubs for PCI devices
82
//////////////////////////////////////////////////////////////////////
83
 
84
class bx_list_c;
85
class device_image_t;
86
class LOWLEVEL_CDROM;
87
 
88
// the best should be deriving of bx_pci_device_stub_c from bx_devmodel_c
89
// but it make serious problems for cirrus_svga device
90
class BOCHSAPI bx_pci_device_stub_c {
91
public:
92
  bx_pci_device_stub_c(): pci_rom(NULL), pci_rom_size(0) {}
93
  virtual ~bx_pci_device_stub_c() {
94
    if (pci_rom != NULL) delete [] pci_rom;
95
  }
96
 
97
  virtual Bit32u pci_read_handler(Bit8u address, unsigned io_len) {
98
    return 0;
99
  }
100
 
101
  virtual void pci_write_handler(Bit8u address, Bit32u value, unsigned io_len) {}
102
 
103
  void register_pci_state(bx_list_c *list);
104
 
105
  void load_pci_rom(const char *path);
106
 
107
protected:
108
  Bit8u pci_conf[256];
109
  Bit32u pci_base_address[6];
110
  Bit8u  *pci_rom;
111
  Bit32u pci_rom_address;
112
  Bit32u pci_rom_size;
113
};
114
 
115
//////////////////////////////////////////////////////////////////////
116
// declare stubs for devices
117
//////////////////////////////////////////////////////////////////////
118
 
119
//////////////////////////////////////////////////////////////////////
120
#define STUBFUNC(dev,method) \
121
   pluginlog->panic("%s called in %s stub. you must not have loaded the %s plugin", #dev, #method, #dev)
122
//////////////////////////////////////////////////////////////////////
123
 
124
class BOCHSAPI bx_keyb_stub_c : public bx_devmodel_c {
125
public:
126
  virtual ~bx_keyb_stub_c() {}
127
  // stubs for bx_keyb_c methods
128
  virtual void gen_scancode(Bit32u key) {
129
    STUBFUNC(keyboard, gen_scancode);
130
  }
131
  virtual void paste_bytes(Bit8u *data, Bit32s length) {
132
    STUBFUNC(keyboard, paste_bytes);
133
  }
134
};
135
 
136
class BOCHSAPI bx_hard_drive_stub_c : public bx_devmodel_c {
137
public:
138
  virtual void   init() {
139
    STUBFUNC(HD, init);
140
  }
141
  virtual void   reset(unsigned type) {
142
    STUBFUNC(HD, reset);
143
  }
144
  virtual Bit32u   get_first_cd_handle(void) {
145
    STUBFUNC(HD, get_first_cd_handle); return 0;
146
  }
147
  virtual unsigned get_cd_media_status(Bit32u handle) {
148
    STUBFUNC(HD, get_cd_media_status); return 0;
149
  }
150
  virtual unsigned set_cd_media_status(Bit32u handle, unsigned status) {
151
    STUBFUNC(HD, set_cd_media_status); return 0;
152
  }
153
  virtual Bit32u virt_read_handler(Bit32u address, unsigned io_len)
154
  {
155
    STUBFUNC(HD, virt_read_handler); return 0;
156
  }
157
  virtual void   virt_write_handler(Bit32u address,
158
      Bit32u value, unsigned io_len)
159
  {
160
    STUBFUNC(HD, virt_write_handler);
161
  }
162
  virtual bx_bool bmdma_read_sector(Bit8u channel, Bit8u *buffer, Bit32u *sector_size) {
163
    STUBFUNC(HD, bmdma_read_sector); return 0;
164
  }
165
  virtual bx_bool bmdma_write_sector(Bit8u channel, Bit8u *buffer) {
166
    STUBFUNC(HD, bmdma_write_sector); return 0;
167
  }
168
  virtual void bmdma_complete(Bit8u channel) {
169
    STUBFUNC(HD, bmdma_complete);
170
  }
171
};
172
 
173
class BOCHSAPI bx_floppy_stub_c : public bx_devmodel_c {
174
public:
175
  virtual unsigned set_media_status(unsigned drive, unsigned status) {
176
    STUBFUNC(floppy, set_media_status); return 0;
177
  }
178
};
179
 
180
class BOCHSAPI bx_cmos_stub_c : public bx_devmodel_c {
181
public:
182
  virtual Bit32u get_reg(unsigned reg) {
183
    STUBFUNC(cmos, get_reg); return 0;
184
  }
185
  virtual void set_reg(unsigned reg, Bit32u val) {
186
    STUBFUNC(cmos, set_reg);
187
  }
188
  virtual time_t get_timeval() {
189
    return 0;
190
  }
191
  virtual void checksum_cmos(void) {
192
    STUBFUNC(cmos, checksum);
193
  }
194
};
195
 
196
class BOCHSAPI bx_dma_stub_c : public bx_devmodel_c {
197
public:
198
  virtual unsigned registerDMA8Channel(
199
    unsigned channel,
200
    Bit16u (* dmaRead)(Bit8u *data_byte, Bit16u maxlen),
201
    Bit16u (* dmaWrite)(Bit8u *data_byte, Bit16u maxlen),
202
    const char *name)
203
  {
204
    STUBFUNC(dma, registerDMA8Channel); return 0;
205
  }
206
  virtual unsigned registerDMA16Channel(
207
    unsigned channel,
208
    Bit16u (* dmaRead)(Bit16u *data_word, Bit16u maxlen),
209
    Bit16u (* dmaWrite)(Bit16u *data_word, Bit16u maxlen),
210
    const char *name)
211
  {
212
    STUBFUNC(dma, registerDMA16Channel); return 0;
213
  }
214
  virtual unsigned unregisterDMAChannel(unsigned channel) {
215
    STUBFUNC(dma, unregisterDMAChannel); return 0;
216
  }
217
  virtual unsigned get_TC(void) {
218
    STUBFUNC(dma, get_TC); return 0;
219
  }
220
  virtual void set_DRQ(unsigned channel, bx_bool val) {
221
    STUBFUNC(dma, set_DRQ);
222
  }
223
  virtual void raise_HLDA(void) {
224
    STUBFUNC(dma, raise_HLDA);
225
  }
226
};
227
 
228
class BOCHSAPI bx_pic_stub_c : public bx_devmodel_c {
229
public:
230
  virtual void raise_irq(unsigned irq_no) {
231
    STUBFUNC(pic, raise_irq);
232
  }
233
  virtual void lower_irq(unsigned irq_no) {
234
    STUBFUNC(pic, lower_irq);
235
  }
236
  virtual void set_mode(bx_bool ma_sl, Bit8u mode) {
237
    STUBFUNC(pic, set_mode);
238
  }
239
  virtual Bit8u IAC(void) {
240
    STUBFUNC(pic, IAC); return 0;
241
  }
242
};
243
 
244
class BOCHSAPI bx_vga_stub_c : public bx_devmodel_c {
245
public:
246
  virtual void redraw_area(unsigned x0, unsigned y0,
247
                           unsigned width, unsigned height) {
248
    STUBFUNC(vga, redraw_area);
249
  }
250
  virtual Bit8u mem_read(bx_phy_address addr) {
251
    STUBFUNC(vga, mem_read);  return 0;
252
  }
253
  virtual void mem_write(bx_phy_address addr, Bit8u value) {
254
    STUBFUNC(vga, mem_write);
255
  }
256
  virtual void get_text_snapshot(Bit8u **text_snapshot,
257
                                 unsigned *txHeight, unsigned *txWidth) {
258
    STUBFUNC(vga, get_text_snapshot);
259
  }
260
  virtual void set_override(bx_bool enabled, void *dev) {
261
    STUBFUNC(vga, set_override);
262
  }
263
  virtual void refresh_display(void *this_ptr, bx_bool redraw) {
264
    STUBFUNC(vga, refresh_display);
265
  }
266
};
267
 
268
class BOCHSAPI bx_pci2isa_stub_c : public bx_devmodel_c, public bx_pci_device_stub_c {
269
public:
270
  virtual void pci_set_irq (Bit8u devfunc, unsigned line, bx_bool level) {
271
    STUBFUNC(pci2isa, pci_set_irq);
272
  }
273
};
274
 
275
class BOCHSAPI bx_pci_ide_stub_c : public bx_devmodel_c, public bx_pci_device_stub_c {
276
public:
277
  virtual bx_bool bmdma_present(void) {
278
    return 0;
279
  }
280
  virtual void bmdma_set_irq(Bit8u channel) {}
281
};
282
 
283
class BOCHSAPI bx_speaker_stub_c : public bx_devmodel_c {
284
public:
285
  virtual void beep_on(float frequency) {
286
    bx_gui->beep_on(frequency);
287
  }
288
  virtual void beep_off() {
289
    bx_gui->beep_off();
290
  }
291
};
292
 
293
#if BX_SUPPORT_PCI
294
class BOCHSAPI bx_acpi_ctrl_stub_c : public bx_devmodel_c, public bx_pci_device_stub_c {
295
public:
296
  virtual void generate_smi(Bit8u value) {}
297
};
298
#endif
299
 
300
#if BX_SUPPORT_IODEBUG
301
class BOCHSAPI bx_iodebug_stub_c : public bx_devmodel_c {
302
public:
303
  virtual void mem_write(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, void *data) {}
304
  virtual void mem_read(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, void *data) {}
305
};
306
#endif
307
 
308
#if BX_SUPPORT_APIC
309
class BOCHSAPI bx_ioapic_stub_c : public bx_devmodel_c {
310
public:
311
  virtual void receive_eoi(Bit8u vector) {}
312
  virtual void set_irq_level(Bit8u int_in, bx_bool level) {}
313
};
314
#endif
315
 
316
#if BX_SUPPORT_GAMEPORT
317
class BOCHSAPI bx_game_stub_c : public bx_devmodel_c {
318
public:
319
  virtual void set_enabled(bx_bool val) {
320
    STUBFUNC(gameport, set_enabled);
321
  }
322
};
323
#endif
324
 
325
#if BX_SUPPORT_PCIUSB
326
class BOCHSAPI bx_usb_devctl_stub_c : public bx_devmodel_c {
327
public:
328
  virtual int init_device(bx_list_c *portconf, logfunctions *hub, void **dev, bx_list_c *sr_list) {
329
    STUBFUNC(usb_devctl, init_device); return 0;
330
  }
331
  virtual void usb_send_msg(void *dev, int msg) {}
332
};
333
#endif
334
 
335
class BOCHSAPI bx_hdimage_ctl_stub_c : public bx_devmodel_c {
336
public:
337
  virtual device_image_t* init_image(Bit8u image_mode, Bit64u disk_size, const char *journal) {
338
    STUBFUNC(hdimage_ctl, init_image); return NULL;
339
  }
340
#ifdef LOWLEVEL_CDROM
341
  virtual LOWLEVEL_CDROM* init_cdrom(const char *dev) {
342
    STUBFUNC(hdimage_ctl, init_cdrom); return NULL;
343
  }
344
#endif
345
};
346
 
347
#if BX_SUPPORT_SOUNDLOW
348
class BOCHSAPI bx_soundmod_ctl_stub_c : public bx_devmodel_c {
349
public:
350
  virtual void* init_module(const char *type, logfunctions *dev) {
351
    STUBFUNC(soundmod_ctl, init_module); return NULL;
352
  }
353
  virtual bx_bool beep_on(float frequency) {
354
    return 0;
355
  }
356
  virtual bx_bool beep_off() {
357
    return 0;
358
  }
359
};
360
#endif
361
 
362
#if BX_NETWORKING
363
class BOCHSAPI bx_netmod_ctl_stub_c : public bx_devmodel_c {
364
public:
365
  virtual void* init_module(bx_list_c *base, void* rxh, void* rxstat, bx_devmodel_c *dev) {
366
    STUBFUNC(netmod_ctl, init_module); return NULL;
367
  }
368
};
369
#endif
370
 
371
class BOCHSAPI bx_devices_c : public logfunctions {
372
public:
373
  bx_devices_c();
374
 ~bx_devices_c();
375
 
376
  // Initialize the device stubs (in constructur and exit())
377
  void init_stubs(void);
378
  // Register I/O addresses and IRQ lines. Initialize any internal
379
  // structures.  init() is called only once, even if the simulator
380
  // reboots or is restarted.
381
  void init(BX_MEM_C *);
382
  // Enter reset state in response to a reset condition.
383
  // The types of reset conditions are defined in bochs.h:
384
  // power-on, hardware, or software.
385
  void reset(unsigned type);
386
  // Cleanup the devices when the simulation quits.
387
  void exit(void);
388
  void register_state(void);
389
  void after_restore_state(void);
390
  BX_MEM_C *mem;  // address space associated with these devices
391
  bx_bool register_io_read_handler(void *this_ptr, bx_read_handler_t f,
392
                                   Bit32u addr, const char *name, Bit8u mask);
393
  bx_bool unregister_io_read_handler(void *this_ptr, bx_read_handler_t f,
394
                                     Bit32u addr, Bit8u mask);
395
  bx_bool register_io_write_handler(void *this_ptr, bx_write_handler_t f,
396
                                    Bit32u addr, const char *name, Bit8u mask);
397
  bx_bool unregister_io_write_handler(void *this_ptr, bx_write_handler_t f,
398
                                      Bit32u addr, Bit8u mask);
399
  bx_bool register_io_read_handler_range(void *this_ptr, bx_read_handler_t f,
400
                                         Bit32u begin_addr, Bit32u end_addr,
401
                                         const char *name, Bit8u mask);
402
  bx_bool register_io_write_handler_range(void *this_ptr, bx_write_handler_t f,
403
                                          Bit32u begin_addr, Bit32u end_addr,
404
                                          const char *name, Bit8u mask);
405
  bx_bool unregister_io_read_handler_range(void *this_ptr, bx_read_handler_t f,
406
                                           Bit32u begin, Bit32u end, Bit8u mask);
407
  bx_bool unregister_io_write_handler_range(void *this_ptr, bx_write_handler_t f,
408
                                            Bit32u begin, Bit32u end, Bit8u mask);
409
  bx_bool register_default_io_read_handler(void *this_ptr, bx_read_handler_t f, const char *name, Bit8u mask);
410
  bx_bool register_default_io_write_handler(void *this_ptr, bx_write_handler_t f, const char *name, Bit8u mask);
411
  bx_bool register_irq(unsigned irq, const char *name);
412
  bx_bool unregister_irq(unsigned irq, const char *name);
413
  Bit32u inp(Bit16u addr, unsigned io_len) BX_CPP_AttrRegparmN(2);
414
  void   outp(Bit16u addr, Bit32u value, unsigned io_len) BX_CPP_AttrRegparmN(3);
415
 
416
  void register_removable_keyboard(void *dev, bx_keyb_enq_t keyb_enq);
417
  void unregister_removable_keyboard(void *dev);
418
  void register_default_mouse(void *dev, bx_mouse_enq_t mouse_enq, bx_mouse_enabled_changed_t mouse_enabled_changed);
419
  void register_removable_mouse(void *dev, bx_mouse_enq_t mouse_enq, bx_mouse_enabled_changed_t mouse_enabled_changed);
420
  void unregister_removable_mouse(void *dev);
421
  bx_bool optional_key_enq(Bit8u *scan_code);
422
  void mouse_enabled_changed(bx_bool enabled);
423
  void mouse_motion(int delta_x, int delta_y, int delta_z, unsigned button_state, bx_bool absxy);
424
 
425
#if BX_SUPPORT_PCI
426
  Bit32u pci_get_confAddr(void) {return pci.confAddr;}
427
  bx_bool register_pci_handlers(bx_pci_device_stub_c *device, Bit8u *devfunc,
428
                                const char *name, const char *descr);
429
  bx_bool pci_set_base_mem(void *this_ptr, memory_handler_t f1, memory_handler_t f2,
430
                           Bit32u *addr, Bit8u *pci_conf, unsigned size);
431
  bx_bool pci_set_base_io(void *this_ptr, bx_read_handler_t f1, bx_write_handler_t f2,
432
                          Bit32u *addr, Bit8u *pci_conf, unsigned size,
433
                          const Bit8u *iomask, const char *name);
434
#endif
435
 
436
  static void timer_handler(void *);
437
  void timer(void);
438
 
439
  bx_pci2isa_stub_c *pluginPci2IsaBridge;
440
  bx_pci_ide_stub_c *pluginPciIdeController;
441
#if BX_SUPPORT_PCI
442
  bx_acpi_ctrl_stub_c *pluginACPIController;
443
#endif
444
  bx_devmodel_c     *pluginPitDevice;
445
  bx_keyb_stub_c    *pluginKeyboard;
446
  bx_dma_stub_c     *pluginDmaDevice;
447
  bx_floppy_stub_c  *pluginFloppyDevice;
448
  bx_cmos_stub_c    *pluginCmosDevice;
449
  bx_vga_stub_c     *pluginVgaDevice;
450
  bx_pic_stub_c     *pluginPicDevice;
451
  bx_hard_drive_stub_c *pluginHardDrive;
452
  bx_hdimage_ctl_stub_c *pluginHDImageCtl;
453
  bx_speaker_stub_c *pluginSpeaker;
454
#if BX_SUPPORT_IODEBUG
455
  bx_iodebug_stub_c *pluginIODebug;
456
#endif
457
#if BX_SUPPORT_APIC
458
  bx_ioapic_stub_c  *pluginIOAPIC;
459
#endif
460
#if BX_SUPPORT_GAMEPORT
461
  bx_game_stub_c  *pluginGameport;
462
#endif
463
#if BX_SUPPORT_PCIUSB
464
  bx_usb_devctl_stub_c  *pluginUsbDevCtl;
465
#endif
466
#if BX_SUPPORT_SOUNDLOW
467
  bx_soundmod_ctl_stub_c  *pluginSoundModCtl;
468
#endif
469
#if BX_NETWORKING
470
  bx_netmod_ctl_stub_c  *pluginNetModCtl;
471
#endif
472
 
473
  // stub classes that the pointers (above) can point to until a plugin is
474
  // loaded
475
  bx_cmos_stub_c stubCmos;
476
  bx_keyb_stub_c stubKeyboard;
477
  bx_hard_drive_stub_c stubHardDrive;
478
  bx_hdimage_ctl_stub_c stubHDImage;
479
  bx_dma_stub_c  stubDma;
480
  bx_pic_stub_c  stubPic;
481
  bx_floppy_stub_c  stubFloppy;
482
  bx_vga_stub_c  stubVga;
483
  bx_pci2isa_stub_c stubPci2Isa;
484
  bx_pci_ide_stub_c stubPciIde;
485
  bx_speaker_stub_c stubSpeaker;
486
#if BX_SUPPORT_PCI
487
  bx_acpi_ctrl_stub_c stubACPIController;
488
#endif
489
#if BX_SUPPORT_IODEBUG
490
  bx_iodebug_stub_c stubIODebug;
491
#endif
492
#if BX_SUPPORT_APIC
493
  bx_ioapic_stub_c stubIOAPIC;
494
#endif
495
#if BX_SUPPORT_GAMEPORT
496
  bx_game_stub_c stubGameport;
497
#endif
498
#if BX_SUPPORT_PCIUSB
499
  bx_usb_devctl_stub_c stubUsbDevCtl;
500
#endif
501
#if BX_SUPPORT_SOUNDLOW
502
  bx_soundmod_ctl_stub_c  stubSoundModCtl;
503
#endif
504
#if BX_NETWORKING
505
  bx_netmod_ctl_stub_c  stubNetModCtl;
506
#endif
507
 
508
  // Some info to pass to devices which can handled bulk IO.  This allows
509
  // the interface to remain the same for IO devices which can't handle
510
  // bulk IO.  We should probably implement special INPBulk() and OUTBulk()
511
  // functions which stick these values in the bx_devices_c class, and
512
  // then call the normal functions rather than having gross globals
513
  // variables.
514
  Bit8u*   bulkIOHostAddr;
515
  unsigned bulkIOQuantumsRequested;
516
  unsigned bulkIOQuantumsTransferred;
517
 
518
private:
519
 
520
  struct io_handler_struct {
521
    struct io_handler_struct *next;
522
    struct io_handler_struct *prev;
523
    void *funct; // C++ type checking is great, but annoying
524
    void *this_ptr;
525
    char *handler_name;  // name of device
526
    int usage_count;
527
    Bit8u mask;          // io_len mask
528
  };
529
  struct io_handler_struct io_read_handlers;
530
  struct io_handler_struct io_write_handlers;
531
#define PORTS 0x10000
532
  struct io_handler_struct **read_port_to_handler;
533
  struct io_handler_struct **write_port_to_handler;
534
 
535
  // more for informative purposes, the names of the devices which
536
  // are use each of the IRQ 0..15 lines are stored here
537
  char *irq_handler_name[BX_MAX_IRQS];
538
 
539
  static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);
540
  static void   write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);
541
  BX_DEV_SMF Bit32u read(Bit32u address, unsigned io_len);
542
  BX_DEV_SMF void   write(Bit32u address, Bit32u value, unsigned io_len);
543
 
544
  static Bit32u default_read_handler(void *this_ptr, Bit32u address, unsigned io_len);
545
  static void   default_write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);
546
 
547
  bx_bool mouse_captured; // host mouse capture enabled
548
  Bit8u mouse_type;
549
  struct {
550
    void *dev;
551
    bx_mouse_enq_t enq_event;
552
    bx_mouse_enabled_changed_t enabled_changed;
553
  } bx_mouse[2];
554
  struct {
555
    void *dev;
556
    bx_keyb_enq_t enq_event;
557
  } bx_keyboard;
558
 
559
  struct {
560
    bx_bool enabled;
561
#if BX_SUPPORT_PCI
562
    Bit8u handler_id[0x100];  // 256 devices/functions
563
    struct {
564
      bx_pci_device_stub_c *handler;
565
    } pci_handler[BX_MAX_PCI_DEVICES];
566
    unsigned num_pci_handlers;
567
 
568
    bx_bool slot_used[BX_N_PCI_SLOTS];
569
 
570
    Bit32u confAddr;
571
#endif
572
  } pci;
573
 
574
  int timer_handle;
575
 
576
  bx_bool network_enabled;
577
  bx_bool sound_enabled;
578
  bx_bool usb_enabled;
579
 
580
  bx_bool is_harddrv_enabled();
581
  bx_bool is_network_enabled();
582
  bx_bool is_sound_enabled();
583
  bx_bool is_usb_enabled();
584
};
585
 
586
// memory stub has an assumption that there are no memory accesses splitting 4K page
587
BX_CPP_INLINE void DEV_MEM_READ_PHYSICAL(bx_phy_address phy_addr, unsigned len, Bit8u *ptr)
588
{
589
  unsigned remainingInPage = 0x1000 - (phy_addr & 0xfff);
590
  if (len <= remainingInPage) {
591
    BX_MEM(0)->readPhysicalPage(NULL, phy_addr, len, ptr);
592
  }
593
  else {
594
    BX_MEM(0)->readPhysicalPage(NULL, phy_addr, remainingInPage, ptr);
595
    ptr += remainingInPage;
596
    phy_addr += remainingInPage;
597
    len -= remainingInPage;
598
    BX_MEM(0)->readPhysicalPage(NULL, phy_addr, len, ptr);
599
  }
600
}
601
 
602
BX_CPP_INLINE void DEV_MEM_READ_PHYSICAL_DMA(bx_phy_address phy_addr, unsigned len, Bit8u *ptr)
603
{
604
  while(len > 0) {
605
    unsigned remainingInPage = 0x1000 - (phy_addr & 0xfff);
606
    if (len < remainingInPage) remainingInPage = len;
607
    BX_MEM(0)->dmaReadPhysicalPage(phy_addr, remainingInPage, ptr);
608
    ptr += remainingInPage;
609
    phy_addr += remainingInPage;
610
    len -= remainingInPage;
611
  }
612
}
613
 
614
// memory stub has an assumption that there are no memory accesses splitting 4K page
615
BX_CPP_INLINE void DEV_MEM_WRITE_PHYSICAL(bx_phy_address phy_addr, unsigned len, Bit8u *ptr)
616
{
617
  unsigned remainingInPage = 0x1000 - (phy_addr & 0xfff);
618
  if (len <= remainingInPage) {
619
    BX_MEM(0)->writePhysicalPage(NULL, phy_addr, len, ptr);
620
  }
621
  else {
622
    BX_MEM(0)->writePhysicalPage(NULL, phy_addr, remainingInPage, ptr);
623
    ptr += remainingInPage;
624
    phy_addr += remainingInPage;
625
    len -= remainingInPage;
626
    BX_MEM(0)->writePhysicalPage(NULL, phy_addr, len, ptr);
627
  }
628
}
629
 
630
BX_CPP_INLINE void DEV_MEM_WRITE_PHYSICAL_DMA(bx_phy_address phy_addr, unsigned len, Bit8u *ptr)
631
{
632
  while(len > 0) {
633
    unsigned remainingInPage = 0x1000 - (phy_addr & 0xfff);
634
    if (len < remainingInPage) remainingInPage = len;
635
    BX_MEM(0)->dmaWritePhysicalPage(phy_addr, remainingInPage, ptr);
636
    ptr += remainingInPage;
637
    phy_addr += remainingInPage;
638
    len -= remainingInPage;
639
  }
640
}
641
 
642
BOCHSAPI extern bx_devices_c bx_devices;
643
 
644
#endif /* IODEV_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.