Page 1 of 1
Invalid opcodes in real mode/ without paging
Posted: Sun May 26, 2013 10:25 am
by lopidas
Imagine that I have some code from which I want to jump to absolute address how to check if that code is valid opcode (is not data)? I don't want to have some tables of valid instructions.
Re: Invalid opcodes in real mode/ without paging
Posted: Sun May 26, 2013 10:45 am
by ~
lopidas wrote:Imagine that I have some code from which I want to jump to absolute address how to check if that code is valid opcode (is not data)? I don't want to have some tables of valid instructions.
What do you want to do exactly? Do you want to run BIOS INT services without crashing if there aren't available? I remember to need something like this for a 386, where I tried to use BIOS memory detection and memory map services, but it looks like there was no valid interrupt vector (INT 15h?) because I always crashed.
Maybe you could handle invalid opcode exceptions. And maybe you could restrict jumping to addresses that aren't a "null pointer" (maybe a value of 0 or 0000:0000), and only to known locations, and not to memory buffers that only contain 0 or the same byte value or byte pattern, and nothing else.
However, data mostly contains byte values that are indeed valid instructions, and if you run them in Real Mode, you always end up crashing.
Even with a table, jumping to unknown/arbitrary locations will ALWAYS cause a crash in the end.
Re: Invalid opcodes in real mode/ without paging
Posted: Sun May 26, 2013 10:52 am
by sortie
Why do you care? Are you trying to solve the
Halting Problem?
Re: Invalid opcodes in real mode/ without paging
Posted: Sun May 26, 2013 12:03 pm
by lopidas
Doing checks for real mode plugins. I load code from hard drive than I try to execute it (still in real mode). The point is that I am emulating it so I can't get real errors. (I don't have machine without Windows to don't worry about random write calls).
Re: Invalid opcodes in real mode/ without paging
Posted: Sun May 26, 2013 12:31 pm
by lopidas
Re: Invalid opcodes in real mode/ without paging
Posted: Sun May 26, 2013 5:32 pm
by ~
You must remember that you will still find a lot of valid opcodes in most data buffers. And even if you manage to execute only known opcodes for an emulator, in the end the program will crash when leaving instructions without executing.
And if you don't know them you cannot skip them appropriately. If you skip them byte by byte you will often produce a valid instruction which will not make sense for the program, and it will crash for that.
For an emulator, if you only know but a handful of instructions (and not the exact sizes for the rest, even for all combinations of ModR/M and SIB bytes) the only sane thing to do is to halt the emulator, go back to code and implement the currently unknown instructions, and retry.