Changed type of the PCI slot option to bx_param_enum_c and build choices list

from plugin devives with PLUGFLAG_PCI set.
This commit is contained in:
Volker Ruppert 2021-02-27 10:23:05 +00:00
parent 4dd5816108
commit 2aadd3e470
4 changed files with 58 additions and 29 deletions

View File

@ -49,6 +49,7 @@
const char **display_library_list;
const char **vga_extension_names;
const char **vga_extension_plugins;
const char **pcislot_dev_list;
int bochsrc_include_level = 0;
#define LOG_THIS genlog->
@ -325,6 +326,31 @@ void bx_init_vgaext_list()
vga_extension_names[count + 2] = NULL;
}
void bx_init_pcidev_list()
{
Bit8u i, j, count, flags;
const Bit16u mask = PLUGTYPE_VGA | PLUGTYPE_OPTIONAL;
const char *plugname;
count = PLUG_get_plugins_count(mask);
pcislot_dev_list = (const char**) malloc((count + 2) * sizeof(char*));
pcislot_dev_list[0] = "none";
j = 1;
for (i = 0; i < count; i++) {
plugname = PLUG_get_plugin_name(mask, i);
flags = PLUG_get_plugin_flags(mask, i);
if ((flags & PLUGFLAG_PCI) != 0) {
if (!strcmp(plugname, "vga")) {
plugname = "pcivga";
} else if (!strcmp(plugname, "svga_cirrus")) {
plugname = "cirrus";
}
pcislot_dev_list[j++] = plugname;
}
}
pcislot_dev_list[j] = NULL;
}
void bx_init_options()
{
int i;
@ -928,17 +954,19 @@ void bx_init_options()
BX_PCI_CHIPSET_I430FX);
deplist->add(pci_chipset);
// pci slots
bx_init_pcidev_list();
bx_list_c *slot = new bx_list_c(pci, "slot", "PCI Slots");
deplist->add(slot);
for (i=0; i<BX_N_PCI_SLOTS; i++) {
sprintf(name, "%d", i+1);
sprintf (descr, "Name of the device connected to PCI slot #%d", i+1);
sprintf (label, "PCI slot #%d device", i+1);
bx_param_string_c *devname = new bx_param_string_c(slot,
bx_param_enum_c *devname = new bx_param_enum_c(slot,
name,
label,
descr,
"", BX_PATHNAME_LEN);
pcislot_dev_list,
0, 0);
deplist->add(devname);
}
bx_param_string_c *advopts = new bx_param_string_c(pci, "advopts", "Advanced PCI Options",
@ -2893,7 +2921,11 @@ static int parse_line_formatted(const char *context, int num_params, char *param
slot = atol(&params[i][4]);
if ((slot > 0) && (slot < 6)) {
sprintf(tmpdev, "pci.slot.%d", slot);
SIM->get_param_string(tmpdev)->set(&params[i][6]);
if (strlen(&params[i][6]) > 0) {
SIM->get_param_enum(tmpdev)->set_by_name(&params[i][6]);
} else {
SIM->get_param_enum(tmpdev)->set_by_name("none");
}
} else {
BX_ERROR(("%s: unknown pci slot number ignored.", context));
}
@ -3377,14 +3409,11 @@ int bx_write_configuration(const char *rc, int overwrite)
fprintf(fp, ", chipset=%s", SIM->get_param_enum(BXPN_PCI_CHIPSET)->get_selected());
for (i=0; i<BX_N_PCI_SLOTS; i++) {
sprintf(tmpdev, "pci.slot.%d", i+1);
sparam = SIM->get_param_string(tmpdev);
if (!sparam->isempty()) {
fprintf(fp, ", slot%d=%s", i+1, sparam->getptr());
}
fprintf(fp, ", slot%d=%s", i+1, SIM->get_param_enum(tmpdev)->get_selected());
}
sparam = SIM->get_param_string(BXPN_PCI_ADV_OPTS);
if (strlen(sparam->getptr()) > 0) {
fprintf(fp, ", advopts=%s", sparam->getptr());
fprintf(fp, ", advopts=\"%s\"", sparam->getptr());
}
}
fprintf(fp, "\n");

View File

@ -757,7 +757,7 @@ bool bx_real_sim_c::is_pci_device(const char *name)
#if BX_SUPPORT_PCI
unsigned i, max_pci_slots = BX_N_PCI_SLOTS;
char devname[80];
char *device;
const char *device;
if (SIM->get_param_bool(BXPN_PCI_ENABLED)->get()) {
if (SIM->get_param_enum(BXPN_PCI_CHIPSET)->get() == BX_PCI_CHIPSET_I440BX) {
@ -765,8 +765,8 @@ bool bx_real_sim_c::is_pci_device(const char *name)
}
for (i = 0; i < max_pci_slots; i++) {
sprintf(devname, "pci.slot.%d", i+1);
device = SIM->get_param_string(devname)->getptr();
if ((strlen(device) > 0) && (!strcmp(name, device))) {
device = SIM->get_param_enum(devname)->get_selected();
if (!strcmp(name, device)) {
return 1;
}
}
@ -780,8 +780,8 @@ bool bx_real_sim_c::is_agp_device(const char *name)
#if BX_SUPPORT_PCI
if (get_param_bool(BXPN_PCI_ENABLED)->get() &&
(SIM->get_param_enum(BXPN_PCI_CHIPSET)->get() == BX_PCI_CHIPSET_I440BX)) {
const char *device = SIM->get_param_string("pci.slot.5")->getptr();
if ((strlen(device) > 0) && (!strcmp(name, device))) {
const char *device = SIM->get_param_enum("pci.slot.5")->get_selected();
if (!strcmp(name, device)) {
return 1;
}
}

View File

@ -359,20 +359,20 @@ void bx_devices_c::init(BX_MEM_C *newmem)
#if BX_SUPPORT_PCI
// verify PCI slot configuration
char devname[80];
char *device;
const char *device;
if (pci.enabled) {
if (chipset == BX_PCI_CHIPSET_I440BX) {
device = SIM->get_param_string("pci.slot.5")->getptr();
if ((strlen(device) > 0) && !pci.slot_used[4]) {
device = SIM->get_param_enum("pci.slot.5")->get_selected();
if (strcmp(device, "none") && !pci.slot_used[4]) {
BX_PANIC(("Unknown plugin '%s' at AGP slot", device));
}
max_pci_slots = 4;
}
for (i = 0; i < max_pci_slots; i++) {
sprintf(devname, "pci.slot.%d", i+1);
device = SIM->get_param_string(devname)->getptr();
if ((strlen(device) > 0) && !pci.slot_used[i]) {
device = SIM->get_param_enum(devname)->get_selected();
if (strcmp(device, "none") && !pci.slot_used[i]) {
BX_PANIC(("Unknown plugin '%s' at PCI slot #%d", device, i+1));
}
}
@ -1355,7 +1355,7 @@ bool bx_devices_c::register_pci_handlers(bx_pci_device_c *dev,
int first_free_slot = -1;
Bit16u bus_devfunc = *devfunc;
char devname[80];
char *device;
const char *device;
if (strcmp(name, "pci") && strcmp(name, "pci2isa") && strcmp(name, "pci_ide")
&& ((*devfunc & 0xf8) == 0x00)) {
@ -1365,8 +1365,8 @@ bool bx_devices_c::register_pci_handlers(bx_pci_device_c *dev,
if (bus == 0) {
for (i = 0; i < max_pci_slots; i++) {
sprintf(devname, "pci.slot.%d", i+1);
device = SIM->get_param_string(devname)->getptr();
if (strlen(device) > 0) {
device = SIM->get_param_enum(devname)->get_selected();
if (strcmp(device, "none")) {
if (!strcmp(name, device) && !pci.slot_used[i]) {
*devfunc = ((i + pci.map_slot_to_dev) << 3) | (*devfunc & 0x07);
pci.slot_used[i] = 1;
@ -1382,7 +1382,7 @@ bool bx_devices_c::register_pci_handlers(bx_pci_device_c *dev,
if (first_free_slot != -1) {
i = (unsigned)first_free_slot;
sprintf(devname, "pci.slot.%d", i+1);
SIM->get_param_string(devname)->set(name);
SIM->get_param_enum(devname)->set_by_name(name);
*devfunc = ((i + pci.map_slot_to_dev) << 3) | (*devfunc & 0x07);
pci.slot_used[i] = 1;
BX_INFO(("PCI slot #%d used by plugin '%s'", i+1, name));

View File

@ -1003,6 +1003,13 @@ plugin_t bx_builtin_plugins[] = {
#endif
#if BX_WITH_X11
BUILTIN_GUI_PLUGIN_ENTRY(x),
#endif
BUILTIN_VGA_PLUGIN_ENTRY(vga, 0, PLUGFLAG_PCI),
#if BX_SUPPORT_CLGD54XX
BUILTIN_VGA_PLUGIN_ENTRY(svga_cirrus, 0, PLUGFLAG_PCI),
#endif
#if BX_SUPPORT_VOODOO
BUILTIN_VGA_PLUGIN_ENTRY(voodoo, PLUGTYPE_OPTIONAL, PLUGFLAG_PCI),
#endif
BUILTIN_OPT_PLUGIN_ENTRY(unmapped),
BUILTIN_OPT_PLUGIN_ENTRY(biosdev),
@ -1048,13 +1055,6 @@ plugin_t bx_builtin_plugins[] = {
#endif
#if BX_SUPPORT_USB_XHCI
BUILTIN_OPTPCI_PLUGIN_ENTRY(usb_xhci),
#endif
BUILTIN_VGA_PLUGIN_ENTRY(vga, 0, PLUGFLAG_PCI),
#if BX_SUPPORT_CLGD54XX
BUILTIN_VGA_PLUGIN_ENTRY(svga_cirrus, 0, PLUGFLAG_PCI),
#endif
#if BX_SUPPORT_VOODOO
BUILTIN_VGA_PLUGIN_ENTRY(voodoo, PLUGTYPE_OPTIONAL, PLUGFLAG_PCI),
#endif
#if BX_SUPPORT_SOUNDLOW
BUILTIN_SND_PLUGIN_ENTRY(dummy),