Skip to content

Commit

Permalink
fixed issue #95 port_e9_hack
Browse files Browse the repository at this point in the history
refactoring of port_e9_hack configuration options
do not allow port e9 access for all rings if port_e9_hack is not enabled
  • Loading branch information
Stanislav Shwartsman authored and stlintel committed Oct 17, 2023
1 parent 2b873eb commit 727b325
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 41 deletions.
2 changes: 1 addition & 1 deletion bochs/.bochsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ speaker: enabled=1, mode=sound, volume=15
# port_e9_hack: enabled=1
# port_e9_hack: enabled=1, all_rings=1
#=======================================================================
#port_e9_hack: enabled=1
#port_e9_hack: enabled=1, all_rings=1

#=======================================================================
# IODEBUG:
Expand Down
3 changes: 2 additions & 1 deletion bochs/PARAM_TREE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ sound

misc
port_e9_hack
port_e9_hack_all_rings
enabled
all_rings
iodebug_all_rings
gdbstub
port
Expand Down
50 changes: 14 additions & 36 deletions bochs/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ void bx_init_usb_options(const char *usb_name, const char *pname, int maxports,

// xhci host controller type and number of ports
static const char *xhci_model_names[] = { "uPD720202", "uPD720201", NULL };
bx_param_enum_c *model = new bx_param_enum_c(menu,
new bx_param_enum_c(menu,
"model", "HC model",
"Select Host Controller to emulate",
xhci_model_names,
0, 0
);
bx_param_num_c *n_ports = new bx_param_num_c(menu,
new bx_param_num_c(menu,
"n_ports", "Number of ports",
"Set the number of ports for this controller",
-1, 10,
Expand Down Expand Up @@ -1682,15 +1682,16 @@ void bx_init_options()
misc->set_options(misc->SHOW_PARENT);

// port e9 hack
new bx_param_bool_c(misc,
"port_e9_hack",
bx_list_c *port_e9_hack = new bx_list_c(misc, "port_e9_hack", "port 0xE9 hack");
new bx_param_bool_c(port_e9_hack,
"enabled",
"Enable port 0xE9 hack",
"Debug messages written to i/o port 0xE9 will be displayed on console",
0);

// port e9 hack all rings
new bx_param_bool_c(misc,
"port_e9_hack_all_rings",
new bx_param_bool_c(port_e9_hack,
"all_rings",
"Enable port 0xE9 hack for all rings",
"Debug messages written to i/o port 0xE9 from ring3 will be displayed on console",
0);
Expand Down Expand Up @@ -2266,30 +2267,6 @@ static int parse_param_bool(const char *input, int len, const char *param)
return -1;
}

static int parse_port_e9_hack(const char *context, const char **params, int num_params)
{
if (num_params > 2) {
PARSE_ERR(("%s: port_e9_hack directive: wrong # args.", context));
}
if (strncmp(params[0], "enabled=", 8)) {
PARSE_ERR(("%s: port_e9_hack directive malformed.", context));
}
if (parse_param_bool(params[0], 8, BXPN_PORT_E9_HACK) < 0) {
PARSE_ERR(("%s: port_e9_hack directive malformed.", context));
}
if (num_params == 2) {
if (!strncmp(params[1], "all_rings=", 10)) {
if (parse_param_bool(params[1], 10, BXPN_PORT_E9_HACK_ALL_RINGS) < 0) {
PARSE_ERR(("%s: all_rings option malformed.", context));
}
} else {
PARSE_ERR(("%s: port_e9_hack: invalid parameter %s", context, params[1]));
}
}

return 0;
}

int bx_parse_param_from_list(const char *context, const char *input, bx_list_c *list)
{
char *propval, *property, *value;
Expand Down Expand Up @@ -3262,8 +3239,10 @@ static int parse_line_formatted(const char *context, int num_params, char *param
PARSE_ERR(("%s: print_timestamps directive malformed.", context));
}
} else if (!strcmp(params[0], "port_e9_hack")) {
if (parse_port_e9_hack(context, (const char **)(params + 1), num_params - 1) < 0) {
return -1;
for (i=1; i<num_params; i++) {
if (bx_parse_param_from_list(context, params[i], (bx_list_c*) SIM->get_param(BXPN_PORT_E9_HACK_ROOT)) < 0) {
PARSE_ERR(("%s: port_e9_hack directive malformed.", context));
}
}
} else if (!strcmp(params[0], "iodebug")) {
#if BX_SUPPORT_IODEBUG
Expand Down Expand Up @@ -3634,11 +3613,10 @@ int bx_write_configuration(const char *rc, int overwrite)

fprintf(fp, "print_timestamps: enabled=%d\n", bx_dbg.print_timestamps);
bx_write_debugger_options(fp);
fprintf(fp, "port_e9_hack: enabled=%d\n", SIM->get_param_bool(BXPN_PORT_E9_HACK)->get());
fprintf(fp, "port_e9_hack_all_rings: enabled=%d\n", SIM->get_param_bool(BXPN_PORT_E9_HACK_ALL_RINGS)->get());
#if BX_SUPPORT_IODEBUG
bx_write_param_list(fp, (bx_list_c*) SIM->get_param(BXPN_PORT_E9_HACK_ROOT), NULL, 0);
#if BX_SUPPORT_IODEBUG
fprintf(fp, "iodebug_all_rings: enabled=%d\n", SIM->get_param_bool(BXPN_IODEBUG_ALL_RINGS)->get());
#endif
#endif
fprintf(fp, "private_colormap: enabled=%d\n", SIM->get_param_bool(BXPN_PRIVATE_COLORMAP)->get());
#if BX_WITH_AMIGAOS
fprintf(fp, "fullscreen: enabled=%d\n", SIM->get_param_bool(BXPN_FULLSCREEN)->get());
Expand Down
2 changes: 1 addition & 1 deletion bochs/cpu/io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ bool BX_CPP_AttrRegparmN(3) BX_CPU_C::allow_io(bxInstruction_c *i, Bit16u port,
* Otherwise, must check the IO permission map on >286.
* On the 286, there is no IO permissions map */

static bool port_e9_hack_all_rings = SIM->get_param_bool(BXPN_PORT_E9_HACK_ALL_RINGS)->get();
static bool port_e9_hack_all_rings = SIM->get_param_bool(BXPN_PORT_E9_HACK)->get() && SIM->get_param_bool(BXPN_PORT_E9_HACK_ALL_RINGS)->get();
if (0xe9 == port && port_e9_hack_all_rings)
return(1); // port e9 hack can be used by unprivileged code

Expand Down
5 changes: 3 additions & 2 deletions bochs/param_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@
#define BXPN_SOUND_SPEAKER "sound.speaker"
#define BXPN_SOUND_SB16 "sound.sb16"
#define BXPN_SOUND_ES1370 "sound.es1370"
#define BXPN_PORT_E9_HACK "misc.port_e9_hack"
#define BXPN_PORT_E9_HACK_ALL_RINGS "misc.port_e9_hack_all_rings"
#define BXPN_PORT_E9_HACK_ROOT "misc.port_e9_hack"
#define BXPN_PORT_E9_HACK "misc.port_e9_hack.enabled"
#define BXPN_PORT_E9_HACK_ALL_RINGS "misc.port_e9_hack.all_rings"
#define BXPN_IODEBUG_ALL_RINGS "misc.iodebug_all_rings"
#define BXPN_GDBSTUB "misc.gdbstub"
#define BXPN_LOG_FILENAME "log.filename"
Expand Down

0 comments on commit 727b325

Please sign in to comment.