2017-09-30 16:56:38 -04:00
|
|
|
/*
|
|
|
|
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
|
|
|
|
* running old operating systems and software designed for IBM
|
|
|
|
|
* PC systems and compatibles from 1981 through fairly recent
|
|
|
|
|
* system designs based on the PCI bus.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the 86Box distribution.
|
|
|
|
|
*
|
|
|
|
|
* Common code to handle all sorts of disk controllers.
|
|
|
|
|
*
|
2018-05-21 19:04:05 +02:00
|
|
|
* Version: @(#)hdc.c 1.0.15 2018/04/29
|
2017-09-30 16:56:38 -04:00
|
|
|
*
|
|
|
|
|
* Authors: Miran Grca, <mgrca8@gmail.com>
|
|
|
|
|
* Fred N. van Kempen, <decwiz@yahoo.com>
|
2017-10-17 01:59:09 -04:00
|
|
|
*
|
2018-02-14 13:52:19 +01:00
|
|
|
* Copyright 2016-2018 Miran Grca.
|
|
|
|
|
* Copyright 2017,2018 Fred N. van Kempen.
|
2017-09-30 16:56:38 -04:00
|
|
|
*/
|
2018-05-21 19:04:05 +02:00
|
|
|
#include <stdarg.h>
|
2017-09-30 16:56:38 -04:00
|
|
|
#include <stdint.h>
|
2018-05-21 19:04:05 +02:00
|
|
|
#include <stdio.h>
|
2017-09-30 16:56:38 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <wchar.h>
|
2018-05-21 19:04:05 +02:00
|
|
|
#define HAVE_STDARG_H
|
2017-10-17 01:59:09 -04:00
|
|
|
#include "../86box.h"
|
2017-09-30 16:56:38 -04:00
|
|
|
#include "../machine/machine.h"
|
2017-11-02 02:28:00 -05:00
|
|
|
#include "../device.h"
|
2017-09-30 16:56:38 -04:00
|
|
|
#include "hdc.h"
|
2018-03-17 20:32:20 +01:00
|
|
|
#include "hdc_ide.h"
|
2018-04-25 23:51:13 +02:00
|
|
|
#include "hdd.h"
|
2017-09-30 16:56:38 -04:00
|
|
|
|
|
|
|
|
|
2017-10-19 23:55:51 +02:00
|
|
|
char *hdc_name; /* configured HDC name */
|
2017-10-02 02:15:35 -04:00
|
|
|
int hdc_current;
|
2017-09-30 16:56:38 -04:00
|
|
|
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
#ifdef ENABLE_HDC_LOG
|
|
|
|
|
int hdc_do_log = ENABLE_HDC_LOG;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
hdc_log(const char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
#ifdef ENABLE_HDC_LOG
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
if (hdc_do_log) {
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
pclog_ex(fmt, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-09-30 16:56:38 -04:00
|
|
|
static void *
|
2018-03-19 01:02:04 +01:00
|
|
|
null_init(const device_t *info)
|
2017-09-30 16:56:38 -04:00
|
|
|
{
|
|
|
|
|
return(NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
null_close(void *priv)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
static const device_t null_device = {
|
2017-10-07 00:46:54 -04:00
|
|
|
"Null HDC", 0, 0,
|
|
|
|
|
null_init, null_close, NULL,
|
2018-04-26 13:33:29 +02:00
|
|
|
NULL, NULL, NULL, NULL
|
2017-09-30 16:56:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2017-10-01 16:29:15 -04:00
|
|
|
static void *
|
2018-03-19 01:02:04 +01:00
|
|
|
inthdc_init(const device_t *info)
|
2017-10-01 16:29:15 -04:00
|
|
|
{
|
|
|
|
|
return(NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
inthdc_close(void *priv)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
static const device_t inthdc_device = {
|
2017-10-07 00:46:54 -04:00
|
|
|
"Internal Controller", 0, 0,
|
|
|
|
|
inthdc_init, inthdc_close, NULL,
|
2018-04-26 13:33:29 +02:00
|
|
|
NULL, NULL, NULL, NULL
|
2017-10-01 16:29:15 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
static const struct {
|
2018-03-19 08:01:13 +01:00
|
|
|
const char *name;
|
|
|
|
|
const char *internal_name;
|
2018-03-19 01:02:04 +01:00
|
|
|
const device_t *device;
|
2017-09-30 16:56:38 -04:00
|
|
|
} controllers[] = {
|
2017-11-08 16:23:28 -05:00
|
|
|
{ "None", "none",
|
2018-03-19 08:01:13 +01:00
|
|
|
&null_device },
|
2017-09-30 16:56:38 -04:00
|
|
|
|
2017-11-08 16:23:28 -05:00
|
|
|
{ "Internal Controller", "internal",
|
2018-03-19 08:01:13 +01:00
|
|
|
&inthdc_device },
|
2017-09-30 16:56:38 -04:00
|
|
|
|
2017-11-08 16:23:28 -05:00
|
|
|
{ "[ISA] [MFM] IBM PC Fixed Disk Adapter", "mfm_xt",
|
2018-03-19 08:01:13 +01:00
|
|
|
&mfm_xt_xebec_device },
|
2017-09-30 16:56:38 -04:00
|
|
|
|
2017-10-10 00:14:15 +02:00
|
|
|
{ "[ISA] [MFM] DTC-5150X Fixed Disk Adapter", "mfm_dtc5150x",
|
2018-03-19 08:01:13 +01:00
|
|
|
&mfm_xt_dtc5150x_device },
|
2017-09-30 16:56:38 -04:00
|
|
|
|
2017-10-10 00:14:15 +02:00
|
|
|
{ "[ISA] [MFM] IBM PC/AT Fixed Disk Adapter", "mfm_at",
|
2018-03-19 08:01:13 +01:00
|
|
|
&mfm_at_wd1003_device },
|
2017-09-30 16:56:38 -04:00
|
|
|
|
2017-11-08 16:23:28 -05:00
|
|
|
{ "[ISA] [ESDI] PC/AT ESDI Fixed Disk Adapter", "esdi_at",
|
2018-03-19 08:01:13 +01:00
|
|
|
&esdi_at_wd1007vse1_device },
|
2017-09-30 16:56:38 -04:00
|
|
|
|
2017-11-08 16:23:28 -05:00
|
|
|
{ "[ISA] [IDE] PC/AT IDE Adapter", "ide_isa",
|
2018-03-19 08:01:13 +01:00
|
|
|
&ide_isa_device },
|
2017-10-01 16:29:15 -04:00
|
|
|
|
2018-02-14 13:52:19 +01:00
|
|
|
{ "[ISA] [IDE] PC/AT IDE Adapter (Dual-Channel)", "ide_isa_2ch",
|
2018-03-19 08:01:13 +01:00
|
|
|
&ide_isa_2ch_device },
|
2017-09-30 16:56:38 -04:00
|
|
|
|
2017-11-08 16:23:28 -05:00
|
|
|
{ "[ISA] [IDE] PC/AT XTIDE", "xtide_at",
|
2018-03-19 08:01:13 +01:00
|
|
|
&xtide_at_device },
|
2017-09-30 16:56:38 -04:00
|
|
|
|
2017-11-08 16:23:28 -05:00
|
|
|
{ "[ISA] [IDE] PS/2 AT XTIDE (1.1.5)", "xtide_at_ps2",
|
2018-03-19 08:01:13 +01:00
|
|
|
&xtide_at_ps2_device },
|
2017-09-30 16:56:38 -04:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
{ "[ISA] [IDE] WDXT-150 IDE (XTA) Adapter", "xta_wdxt150",
|
|
|
|
|
&xta_wdxt150_device },
|
|
|
|
|
|
2018-02-14 13:52:19 +01:00
|
|
|
{ "[ISA] [XT IDE] Acculogic XT IDE", "xtide_acculogic",
|
2018-03-19 08:01:13 +01:00
|
|
|
&xtide_acculogic_device },
|
2018-02-14 13:52:19 +01:00
|
|
|
|
|
|
|
|
{ "[ISA] [XT IDE] PC/XT XTIDE", "xtide",
|
2018-03-19 08:01:13 +01:00
|
|
|
&xtide_device },
|
2018-02-14 13:52:19 +01:00
|
|
|
|
2017-10-10 00:14:15 +02:00
|
|
|
{ "[MCA] [ESDI] IBM PS/2 ESDI Fixed Disk Adapter","esdi_mca",
|
2018-03-19 08:01:13 +01:00
|
|
|
&esdi_ps2_device },
|
2017-10-10 00:14:15 +02:00
|
|
|
|
2017-12-16 00:02:13 -05:00
|
|
|
{ "[PCI] [IDE] PCI IDE Adapter", "ide_pci",
|
2018-03-19 08:01:13 +01:00
|
|
|
&ide_pci_device },
|
2017-12-16 00:02:13 -05:00
|
|
|
|
2018-02-14 13:52:19 +01:00
|
|
|
{ "[PCI] [IDE] PCI IDE Adapter (Dual-Channel)", "ide_pci_2ch",
|
2018-03-19 08:01:13 +01:00
|
|
|
&ide_pci_2ch_device },
|
2018-02-14 13:52:19 +01:00
|
|
|
|
2017-12-16 00:02:13 -05:00
|
|
|
{ "[VLB] [IDE] PC/AT IDE Adapter", "vlb_isa",
|
2018-03-19 08:01:13 +01:00
|
|
|
&ide_vlb_device },
|
2017-12-16 00:02:13 -05:00
|
|
|
|
2018-02-14 13:52:19 +01:00
|
|
|
{ "[VLB] [IDE] PC/AT IDE Adapter (Dual-Channel)", "vlb_isa_2ch",
|
2018-03-19 08:01:13 +01:00
|
|
|
&ide_vlb_2ch_device },
|
2018-02-14 13:52:19 +01:00
|
|
|
|
2018-03-19 08:01:13 +01:00
|
|
|
{ "", "",
|
|
|
|
|
NULL }
|
2017-09-30 16:56:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2017-10-02 02:15:35 -04:00
|
|
|
/* Initialize the 'hdc_current' value based on configured HDC name. */
|
|
|
|
|
void
|
|
|
|
|
hdc_init(char *name)
|
|
|
|
|
{
|
|
|
|
|
int c;
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
hdc_log("HDC: initializing..\n");
|
2017-10-02 02:15:35 -04:00
|
|
|
|
2018-03-19 08:01:13 +01:00
|
|
|
for (c = 0; controllers[c].device; c++) {
|
|
|
|
|
if (! strcmp(name, (char *) controllers[c].internal_name)) {
|
2017-10-02 02:15:35 -04:00
|
|
|
hdc_current = c;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-25 23:51:13 +02:00
|
|
|
|
|
|
|
|
/* Zero all the hard disk image arrays. */
|
|
|
|
|
hdd_image_init();
|
2017-10-02 02:15:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Reset the HDC, whichever one that is. */
|
|
|
|
|
void
|
|
|
|
|
hdc_reset(void)
|
|
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
hdc_log("HDC: reset(current=%d, internal=%d)\n",
|
2018-04-25 23:51:13 +02:00
|
|
|
hdc_current, (machines[machine].flags & MACHINE_HDC) ? 1 : 0);
|
2017-10-02 02:15:35 -04:00
|
|
|
|
|
|
|
|
/* If we have a valid controller, add its device. */
|
|
|
|
|
if (hdc_current > 1)
|
|
|
|
|
device_add(controllers[hdc_current].device);
|
2018-03-17 20:32:20 +01:00
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
/* Now, add the tertiary and/or quaternary IDE controllers. */
|
|
|
|
|
if (ide_ter_enabled)
|
|
|
|
|
device_add(&ide_ter_device);
|
|
|
|
|
if (ide_qua_enabled)
|
|
|
|
|
device_add(&ide_qua_device);
|
2017-10-02 02:15:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-09-30 16:56:38 -04:00
|
|
|
char *
|
|
|
|
|
hdc_get_name(int hdc)
|
|
|
|
|
{
|
2018-03-19 08:01:13 +01:00
|
|
|
return((char *) controllers[hdc].name);
|
2017-09-30 16:56:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
hdc_get_internal_name(int hdc)
|
|
|
|
|
{
|
2018-03-19 08:01:13 +01:00
|
|
|
return((char *) controllers[hdc].internal_name);
|
2017-09-30 16:56:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
int
|
|
|
|
|
hdc_get_from_internal_name(char *s)
|
|
|
|
|
{
|
|
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
|
|
while (strlen((char *) controllers[c].internal_name))
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp((char *) controllers[c].internal_name, s))
|
|
|
|
|
return c;
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
const device_t *
|
2017-10-10 00:14:15 +02:00
|
|
|
hdc_get_device(int hdc)
|
|
|
|
|
{
|
|
|
|
|
return(controllers[hdc].device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-04-25 23:51:13 +02:00
|
|
|
int
|
|
|
|
|
hdc_has_config(int hdc)
|
|
|
|
|
{
|
|
|
|
|
const device_t *dev = hdc_get_device(hdc);
|
|
|
|
|
|
|
|
|
|
if (dev == NULL) return(0);
|
|
|
|
|
|
|
|
|
|
if (dev->config == NULL) return(0);
|
|
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-09-30 16:56:38 -04:00
|
|
|
int
|
|
|
|
|
hdc_get_flags(int hdc)
|
|
|
|
|
{
|
|
|
|
|
return(controllers[hdc].device->flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
hdc_available(int hdc)
|
|
|
|
|
{
|
|
|
|
|
return(device_available(controllers[hdc].device));
|
|
|
|
|
}
|