Skip to content

Change workaround for the dynamic core #5718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions src/cpu/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3196,36 +3196,6 @@ bool CPU_CPUID(void) {
return true;
}

/* this is used by dynamic core as a workaround for sending the reset signal into the emulator
* because C++ exceptions don't work from within dynamically generated code. */
int reset_decode_signal = 0;
Bits Reset_Decode(void) {
LOG_MSG("CPU: It is now safe to send reset signal");
cpudecoder = cpu.hlt.old_decoder;
throw int(reset_decode_signal);
return 0;
}

void CPU_SetResetSignal(int x) {
LOG_MSG("CPU: Queuing reset signal, to send when dynamic core has completed execution.");
reset_decode_signal = x;
cpu.hlt.old_decoder = cpudecoder;
cpudecoder = &Reset_Decode;
CPU_Cycles = 0;
}

bool CPU_DynamicCoreCannotUseCPPExceptions(void) {
#if C_DYNAMIC_X86
if (cpudecoder == &CPU_Core_Dyn_X86_Run)
return true;
#endif
#if C_DYNREC
if (cpudecoder == &CPU_Core_Dynrec_Run)
return true;
#endif
return false;
}

Bits HLT_Decode(void) {
/* Once an interrupt occurs, it should change cpu core */
if (reg_eip!=cpu.hlt.eip || SegValue(cs) != cpu.hlt.cs) {
Expand Down
58 changes: 26 additions & 32 deletions src/hardware/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
#include "../gamelink/gamelink.h"
#endif // C_GAMELINK

void RebootLanguage(std::string filename, bool confirm=false);

/* memory from file, memory mapping */
#if C_HAVE_MMAP
# define DO_MEMORY_FILE
Expand Down Expand Up @@ -196,7 +198,7 @@ class MEM_callout_vector : public std::vector<MEM_CalloutObject> {

static MEM_callout_vector MEM_callouts[MEM_callouts_max];

extern bool isa_memory_hole_15mb;
extern bool isa_memory_hole_15mb;

bool a20_guest_changeable = true;
bool a20_fake_changeable = false;
Expand Down Expand Up @@ -1420,9 +1422,6 @@ uint16_t CPU_Pop16(void);

static bool cmos_reset_type_9_sarcastic_win31_comments=true;

void CPU_SetResetSignal(int x);
bool CPU_DynamicCoreCannotUseCPPExceptions(void);

void On_Software_286_int15_block_move_return(unsigned char code) {
uint16_t vec_seg,vec_off;

Expand Down Expand Up @@ -1461,10 +1460,8 @@ void On_Software_286_int15_block_move_return(unsigned char code) {
CPU_IRET(false,0);

/* force execution change (FIXME: Is there a better way to do this?) */
if (CPU_DynamicCoreCannotUseCPPExceptions())
CPU_SetResetSignal(4);
else
throw int(4);
throw int(4);
/* does not return */
}

void On_Software_286_reset_vector(unsigned char code) {
Expand Down Expand Up @@ -1504,10 +1501,8 @@ void On_Software_286_reset_vector(unsigned char code) {
reg_eip = vec_off;

/* force execution change (FIXME: Is there a better way to do this?) */
if (CPU_DynamicCoreCannotUseCPPExceptions())
CPU_SetResetSignal(4);
else
throw int(4);
throw int(4);
/* does not return */
}

void CPU_Exception_Level_Reset();
Expand Down Expand Up @@ -1585,10 +1580,7 @@ void On_Software_CPU_Reset() {
LOG_MSG("PC-98 reset and continue: RETF to %04x:%04x",SegValue(cs),reg_ip);

/* force execution change (FIXME: Is there a better way to do this?) */
if (CPU_DynamicCoreCannotUseCPPExceptions())
CPU_SetResetSignal(4);
else
throw int(4);
throw int(4);
/* does not return */
}
}
Expand All @@ -1608,10 +1600,16 @@ void On_Software_CPU_Reset() {
}
}

if (CPU_DynamicCoreCannotUseCPPExceptions())
CPU_SetResetSignal(3);
else
throw int(3);
#if C_DYNAMIC_X86
/* this technique is NOT reliable when running the dynamic core! */
if (cpudecoder == &CPU_Core_Dyn_X86_Run || cpudecoder == &CPU_Core_Dynrec_Run) {
LOG_MSG("Warning: C++ exception method is not compatible with dynamic core when emulating reset");
RebootLanguage("");
}
#endif

throw int(3);
/* does not return */
}

/* Some PC-98 code uses this register to know if the 16MB "memory hole" is open,
Expand Down Expand Up @@ -1805,19 +1803,15 @@ HostPt GetMemBase(void) { return MemBase; }
/*! \brief REDOS.COM utility command on drive Z: to trigger restart of the DOS kernel
*/
class REDOS : public Program {
public:
/*! \brief Program entry point, when the command is run */
void Run(void) override {
if (cmd->FindExist("/?", false) || cmd->FindExist("-?", false)) {
WriteOut("Reboots the kernel of DOSBox-X's emulated DOS.\n\nRE-DOS\n");
return;
}

if (CPU_DynamicCoreCannotUseCPPExceptions())
CPU_SetResetSignal(6);
else
throw int(6);
public:
/*! \brief Program entry point, when the command is run */
void Run(void) override {
if (cmd->FindExist("/?", false) || cmd->FindExist("-?", false)) {
WriteOut("Reboots the kernel of DOSBox-X's emulated DOS.\n\nRE-DOS\n");
return;
}
throw int(6);
}
};

void REDOS_ProgramStart(Program * * make) {
Expand Down