Invalid opcodes in real mode/ without paging

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
lopidas
Member
Member
Posts: 65
Joined: Sun May 26, 2013 10:12 am

Invalid opcodes in real mode/ without paging

Post 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.
User avatar
~
Member
Member
Posts: 1226
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Invalid opcodes in real mode/ without paging

Post 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.
YouTube:
http://youtube.com/@AltComp126

My x86 emulator/kernel project and software tools/documentation:
http://master.dl.sourceforge.net/projec ... 7z?viasf=1
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Invalid opcodes in real mode/ without paging

Post by sortie »

Why do you care? Are you trying to solve the Halting Problem?
lopidas
Member
Member
Posts: 65
Joined: Sun May 26, 2013 10:12 am

Re: Invalid opcodes in real mode/ without paging

Post 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).
lopidas
Member
Member
Posts: 65
Joined: Sun May 26, 2013 10:12 am

Re: Invalid opcodes in real mode/ without paging

Post by lopidas »

User avatar
~
Member
Member
Posts: 1226
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Invalid opcodes in real mode/ without paging

Post 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.
YouTube:
http://youtube.com/@AltComp126

My x86 emulator/kernel project and software tools/documentation:
http://master.dl.sourceforge.net/projec ... 7z?viasf=1
Post Reply