RayeR wrote on Yesterday, 23:13:
AFAIK as I it understood (maybe wrong), apps that use unreal mode do the RM-PM-RM switch only once at startup and rely on CPU descriptor cache will holds the right values set in PM for the rest of running. If V86 mon activates it reloads GDT with it's own setup then it would need to set it back for the app.
Theoretically yes, provided that any BIOS/DOS ints will not reset the segment registers to real mode ones. otherwise it needs more. so the best might be use FS/GS which is not frequently used.
And because on switching from pm to v86, the CPU will RELOAD ALL segment registers (either via TSS call gate or IRETD) so those cache are gone for good. recording app's previously unreal pm selector (base and size) and emulate the access may work; but that's way too slow, there might be thousands of fault per one game loop, e.g. think about a game write VBE LFB at high address using unreal mode, there might be 800x600 writes, let alone other game data.
so v86 mode is not a good option for emulate that.
making the unreal selector working directly in pm is more doable, but needs to patch the rm segments. and there could be not fault to intercept if there's collision between rm segment and pm selectors.
the very first thing to think about, is how to emulate "lgdt", we can assume an unreal program do not use page tables, but to load the pm selector cache, you still need to emulate it.
obviously the monitor cannot switch gdt directly to the program's because every code&data the monitor uses rely on its own gdt.
the proper way I can think about it to (1) move the monitor's gdt descriptors down (or preserve) and copy programs' gdt to monitor's, or (2) leave the first descriptors empty to trigger exceptions and set a working one for it. or (3) you can just do nothing and let it load monitor's ring0 descriptor which will trigger a fault in ring3 and set a working one for it, not the exactly value it expects but it probably will work.
to preserve some empty descriptors breaks the compatible EMM386 GDT layout for your HIMEMEX.SYS/RAMDSK64.COM already.
to dynamically move monitor's own descriptors, that is not possible for vdpmi for now without architectural changes. the GDT descriptors are all hard coded and selectors are used as an literal value (I believe all existing v86/dpmi code uses static layout).
so the third option could be the easiest solution, for now - but I don't know if there are more problems being overlooked. at least it needs state management, a flag should be set when "lgdt" is triggered and emulate the descriptor loads later. and the flag should be cleared after the app exits - which require another app state management. you cannot just blindly emulate every privilege instructions, because there are some real faults.
because the unreal mode may also have real mode segments, so about the rm segment & pm selector collisions, I ain't think of any solutions yet. and also, if in pm, how to bridge BIOS/DOS int calls is another problem; in DPMI there is clearly defined API, an DPMI program does that explicitly - it's total aware of that. but in a pm mode emulating unreal, the program does not know at all it's being "emulated", how to automatically translate the pm data buffers is another problem.
or maybe using v86 mode is much more easy on this problem, maybe trap every unreal access in v86 mode is not that slow; but that all needs real code to test out. in v86 mode, loading a segment is valid so an "virtual pm" flag is need to record whether it's loading a pm selector now or a rm segment, and record the assignment from its gdt previous via "lgdt" in a table for later trap access emulations.
another problem in v86 mode: accessing an emulated unreal selector does not always triggers faults, e.g.
08h:20000h accessing memory above 64K offset and will trigger a fault. but since the offset could be legal: 08h:1000h won't trigger a fault, instead, CPU will auto perform real mode addressing in v86 mode, which will read the wrong data, at linear address 1080h. not 1000h.
unlike v86 or dpmi with a clear protocol, it's just all hacks, and every step taken might have pitfalls.
currently vdpmi has too much problem itself, so its not suitable to try it, at least for now.
Toshiba Satellite Pro 4300 - YMF744, Savage IX
Toshiba Satellite 2805-S501 - YMF754, GeForce 2Go
IBM Thinkpad A21p - CS4624, Mobility Radeon 128
main: Intel NUC11PHKi7C Phantom Canyon: i7-1165G7 RTX2060 64G 2T760PSDD