Added USB printer support (patch by Ben Lunt)

This commit is contained in:
Stanislav Shwartsman 2009-12-04 13:01:41 +00:00
parent 604e7aa7ac
commit fb64ec4d0c
8 changed files with 465 additions and 87 deletions

4
bochs/configure vendored
View File

@ -1,5 +1,5 @@
#! /bin/sh
# From configure.in Id: configure.in,v 1.418 2009/11/13 15:55:46 sshwarts Exp .
# From configure.in Id: configure.in,v 1.419 2009/11/20 14:58:48 sshwarts Exp .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.64.
#
@ -22075,7 +22075,7 @@ fi
if test "$use_usb" = 1; then
USBDEV_OBJS="usb_common.o usb_hid.o usb_hub.o usb_msd.o"
USBDEV_OBJS="usb_common.o usb_hid.o usb_hub.o usb_msd.o usb_printer.o"
SCSI_OBJS="scsi_device.o"

View File

@ -2,7 +2,7 @@ dnl // Process this file with autoconf to produce a configure script.
AC_PREREQ(2.50)
AC_INIT(bochs.h)
AC_REVISION([[$Id: configure.in,v 1.419 2009-11-20 14:58:48 sshwarts Exp $]])
AC_REVISION([[$Id: configure.in,v 1.420 2009-12-04 13:01:40 sshwarts Exp $]])
AC_CONFIG_HEADER(config.h)
AC_CONFIG_HEADER(ltdlconf.h)
@ -780,7 +780,7 @@ AC_ARG_ENABLE(usb-ohci,
)
if test "$use_usb" = 1; then
USBDEV_OBJS="usb_common.o usb_hid.o usb_hub.o usb_msd.o"
USBDEV_OBJS="usb_common.o usb_hid.o usb_hub.o usb_msd.o usb_printer.o"
SCSI_OBJS="scsi_device.o"
AC_SUBST(USBDEV_OBJS)
AC_SUBST(SCSI_OBJS)

View File

@ -482,7 +482,7 @@ usb_common.o: usb_common.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
../extplugin.h ../ltdl.h ../gui/gui.h ../instrument/stubs/instrument.h \
../iodev/vga.h usb_common.h usb_hid.h usb_hub.h usb_msd.h
../iodev/vga.h usb_common.h usb_hid.h usb_hub.h usb_msd.h usb_printer.h
usb_hid.o: usb_hid.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
@ -492,23 +492,28 @@ usb_hub.o: usb_hub.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
../extplugin.h ../ltdl.h ../gui/gui.h ../instrument/stubs/instrument.h \
usb_common.h usb_hub.h usb_msd.h
usb_common.h usb_hub.h usb_msd.h usb_printer.h
usb_msd.o: usb_msd.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
../extplugin.h ../ltdl.h ../gui/gui.h ../instrument/stubs/instrument.h \
usb_common.h cdrom.h hdimage.h scsi_device.h usb_msd.h
usb_common.h cdrom.h hdimage.h scsi_device.h usb_msd.h usb_printer.h
usb_printer.o: usb_printer.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
../extplugin.h ../ltdl.h ../gui/gui.h ../instrument/stubs/instrument.h \
usb_common.h cdrom.h hdimage.h scsi_device.h usb_msd.h usb_printer.h
usb_ohci.o: usb_ohci.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
../extplugin.h ../ltdl.h ../gui/gui.h ../instrument/stubs/instrument.h \
../iodev/vga.h pci.h usb_common.h usb_hid.h usb_hub.h usb_msd.h \
../iodev/vga.h pci.h usb_common.h usb_hid.h usb_hub.h usb_msd.h usb_printer.h \
usb_ohci.h
usb_uhci.o: usb_uhci.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
../extplugin.h ../ltdl.h ../gui/gui.h ../instrument/stubs/instrument.h \
../iodev/vga.h pci.h usb_common.h usb_hid.h usb_hub.h usb_msd.h \
../iodev/vga.h pci.h usb_common.h usb_hid.h usb_hub.h usb_msd.h usb_printer.h \
usb_uhci.h
vga.o: vga.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
@ -786,7 +791,7 @@ usb_common.lo: usb_common.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
../extplugin.h ../ltdl.h ../gui/gui.h ../instrument/stubs/instrument.h \
../iodev/vga.h usb_common.h usb_hid.h usb_hub.h usb_msd.h
../iodev/vga.h usb_common.h usb_hid.h usb_hub.h usb_msd.h usb_printer.h
usb_hid.lo: usb_hid.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
@ -796,23 +801,23 @@ usb_hub.lo: usb_hub.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
../extplugin.h ../ltdl.h ../gui/gui.h ../instrument/stubs/instrument.h \
usb_common.h usb_hub.h usb_msd.h
usb_common.h usb_hub.h usb_msd.h usb_printer.h
usb_msd.lo: usb_msd.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
../extplugin.h ../ltdl.h ../gui/gui.h ../instrument/stubs/instrument.h \
usb_common.h cdrom.h hdimage.h scsi_device.h usb_msd.h
usb_common.h cdrom.h hdimage.h scsi_device.h usb_msd.h usb_printer.h
usb_ohci.lo: usb_ohci.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
../extplugin.h ../ltdl.h ../gui/gui.h ../instrument/stubs/instrument.h \
../iodev/vga.h pci.h usb_common.h usb_hid.h usb_hub.h usb_msd.h \
../iodev/vga.h pci.h usb_common.h usb_hid.h usb_hub.h usb_msd.h usb_printer.h \
usb_ohci.h
usb_uhci.lo: usb_uhci.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \
../gui/siminterface.h ../memory/memory.h ../pc_system.h ../plugin.h \
../extplugin.h ../ltdl.h ../gui/gui.h ../instrument/stubs/instrument.h \
../iodev/vga.h pci.h usb_common.h usb_hid.h usb_hub.h usb_msd.h \
../iodev/vga.h pci.h usb_common.h usb_hid.h usb_hub.h usb_msd.h usb_printer.h \
usb_uhci.h
vga.lo: vga.@CPP_SUFFIX@ iodev.h ../bochs.h ../config.h ../osdep.h \
../bx_debug/debug.h ../config.h ../osdep.h ../bxversion.h \

