crazii wrote on 2026-12-01, 07:18:
RayeR wrote on 2026-11-30, 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.
Sorry, I hadn't noticed this post before making my earlier replies.
The idea, which I probably didn't explain very well, is to record the protected mode GDT and reference it when handling GPFs in extended memory. I don't know anything about trying to mess with the program's GDT once it's back in V86 mode, but I would be surprised if it works. I haven't seen much documentation of how V86 mode's real-mode addressing emulation interacts with the segment descriptor table, but the answer probably isn't anything convenient enough to be useful.
crazii wrote on 2026-12-01, 07:18:
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.
I did say something similar to this in one of my posts. The performance hit from this approach will definitely be enormous, precluding it from being practical on 90s CPUs. The old Ultima VII in Windows project was my initial inspiration for this idea, and it notably makes the game run much slower because it's handling thousands of interrupts and context switches on every frame to deal with the extended memory accesses, just like this would.
The silver lining, though, is that processors have become so much faster since the mid-90s that they can handle all of this. The aforementioned "Ultima VII in Windows" runs at a more than playable speed (actually even a bit too fast) on my Athlon 64. And actual modern processors are dozens of times faster than that Athlon 64. So the performance cost doesn't make the idea untenable; it just raises the minimum system requirements.
crazii wrote on 2026-12-01, 07:18:
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.
On this topic, the Pentium Pro manual and the modern Intel documentation say very different things about what happens when "lgdt" is run in V86 mode. I'm inclined to believe the newer version, especially since the PPro manual's implications here don't make any sense. The modern reference says that "lgdt" always causes a GPF in V86 mode unless the CPL is 0. (CPL=3 for any V86 task under a normal V86 monitor).
Since it causes a GPF, the monitor can handle it by simply recording what is written to the GDT, and using that information when emulating extended memory accesses.
crazii wrote on 2026-12-01, 07:18: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.
This is why I think the best solution is to not mess with the CPU's actual GDT at all. If you're thinking in terms of messing with the real GDT, I can see why you'd think this approach would break a lot of things.
crazii wrote on 2026-12-01, 07:18:because the unreal mode may also have real mode segments, so about the rm segment & pm selector collisions, I ain't think of any […]
Show full quote
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.
So I think my understanding of unreal mode and yours are different. I don't know who's right.
From what I understand, unreal mode is not a mix of real and protected mode segments. Instead, all addressing works like real mode, except that the larger cached segment length prevents a GPF from happening when accessing beyond 1 MB. This means that there's no issue with RM and PM sector collisions, since there are only RM sectors. It also means that, in your example, 1080h is the correct address, so there's not a problem with accessing it.
If I'm wrong, and you're right, and unreal mode is some weird mix of real/protected addressing, then indeed, none of this "unreal monitor" business is very feasible.
crazii wrote on 2026-12-01, 07:18:
and things will go much more compilated if a program do extra unexpected things in protected mode during the "unreal mode switch process".
This is definitely a real problem. My best idea at present is to give the program more or less what it wants. When it tries to switch to protected mode, actually switch the program into non-V86 protected mode. When it tries to switch back, switch it back into V86 mode. This might be a pain, but we can at least count on protected mode to behave like itself. Not much else needed there, unless the program tries to do something very strange. Hopefully, for its brief time in protected mode, the program can be set up with an LDT equivalent to its requested GDT. I haven't done much reading on LDTs, though.
Also, thanks for writing such a detailed reply 😀