crazii wrote on Yesterday, 14:40:I don't think it's quite possible for an “unreal monitor” […]
Show full quote
I don't think it's quite possible for an “unreal monitor”
let'ssay We can hack the mode switch and setup a protected mode client(dpmi env) for it and successfully hack Its interrupt handlers. the key problem is, the unreal mode is still in real mode. the addressing is different from protected mode. there is no way to map real mode segment to protected mode selectors because real mode segment has a increment of 1 for 16bytes aka 1 paragraph. but pm selector's minimal numerical increment is 8. the left 3 bits are RPL and LDT( TI aka table indicator).
I think you can talk to AI for possible solutions but I ain't thinking of any.
it might be possible If 4 selectors in gdt and another 4 in ldt to workaround the TI bit but the 2 RPL bit cannot overcome.
I had to do some more reading about x86 and segments, but now I understand what you’re saying, and why non-V86 protected mode can’t emulate real-mode addressing.
As an aside, I’m not taking your suggestion to ask AI about it. Whenever I’m searching for semi-obscure technical information like this, Google always pops up with an (unwanted) AI answer, and about 75% of the time, that answer is completely wrong. If none of the AI’s training data contains a solution to the problem, and it does contain someone on a forum claiming it isn’t possible, the AI will usually just claim, with unearned total confidence, that the problem can’t be solved. It has no framework for actually creating novel solutions to novel problems. So AI is really not useful at all for things like this.
I haven’t given up, though. Instead, I’ve started thinking about it from another angle: is there any real need to switch the task out of V86 mode at all?
In any mode (protected, V86, even real mode), the processor raises a general protection fault on memory accesses whose effective address is outside of the segment limit. In protected mode, the segment limit is set by the descriptor table. In real and V86 mode, the segment limit is forced to 64 KB by the CPU. “Unreal mode” works around this in real mode by tricking the CPU into thinking the segment limit is the entire size of available memory, instead of 64 KB.
The segment limit trick doesn’t work in V86 mode, so accesses above 1 MB will always cause a general protection fault. But V86 monitors work in the first place by handling general protection faults! The “unreal monitor” knows where the memory access was supposed to go, and can access whatever memory it wants, so it can just run the instruction itself, just like V86 monitors do with I/O instructions and such.
Even better, since the application’s upper memory accesses are all routed through the monitor this way, the unreal monitor can do software-based virtual memory management. If the application tries to use an upper memory block that TSRs have been loaded into, the monitor can allocate any actually free block and transparently map the application’s accesses to that.
There is, of course, a significant performance cost to running an interrupt handler every time the application tries to access upper memory. But I doubt it matters much when factoring in the vastly greater speed of 21st-century CPUs compared to the humble 386/486 that “unreal mode” games were targeting.
This approach is really a lot simpler than the previous one, so I’m feeling better about its chances of working than I did with the first version. It does still have the same problem with SMSW being unprivileged, though, and will need the same solution.