View File

@ -1,101 +1,99 @@
/////////////////////////////////////////////////////////////////////////
// $Id: devices.txt,v 1.2 2009-04-21 19:10:13 vruppert Exp $
// $Id: devices.txt,v 1.3 2009-12-04 13:01:41 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
MOTHER BOARD (i440FX Support) devices.cc
MOTHER BOARD (i440FX Support) devices.cc
|
+-------- 82441FX (PMC) and 82442 (DBX) emulation pci.cc
+---- 82441FX (PMC) and 82442 (DBX) emulation pci.cc
|
+-------- 82371SB (PIIX3) PCI ISA IDE XCELERATOR
+---- 82371SB (PIIX3) PCI ISA IDE XCELERATOR
| |
| +-------- PCI-to-ISA bridge pci2isa.cc
| +-------- PCI IDE controller pci_ide.cc
| +---- PCI-to-ISA bridge pci2isa.cc
| +---- PCI IDE controller pci_ide.cc
| |
| +-------- PIIX4 ACPI support acpi.cc
| +---- PIIX4 ACPI support acpi.cc
|
+-------- PCI host device mapping (Linux only) pcidev.cc
+---- PCI host device mapping (Linux only) pcidev.cc
|
+-------- Integrated peripherals
+---- Integrated peripherals
| |
| +-------- 8259A PIC pic.cc
| +-------- 82093AA I/O APIC ioapic.cc
| +-------- 8254/82C54 Programmable Interval Timer pit_wrap.cc, pit82c54.cc
| +---- 8259A PIC pic.cc
| +---- 82093AA I/O APIC ioapic.cc
| +---- 8254/82C54 Programmable Interval Timer pit_wrap.cc, pit82c54.cc
| | |
| | +-------- PC Speaker (lowlevel) speaker.cc
| +-------- 8237 DMA controller dma.cc
| +-------- 82077A Floppy Drive Controller floppy.cc
| +-------- CMOS device cmos.cc
| +-------- External circuit for #FERR pin extfpuirq.cc
| +-------- Parallel ports emulation parallel.cc
| +-------- UART 16550A Serial Port serial.cc
| | +---- PC Speaker (lowlevel) speaker.cc
| +---- 8237 DMA controller dma.cc
| +---- 82077A Floppy Drive Controller floppy.cc
| +---- CMOS device cmos.cc
| +---- External circuit for #FERR pin extfpuirq.cc
| +---- Parallel ports emulation parallel.cc
| +---- UART 16550A Serial Port serial.cc
| | |
| | +-------- Host specific Modules serial_raw.cc
| |
| +-------- Standard PC gameport gameport.cc
| | +---- Host specific Modules serial_raw.cc
| +---- Standard PC gameport gameport.cc
|
+---------------------- Debugging/Instrumentation biosdev.cc, iodebug.cc, unmapped.cc
+-------------- Debugging/Instrumentation biosdev.cc, iodebug.cc, unmapped.cc
Attached devices
|
+-------- PS/2 Keyboard and Mouse keyboard.cc, scancodes.cc
+---- PS/2 Keyboard and Mouse keyboard.cc, scancodes.cc
|
+-------- Bus Mouse (not complete) busmouse.cc
+---- Bus Mouse (not complete) busmouse.cc
|
+-------- Hard Drive + ATA controller harddrv.cc
+---- Hard Drive + ATA controller harddrv.cc
| |
| +-------- Hard Drive image support (*) hdimage.cc, vmware3.cc, vmware4.cc
| +---- Hard Drive image support (*) hdimage.cc, vmware3.cc, vmware4.cc
| |
| +-------- CD/DVD-ROM image / device access (*) cdrom.cc
| +---- CD/DVD-ROM image / device access (*) cdrom.cc
| |
| +-------- Host specific Modules cdrom_amigaos.cc, cdrom_beos.cc
|
+-------- Network Support
| +---- Host specific Modules cdrom_amigaos.cc, cdrom_beos.cc
+---- Network Support
| |
| +-------- Network Devices
| +---- Network Devices
| | |
| | +-------- NE2000 (ISA/PCI) ne2k.cc, pcipnic.cc
| | +-------- PCI Pseudo NIC pcipnic.cc
| | +---- NE2000 (ISA/PCI) ne2k.cc, pcipnic.cc
| | +---- PCI Pseudo NIC pcipnic.cc
| |
| +-------- Networking Modules eth.cc
| +---- Networking Modules eth.cc
| |
| +-------- Dummy module eth_null.cc
| +-------- ARP simulator eth_arpback.cc, eth_packetmaker.cc, crc32.cc
| +-------- Host specific Modules eth_fbsd.cc, eth_linux.cc, eth_win32.cc
| +-------- TAP Interface eth_tap.cc
| +-------- TUN/TAP Interface eth_tuntap.cc
| +-------- VDE Interface eth_vde.cc
| +-------- virtual Ethernet locator eth_vnet.cc
| +---- Dummy module eth_null.cc
| +---- ARP simulator eth_arpback.cc, eth_packetmaker.cc, crc32.cc
| +---- Host specific Modules eth_fbsd.cc, eth_linux.cc, eth_win32.cc
| +---- TAP Interface eth_tap.cc
| +---- TUN/TAP Interface eth_tuntap.cc
| +---- VDE Interface eth_vde.cc
| +---- virtual Ethernet locator eth_vnet.cc
|
+-------- Graphics
+---- Graphics
| |
| +-------- VGA, PCI VGA adapter vga.cc, pci_vga.cc
| +-------- Cirrus Logic PCI/ISA CLGD5446 SVGA adapter svga_cirrus.cc
| +---- VGA, PCI VGA adapter vga.cc, pci_vga.cc
| +---- Cirrus Logic PCI/ISA CLGD5446 SVGA adapter svga_cirrus.cc
|
+-------- Sound support
+---- Sound support
| |
| +-------- Sound Blaster SB16 sb16.cc
| +---- Sound Blaster SB16 sb16.cc
| |
| +-------- Host specific Modules soundlnx.cc, soundosx.cc, soundwin.cc
| +---- Host specific Modules soundlnx.cc, soundosx.cc, soundwin.cc
|
+-------- PCI USB adapter usb_common.cc
+---- PCI USB adapter usb_common.cc
|
+-------- Host Controllers
+---- Host Controllers
| |
| +-------- USB OHCI adapter usb_ohci.cc
| +-------- USB UHCI adapter (PIIX3) usb_uhci.cc
| +---- USB OHCI adapter usb_ohci.cc
| +---- USB UHCI adapter (PIIX3) usb_uhci.cc
|
+-------- Attached USB devices usb_common.cc
+---- Attached USB devices usb_common.cc
|
+-------- USB HID emulation usb_hid.cc
+-------- USB external HUB usb_hub.cc
+-------- USB mass storage device (*) usb_msd.cc, scsi_device.cc
+---- USB HID emulation usb_hid.cc
+---- USB external HUB usb_hub.cc
+---- USB mass storage device (*) usb_msd.cc, scsi_device.cc
+---- USB HP DeskJet 920C printer usb_printer.cc
(*) USB MSD uses hdimage.cc and cdrom.cc for image / device access
BOCHS timer sycronisation modules
|
+-------- Slowdown timer slowdown_timer.cc
|
+-------- Virtual timer virt_timer.cc
+---- Slowdown timer slowdown_timer.cc
+---- Virtual timer virt_timer.cc
TODO:

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_common.cc,v 1.12 2009-04-12 07:26:58 vruppert Exp $
// $Id: usb_common.cc,v 1.13 2009-12-04 13:01:41 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net)
@ -17,6 +17,7 @@
// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
/////////////////////////////////////////////////////////////////////////
// Experimental PCI USB adapter
@ -51,6 +52,7 @@
#include "usb_hid.h"
#include "usb_hub.h"
#include "usb_msd.h"
#include "usb_printer.h"
#define LOG_THIS
@ -98,6 +100,14 @@ usbdev_type usb_init_device(const char *devname, logfunctions *hub, usb_device_c
}
}
*device = new usb_hub_device_c(ports);
} else if (!strncmp(devname, "printer", 7)) {
if ((strlen(devname) > 8) && (devname[7] == ':')) {
type = USB_DEV_TYPE_PRINTER;
*device = new usb_printer_device_c(type, devname+8);
} else {
hub->panic("USB device 'printer' needs a filename separated with a colon");
return type;
}
} else {
hub->panic("unknown USB device: %s", devname);
return type;
@ -300,7 +310,8 @@ void usb_device_c::register_state(bx_list_c *parent)
}
// base class for USB devices
usb_device_c::usb_device_c(void) {
usb_device_c::usb_device_c(void)
{
memset((void*)&d, 0, sizeof(d));
}

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_common.h,v 1.10 2009-04-10 20:26:14 vruppert Exp $
// $Id: usb_common.h,v 1.11 2009-12-04 13:01:41 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin D Lunt (fys at frontiernet net)
@ -20,7 +20,6 @@
//
/////////////////////////////////////////////////////////////////////////
#ifndef BX_IODEV_USB_COMMON_H
#define BX_IODEV_USB_COMMON_H
@ -68,16 +67,16 @@
#define DeviceRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
#define DeviceOutRequest ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
#define InterfaceRequest \
((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
#define InterfaceInClassRequest \
((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE)<<8)
((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE)<<8)
#define InterfaceOutRequest \
((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
#define InterfaceOutClassRequest \
((USB_DIR_OUT|USB_TYPE_CLASS|USB_RECIP_INTERFACE)<<8)
((USB_DIR_OUT|USB_TYPE_CLASS|USB_RECIP_INTERFACE)<<8)
#define EndpointRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
#define EndpointOutRequest \
((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
#define USB_REQ_GET_STATUS 0x00
#define USB_REQ_CLEAR_FEATURE 0x01
@ -123,16 +122,16 @@ enum usbdev_type {
USB_DEV_TYPE_KEYPAD,
USB_DEV_TYPE_DISK,
USB_DEV_TYPE_CDROM,
USB_DEV_TYPE_HUB
USB_DEV_TYPE_HUB,
USB_DEV_TYPE_PRINTER
};
usbdev_type usb_init_device(const char *devname, logfunctions *hc, usb_device_c **device);
class usb_device_c : public logfunctions {
public:
usb_device_c(void);
virtual ~usb_device_c(void) {}
virtual ~usb_device_c() {}
virtual int handle_packet(USBPacket *p);
virtual void handle_reset() {}
@ -173,12 +172,12 @@ protected:
int set_usb_string(Bit8u *buf, const char *str);
};
static inline void usb_defer_packet(USBPacket *p, usb_device_c *dev)
static BX_CPP_INLINE void usb_defer_packet(USBPacket *p, usb_device_c *dev)
{
p->dev = dev;
}
static inline void usb_cancel_packet(USBPacket *p)
static BX_CPP_INLINE void usb_cancel_packet(USBPacket *p)
{
p->dev->cancel_packet(p);
}

322
bochs/iodev/usb_printer.cc Executable file
View File

@ -0,0 +1,322 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_printer.cc,v 1.1 2009-12-04 13:01:41 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin David Lunt
//
// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
/////////////////////////////////////////////////////////////////////////
// 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
#define NO_DEVICE_INCLUDES
#include "iodev.h"
#if BX_SUPPORT_PCI && BX_SUPPORT_PCIUSB
#include "usb_common.h"
#include "usb_printer.h"
#define LOG_THIS
static const Bit8u bx_printer_dev_descriptor[] = {
0x12, /* u8 bLength; */
0x01, /* u8 bDescriptorType; Device */
0x10, 0x01, /* u16 bcdUSB; v1.10 */
0x00, /* u8 bDeviceClass; */
0x00, /* u8 bDeviceSubClass; */
0x00, /* u8 bDeviceProtocol; [ low/full speeds only ] */
0x08, /* u8 bMaxPacketSize0; 8 Bytes */
0xF0, 0x03, /* u16 idVendor; */
0x04, 0x15, /* u16 idProduct; */
0x00, 0x01, /* u16 bcdDevice */
0x01, /* u8 iManufacturer; */
0x02, /* u8 iProduct; */
0x03, /* u8 iSerialNumber; */
0x01 /* u8 bNumConfigurations; */
};
static const Bit8u bx_printer_config_descriptor[] = {
/* one configuration */
0x09, /* u8 bLength; */
0x02, /* u8 bDescriptorType; Configuration */
0x20, 0x00, /* u16 wTotalLength; */
0x01, /* u8 bNumInterfaces; (1) */
0x01, /* u8 bConfigurationValue; */
0x00, /* u8 iConfiguration string desc.; */
0xC0, /* u8 bmAttributes;
Bit 7: must be set,
6: Self-powered,
5: Remote wakeup,
4..0: resvd */
0x02, /* u8 MaxPower; */
/* one interface */
0x09, /* u8 if_bLength; */
0x04, /* u8 if_bDescriptorType; Interface */
0x00, /* u8 if_bInterfaceNumber; */
0x00, /* u8 if_bAlternateSetting; */
0x02, /* u8 if_bNumEndpoints; */
0x07, /* u8 if_bInterfaceClass; */
0x01, /* u8 if_bInterfaceSubClass; */
0x02, /* u8 if_bInterfaceProtocol; */
0x00, /* u8 if_iInterface; string desc. */
/* first endpoint */
0x07, /* u8 ep_bLength; */
0x05, /* u8 ep_bDescriptorType; Endpoint */
0x81, /* u8 ep_bEndpointAddress; IN Endpoint 1 */
0x02, /* u8 ep_bmAttributes; Bulk */
0x40, 0x00, /* u16 ep_wMaxPacketSize; */
0x00, /* u8 ep_bInterval; */
/* second endpoint */
0x07, /* u8 ep_bLength; */
0x05, /* u8 ep_bDescriptorType; Endpoint */
0x02, /* u8 ep_bEndpointAddress; OUT Endpoint 2 */
0x02, /* u8 ep_bmAttributes; Bulk */
0x40, 0x00, /* u16 ep_wMaxPacketSize; */
0x00, /* u8 ep_bInterval; */
};
// Length word calculated at run time
static const Bit8u bx_device_id_string[] =
"\0\0" // len field is calculated at run-time
"MFG:HEWLETT-PACKARD;"
"MDL:DESKJET 920C;"
"CMD:MLC,PCL,PML;"
"CLASS:PRINTER;"
"DESCRIPTION:Hewlett-Packard DeskJet 920C;"
"SERN:CN21R1C0BPIS;"
"VSTATUS:$HBO,$NCO,ff,DN,IDLE,CUT,K0,C0,SM,NR,KP093,CP097;"
"VP:0800,FL,B0;"
"VJ: ;";
usb_printer_device_c::usb_printer_device_c(usbdev_type type, const char *filename)
{
d.type = type;
d.speed = USB_SPEED_FULL;
strcpy(d.devname, "USB Printer");
d.connected = 1;
memset((void*)&s, 0, sizeof(s));
strncpy(s.fname, filename, 255);
s.fp = fopen(s.fname, "a+b");
if (s.fp == NULL)
BX_PANIC(("Could not create/open %s", s.fname));
put("USBPR");
}
usb_printer_device_c::~usb_printer_device_c(void)
{
fclose(s.fp);
}
void usb_printer_device_c::register_state_specific(bx_list_c *parent)
{
/*
bx_list_c *key;
Bit8u i;
char name[6];
bx_list_c *list = new bx_list_c(parent, "s", "USB HID Device State", 9);
new bx_shadow_num_c(list, "mouse_delayed_dx", &s.mouse_delayed_dx);
new bx_shadow_num_c(list, "mouse_delayed_dy", &s.mouse_delayed_dy);
new bx_shadow_num_c(list, "mouse_delayed_dz", &s.mouse_delayed_dz);
new bx_shadow_num_c(list, "mouse_x", &s.mouse_x);
new bx_shadow_num_c(list, "mouse_y", &s.mouse_y);
new bx_shadow_num_c(list, "mouse_z", &s.mouse_z);
new bx_shadow_num_c(list, "b_state", &s.b_state, BASE_HEX);
key = new bx_list_c(list, "saved_key", 8);
for (i=0; i<8; i++) {
sprintf(name, "0x%02x", i);
new bx_shadow_num_c(key, name, &s.saved_key[i], BASE_HEX);
}
key = new bx_list_c(list, "key_pad_packet", 8);
for (i=0; i<8; i++) {
sprintf(name, "0x%02x", i);
new bx_shadow_num_c(key, name, &s.key_pad_packet[i], BASE_HEX);
}
*/
}
void usb_printer_device_c::handle_reset()
{
BX_INFO(("Openned: %s for USB HP Deskjet 920C printer emulation.", s.fname));
BX_DEBUG(("Reset"));
}
int usb_printer_device_c::handle_control(int request, int value, int index, int length, Bit8u *data)
{
int ret = 0;
BX_DEBUG(("Printer: request: 0x%04X value: 0x%04X index: 0x%04X len: %i", request, value, index, length));
switch(request) {
case DeviceRequest | USB_REQ_GET_STATUS:
if (d.state == USB_STATE_DEFAULT)
goto fail;
else {
data[0] = (1 << USB_DEVICE_SELF_POWERED) |
(d.remote_wakeup << USB_DEVICE_REMOTE_WAKEUP);
data[1] = 0x00;
ret = 2;
}
break;
case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
if (value == USB_DEVICE_REMOTE_WAKEUP) {
d.remote_wakeup = 0;
} else {
goto fail;
}
ret = 0;
break;
case DeviceOutRequest | USB_REQ_SET_FEATURE:
if (value == USB_DEVICE_REMOTE_WAKEUP) {
d.remote_wakeup = 1;
} else {
goto fail;
}
ret = 0;
break;
case DeviceOutRequest | USB_REQ_SET_ADDRESS:
d.state = USB_STATE_ADDRESS;
d.addr = value;
ret = 0;
break;
case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
switch(value >> 8) {
case USB_DT_DEVICE:
memcpy(data, bx_printer_dev_descriptor, sizeof(bx_printer_dev_descriptor));
ret = sizeof(bx_printer_dev_descriptor);
break;
case USB_DT_CONFIG:
memcpy(data, bx_printer_config_descriptor, sizeof(bx_printer_config_descriptor));
ret = sizeof(bx_printer_config_descriptor);
break;
case USB_DT_STRING:
switch(value & 0xff) {
case 0:
/* language ids */
data[0] = 4;
data[1] = 3;
data[2] = 0x09;
data[3] = 0x04;
ret = 4;
break;
case 1:
/* vendor description */
ret = set_usb_string(data, "Hewlett-Packard");
break;
case 2:
/* product description */
ret = set_usb_string(data, "Deskjet 920C");
break;
case 3:
/* serial number */
ret = set_usb_string(data, "HU18L6P2DNBI");
break;
default:
BX_ERROR(("USB Printer handle_control: unknown string descriptor 0x%02x", value & 0xff));
goto fail;
}
break;
default:
BX_ERROR(("USB Printer handle_control: unknown descriptor type 0x%02x", value >> 8));
goto fail;
}
break;
case DeviceRequest | USB_REQ_GET_CONFIGURATION:
data[0] = 1;
ret = 1;
break;
case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
d.state = USB_STATE_CONFIGURED;
ret = 0;
break;
case DeviceRequest | USB_REQ_GET_INTERFACE:
data[0] = 0;
ret = 1;
break;
case DeviceOutRequest | USB_REQ_SET_INTERFACE:
ret = 0;
break;
/* printer specific requests */
case InterfaceInClassRequest | 0x00: // 1284 get device id string
memcpy(data, bx_device_id_string, sizeof(bx_device_id_string));
ret = sizeof(bx_device_id_string);
data[0] = (Bit8u) (ret >> 8); // len word is big endian
data[1] = (Bit8u) (ret & 0xFF); //
break;
case InterfaceInClassRequest | 0x01: // Get Port Status
s.printer_status = (0<<5) | (1<<4) | (1<<3);
memcpy(data, &s.printer_status, 1);
ret = 1;
break;
case InterfaceOutClassRequest | 0x02: // soft reset
// for now, just return
ret = 0;
break;
default:
BX_ERROR(("USB PRINTER handle_control: unknown request 0x%04x", request));
fail:
d.stall = 1;
ret = USB_RET_STALL;
break;
}
return ret;
}
int usb_printer_device_c::handle_data(USBPacket *p)
{
int ret = 0;
switch(p->pid) {
case USB_TOKEN_IN:
if (p->devep == 1) {
BX_INFO(("Printer: handle_data: IN: len = %i", p->len));
BX_INFO(("Printer: Ben: We need to find out what this is and send valid status back"));
ret = p->len;
} else {
goto fail;
}
break;
case USB_TOKEN_OUT:
if (p->devep == 2) {
BX_DEBUG(("Sent %i bytes to the 'usb printer': %s", p->len, s.fname));
usb_dump_packet(p->data, p->len);
fwrite(p->data, 1, p->len, s.fp);
ret = p->len;
} else {
goto fail;
}
break;
default:
fail:
d.stall = 1;
ret = USB_RET_STALL;
break;
}
return ret;
}
#endif // BX_SUPPORT_PCI && BX_SUPPORT_PCIUSB

43
bochs/iodev/usb_printer.h Executable file
View File

@ -0,0 +1,43 @@
/////////////////////////////////////////////////////////////////////////
// $Id: usb_printer.h,v 1.1 2009-12-04 13:01:41 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2009 Benjamin David Lunt
//
// 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
/////////////////////////////////////////////////////////////////////////
#ifndef BX_IODEV_USB_PRINTER_H
#define BX_IODEV_USB_PRINTER_H
class usb_printer_device_c : public usb_device_c {
public:
usb_printer_device_c(usbdev_type type, const char *filename);
virtual ~usb_printer_device_c(void);
virtual void handle_reset();
virtual int handle_control(int request, int value, int index, int length, Bit8u *data);
virtual int handle_data(USBPacket *p);
virtual void register_state_specific(bx_list_c *parent);
private:
struct {
Bit8u printer_status;
char fname[256];
FILE *fp;
} s;
};
#endif