2001-04-10 06:20:02 +04:00
|
|
|
// Copyright (C) 2001 MandrakeSoft S.A.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
|
|
// These are the low-level CDROM functions which are called
|
|
|
|
// from 'harddrv.cc'. They effect the OS specific functionality
|
|
|
|
// needed by the CDROM emulation in 'harddrv.cc'. Mostly, just
|
|
|
|
// ioctl() calls and such. Should be fairly easy to add support
|
|
|
|
// for your OS if it is not supported yet.
|
|
|
|
|
|
|
|
|
|
|
|
#include "bochs.h"
|
|
|
|
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
#define LOG_THIS /* no SMF tricks here, not needed */
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#ifdef __linux__
|
|
|
|
extern "C" {
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/cdrom.h>
|
|
|
|
// I use the framesize in non OS specific code too
|
|
|
|
#define BX_CD_FRAMESIZE CD_FRAMESIZE
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-04-10 06:15:31 +04:00
|
|
|
#ifdef __sun
|
|
|
|
extern "C" {
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/cdio.h>
|
|
|
|
#define BX_CD_FRAMESIZE CDROM_BLK_2048
|
|
|
|
}
|
|
|
|
#endif /* __sun */
|
|
|
|
|
2001-05-16 21:39:07 +04:00
|
|
|
#if (defined(__OpenBSD__) || defined(__FreeBSD__))
|
2001-05-08 23:51:46 +04:00
|
|
|
// OpenBSD pre version 2.7 may require extern "C" { } structure around
|
|
|
|
// all the includes, because the i386 sys/disklabel.h contains code which
|
|
|
|
// c++ considers invalid.
|
2001-04-10 05:04:59 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/cdio.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
|
|
|
|
// XXX
|
|
|
|
#define BX_CD_FRAMESIZE 2048
|
|
|
|
#define CD_FRAMESIZE 2048
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#include <winioctl.h>
|
|
|
|
#define BX_CD_FRAMESIZE 2048
|
|
|
|
#define CD_FRAMESIZE 2048
|
|
|
|
HANDLE hFile = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cdrom_interface::cdrom_interface(char *dev)
|
|
|
|
{
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
setprefix("[CD ]");
|
|
|
|
settype(CDLOG);
|
2001-04-10 05:04:59 +04:00
|
|
|
fd = -1; // File descriptor not yet allocated
|
|
|
|
|
|
|
|
if ( dev == NULL )
|
|
|
|
path = NULL;
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
else {
|
2001-04-10 05:04:59 +04:00
|
|
|
path = strdup(dev);
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("Init, file = '%s'",dev));
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cdrom_interface::~cdrom_interface(void)
|
|
|
|
{
|
|
|
|
if (fd >= 0)
|
|
|
|
close(fd);
|
|
|
|
if (path)
|
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
cdrom_interface::insert_cdrom()
|
|
|
|
{
|
|
|
|
unsigned char buffer[BX_CD_FRAMESIZE];
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
// Load CD-ROM. Returns false if CD is not ready.
|
|
|
|
#ifdef WIN32
|
2001-04-10 06:17:10 +04:00
|
|
|
char drive[256];
|
|
|
|
sprintf(drive, "\\\\.\\%s", path);
|
|
|
|
hFile=CreateFile((char *)&drive, GENERIC_READ, 0 , NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL);
|
2001-04-10 05:04:59 +04:00
|
|
|
//printf("%s", path);
|
|
|
|
//hFile=CreateFile(path, GENERIC_READ, 0 , NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL);
|
|
|
|
if (hFile !=(void *)0xFFFFFFFF)
|
|
|
|
fd=1;
|
|
|
|
#else
|
|
|
|
fd = open(path, O_RDONLY);
|
|
|
|
#endif
|
|
|
|
if (fd < 0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(( "::cdrom_interface: open failed on dev '%s'.", path));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// I just see if I can read a sector to verify that a
|
|
|
|
// CD is in the drive and readable.
|
|
|
|
#ifdef WIN32
|
|
|
|
ReadFile(hFile, (void *) buffer, BX_CD_FRAMESIZE, (unsigned long *) &ret, NULL);
|
|
|
|
if (ret < 0) {
|
|
|
|
CloseHandle(hFile);
|
|
|
|
fd = -1;
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(( "insert_cdrom: read returns error." ));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
ret = read(fd, &buffer, BX_CD_FRAMESIZE);
|
|
|
|
if (ret < 0) {
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(( "insert_cdrom: read returns error." ));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
cdrom_interface::eject_cdrom()
|
|
|
|
{
|
|
|
|
// Logically eject the CD. I suppose we could stick in
|
|
|
|
// some ioctl() calls to really eject the CD as well.
|
|
|
|
|
|
|
|
if (fd >= 0) {
|
2001-05-16 21:39:07 +04:00
|
|
|
#if (defined(__OpenBSD__) || defined(__FreeBSD__))
|
2001-04-10 05:04:59 +04:00
|
|
|
(void) ioctl (fd, CDIOCALLOW);
|
|
|
|
if (ioctl (fd, CDIOCEJECT) < 0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(( "eject_cdrom: eject returns error." ));
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
DWORD lpBytesReturned;
|
|
|
|
DeviceIoControl(hFile, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &lpBytesReturned, NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
cdrom_interface::read_toc(uint8* buf, int* length, bool msf, int start_track)
|
|
|
|
{
|
|
|
|
// Read CD TOC. Returns false if start track is out of bounds.
|
|
|
|
|
|
|
|
if (fd < 0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: read_toc: file not open."));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
{
|
|
|
|
/* #define IOCTL_CDROM_BASE FILE_DEVICE_CD_ROM
|
|
|
|
#define IOCTL_CDROM_READ_TOC CTL_CODE(IOCTL_CDROM_BASE, 0x0000, METHOD_BUFFERED, FILE_READ_ACCESS)
|
|
|
|
unsigned long iBytesReturned;
|
|
|
|
DeviceIoControl(hFile, IOCTL_CDROM_READ_TOC, NULL, 0, NULL, 0, &iBytesReturned, NULL); */
|
|
|
|
return true;
|
|
|
|
}
|
2001-04-10 06:15:31 +04:00
|
|
|
#elif __linux__ || defined(__sun)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
struct cdrom_tochdr tochdr;
|
|
|
|
if (ioctl(fd, CDROMREADTOCHDR, &tochdr))
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: read_toc: READTOCHDR failed."));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (start_track > tochdr.cdth_trk1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
buf[2] = tochdr.cdth_trk0;
|
|
|
|
buf[3] = tochdr.cdth_trk1;
|
|
|
|
|
|
|
|
if (start_track < tochdr.cdth_trk0)
|
|
|
|
start_track = tochdr.cdth_trk0;
|
|
|
|
|
|
|
|
int len = 4;
|
|
|
|
for (int i = start_track; i <= tochdr.cdth_trk1; i++) {
|
|
|
|
struct cdrom_tocentry tocentry;
|
|
|
|
tocentry.cdte_format = (msf) ? CDROM_MSF : CDROM_LBA;
|
|
|
|
tocentry.cdte_track = i;
|
|
|
|
if (ioctl(fd, CDROMREADTOCENTRY, &tocentry))
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: read_toc: READTOCENTRY failed."));
|
2001-04-10 05:04:59 +04:00
|
|
|
buf[len++] = 0; // Reserved
|
|
|
|
buf[len++] = (tocentry.cdte_adr << 4) | tocentry.cdte_ctrl ; // ADR, control
|
|
|
|
buf[len++] = i; // Track number
|
|
|
|
buf[len++] = 0; // Reserved
|
|
|
|
|
|
|
|
// Start address
|
|
|
|
if (msf) {
|
|
|
|
buf[len++] = 0; // reserved
|
|
|
|
buf[len++] = tocentry.cdte_addr.msf.minute;
|
|
|
|
buf[len++] = tocentry.cdte_addr.msf.second;
|
|
|
|
buf[len++] = tocentry.cdte_addr.msf.frame;
|
|
|
|
} else {
|
|
|
|
buf[len++] = (((unsigned)tocentry.cdte_addr.lba) >> 24) & 0xff;
|
|
|
|
buf[len++] = (((unsigned)tocentry.cdte_addr.lba) >> 16) & 0xff;
|
|
|
|
buf[len++] = (((unsigned)tocentry.cdte_addr.lba) >> 8) & 0xff;
|
|
|
|
buf[len++] = (((unsigned)tocentry.cdte_addr.lba) >> 0) & 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lead out track
|
|
|
|
struct cdrom_tocentry tocentry;
|
|
|
|
tocentry.cdte_format = (msf) ? CDROM_MSF : CDROM_LBA;
|
2001-04-10 06:15:31 +04:00
|
|
|
#ifdef CDROM_LEADOUT
|
|
|
|
tocentry.cdte_track = CDROM_LEADOUT;
|
|
|
|
#else
|
2001-04-10 05:04:59 +04:00
|
|
|
tocentry.cdte_track = 0xaa;
|
2001-04-10 06:15:31 +04:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
if (ioctl(fd, CDROMREADTOCENTRY, &tocentry))
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: read_toc: READTOCENTRY lead-out failed."));
|
2001-04-10 05:04:59 +04:00
|
|
|
buf[len++] = 0; // Reserved
|
|
|
|
buf[len++] = (tocentry.cdte_adr << 4) | tocentry.cdte_ctrl ; // ADR, control
|
|
|
|
buf[len++] = 0xaa; // Track number
|
|
|
|
buf[len++] = 0; // Reserved
|
|
|
|
|
|
|
|
// Start address
|
|
|
|
if (msf) {
|
|
|
|
buf[len++] = 0; // reserved
|
|
|
|
buf[len++] = tocentry.cdte_addr.msf.minute;
|
|
|
|
buf[len++] = tocentry.cdte_addr.msf.second;
|
|
|
|
buf[len++] = tocentry.cdte_addr.msf.frame;
|
|
|
|
} else {
|
|
|
|
buf[len++] = (((unsigned)tocentry.cdte_addr.lba) >> 24) & 0xff;
|
|
|
|
buf[len++] = (((unsigned)tocentry.cdte_addr.lba) >> 16) & 0xff;
|
|
|
|
buf[len++] = (((unsigned)tocentry.cdte_addr.lba) >> 8) & 0xff;
|
|
|
|
buf[len++] = (((unsigned)tocentry.cdte_addr.lba) >> 0) & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[0] = ((len-2) >> 8) & 0xff;
|
|
|
|
buf[1] = (len-2) & 0xff;
|
|
|
|
|
|
|
|
*length = len;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2001-05-16 21:39:07 +04:00
|
|
|
#elif (defined(__OpenBSD__) || defined(__FreeBSD__))
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
struct ioc_toc_header h;
|
|
|
|
struct ioc_read_toc_entry t;
|
|
|
|
|
|
|
|
if (ioctl (fd, CDIOREADTOCHEADER, &h) < 0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: read_toc: READTOCHDR failed."));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (start_track > h.ending_track)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
buf[2] = h.starting_track;
|
|
|
|
buf[3] = h.ending_track;
|
|
|
|
|
|
|
|
if (start_track < h.starting_track)
|
|
|
|
start_track = h.starting_track;
|
|
|
|
|
|
|
|
int len = 4;
|
|
|
|
for (int i = start_track; i <= h.ending_track; i++) {
|
|
|
|
struct cd_toc_entry tocentry;
|
|
|
|
t.address_format = (msf) ? CD_MSF_FORMAT : CD_LBA_FORMAT;
|
|
|
|
t.starting_track = i;
|
|
|
|
t.data_len = sizeof(tocentry);
|
|
|
|
t.data = &tocentry;
|
|
|
|
|
|
|
|
if (ioctl (fd, CDIOREADTOCENTRYS, &tocentry) < 0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: read_toc: READTOCENTRY failed."));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
buf[len++] = 0; // Reserved
|
|
|
|
buf[len++] = (tocentry.addr_type << 4) | tocentry.control ; // ADR, control
|
|
|
|
buf[len++] = i; // Track number
|
|
|
|
buf[len++] = 0; // Reserved
|
|
|
|
|
|
|
|
// Start address
|
|
|
|
if (msf) {
|
|
|
|
buf[len++] = 0; // reserved
|
|
|
|
buf[len++] = tocentry.addr.msf.minute;
|
|
|
|
buf[len++] = tocentry.addr.msf.second;
|
|
|
|
buf[len++] = tocentry.addr.msf.frame;
|
|
|
|
} else {
|
|
|
|
buf[len++] = (((unsigned)tocentry.addr.lba) >> 24) & 0xff;
|
|
|
|
buf[len++] = (((unsigned)tocentry.addr.lba) >> 16) & 0xff;
|
|
|
|
buf[len++] = (((unsigned)tocentry.addr.lba) >> 8) & 0xff;
|
|
|
|
buf[len++] = (((unsigned)tocentry.addr.lba) >> 0) & 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lead out track
|
|
|
|
struct cd_toc_entry tocentry;
|
|
|
|
t.address_format = (msf) ? CD_MSF_FORMAT : CD_LBA_FORMAT;
|
|
|
|
t.starting_track = 0xaa;
|
|
|
|
t.data_len = sizeof(tocentry);
|
|
|
|
t.data = &tocentry;
|
|
|
|
|
|
|
|
if (ioctl (fd, CDIOREADTOCENTRYS, &tocentry) < 0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: read_toc: READTOCENTRY lead-out failed."));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
buf[len++] = 0; // Reserved
|
|
|
|
buf[len++] = (tocentry.addr_type << 4) | tocentry.control ; // ADR, control
|
|
|
|
buf[len++] = 0xaa; // Track number
|
|
|
|
buf[len++] = 0; // Reserved
|
|
|
|
|
|
|
|
// Start address
|
|
|
|
if (msf) {
|
|
|
|
buf[len++] = 0; // reserved
|
|
|
|
buf[len++] = tocentry.addr.msf.minute;
|
|
|
|
buf[len++] = tocentry.addr.msf.second;
|
|
|
|
buf[len++] = tocentry.addr.msf.frame;
|
|
|
|
} else {
|
|
|
|
buf[len++] = (((unsigned)tocentry.addr.lba) >> 24) & 0xff;
|
|
|
|
buf[len++] = (((unsigned)tocentry.addr.lba) >> 16) & 0xff;
|
|
|
|
buf[len++] = (((unsigned)tocentry.addr.lba) >> 8) & 0xff;
|
|
|
|
buf[len++] = (((unsigned)tocentry.addr.lba) >> 0) & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[0] = ((len-2) >> 8) & 0xff;
|
|
|
|
buf[1] = (len-2) & 0xff;
|
|
|
|
|
|
|
|
*length = len;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("read_toc: your OS is not supported yet."));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(false); // OS not supported yet, return false always.
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32
|
|
|
|
cdrom_interface::capacity()
|
|
|
|
{
|
|
|
|
// Return CD-ROM capacity. I believe you want to return
|
|
|
|
// the number of bytes of capacity the actual media has.
|
2001-04-10 06:15:31 +04:00
|
|
|
#ifdef __sun
|
|
|
|
{
|
|
|
|
struct stat buf = {0};
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-04-10 06:15:31 +04:00
|
|
|
if (fd < 0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: capacity: file not open."));
|
2001-04-10 06:15:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if( fstat(fd, &buf) != 0 )
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: capacity: stat() failed."));
|
2001-04-10 06:15:31 +04:00
|
|
|
|
|
|
|
return(buf.st_size);
|
|
|
|
}
|
|
|
|
#elif __linux__
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
// I just looked through the Linux kernel source to see
|
|
|
|
// what it does with the ATAPI capacity command, and reversed
|
|
|
|
// that process here.
|
|
|
|
uint32 nr_sects;
|
|
|
|
|
|
|
|
if (fd < 0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: capacity: file not open."));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
if (ioctl(fd, BLKGETSIZE, &nr_sects) != 0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: ioctl(BLKGETSIZE) failed"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
nr_sects /= (CD_FRAMESIZE / 512);
|
|
|
|
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(( "capacity: %u", nr_sects));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(nr_sects);
|
|
|
|
}
|
|
|
|
#elif defined(__OpenBSD__)
|
|
|
|
{
|
|
|
|
// We just read the disklabel, imagine that...
|
|
|
|
struct disklabel lp;
|
|
|
|
|
|
|
|
if (fd < 0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: capacity: file not open."));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
if (ioctl(fd, DIOCGDINFO, &lp) < 0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: ioctl(DIOCGDINFO) failed"));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(( "capacity: %u", lp.d_secperunit ));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(lp.d_secperunit);
|
2001-05-16 21:39:07 +04:00
|
|
|
}
|
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
{
|
|
|
|
// Read the TOC to get the data size, since disklabel doesn't appear
|
|
|
|
// to work, sadly.
|
|
|
|
// Keith Jones, 16 January 2000
|
|
|
|
|
|
|
|
#define MAX_TRACKS 100
|
|
|
|
|
|
|
|
int i, num_tracks, num_sectors;
|
|
|
|
struct ioc_toc_header td;
|
|
|
|
struct ioc_read_toc_entry rte;
|
|
|
|
struct cd_toc_entry toc_buffer[MAX_TRACKS + 1];
|
|
|
|
|
|
|
|
if (fd < 0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: capacity: file not open."));
|
2001-05-16 21:39:07 +04:00
|
|
|
|
|
|
|
if (ioctl(fd, CDIOREADTOCHEADER, &td) < 0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: ioctl(CDIOREADTOCHEADER) failed"));
|
2001-05-16 21:39:07 +04:00
|
|
|
|
|
|
|
num_tracks = (td.ending_track - td.starting_track) + 1;
|
|
|
|
if (num_tracks > MAX_TRACKS)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: TOC is too large"));
|
2001-05-16 21:39:07 +04:00
|
|
|
|
|
|
|
rte.address_format = CD_LBA_FORMAT;
|
|
|
|
rte.starting_track = td.starting_track;
|
|
|
|
rte.data_len = (num_tracks + 1) * sizeof(struct cd_toc_entry);
|
|
|
|
rte.data = toc_buffer;
|
|
|
|
if (ioctl(fd, CDIOREADTOCENTRYS, &rte) < 0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: ioctl(CDIOREADTOCENTRYS) failed"));
|
2001-05-16 21:39:07 +04:00
|
|
|
|
|
|
|
num_sectors = -1;
|
|
|
|
for (i = 0; i < num_tracks; i++) {
|
|
|
|
if (rte.data[i].control & 4) { /* data track */
|
|
|
|
num_sectors = ntohl(rte.data[i + 1].addr.lba)
|
|
|
|
- ntohl(rte.data[i].addr.lba);
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_ERROR(( "cdrom: Data track %d, length %d",
|
|
|
|
rte.data[i].track, num_sectors));
|
2001-05-16 21:39:07 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_sectors < 0)
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: no data track found"));
|
2001-05-16 21:39:07 +04:00
|
|
|
|
|
|
|
return(num_sectors);
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
#elif defined WIN32
|
|
|
|
{
|
|
|
|
unsigned long FileSize;
|
|
|
|
return (GetFileSize(hFile, &FileSize)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
#else
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(( "capacity: your OS is not supported yet." ));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cdrom_interface::read_block(uint8* buf, int lba)
|
|
|
|
{
|
|
|
|
// Read a single block from the CD
|
|
|
|
|
|
|
|
off_t pos;
|
|
|
|
ssize_t n;
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
pos = SetFilePointer(hFile, lba*BX_CD_FRAMESIZE, NULL, SEEK_SET);
|
|
|
|
if (pos == 0xffffffff) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: read_block: lseek returned error."));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
pos = lseek(fd, lba*BX_CD_FRAMESIZE, SEEK_SET);
|
|
|
|
if (pos < 0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: read_block: lseek returned error."));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
ReadFile(hFile, (void *) buf, BX_CD_FRAMESIZE, (unsigned long *) &n, NULL);
|
|
|
|
#else
|
|
|
|
n = read(fd, buf, BX_CD_FRAMESIZE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (n != BX_CD_FRAMESIZE) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("cdrom: read_block: read returned %d",
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
(int) n));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|