Re:Reverse engineering the Intel 386 processor's register cell
by bonzini on Friday November 10, 2023 @03:08AM
(#38216352)
Right, the 386 has 10 internal segment descriptor caches but only 8 segment selector registers. The 286 had 8 and 6 respectively.
But wait, HIMEM.SYS used LOADALL to avoid going into protected mode and back?!? When you thought you knew everything (which I absolutely don't, but I knew it used big real mode on the 386 and I totally didn't expect LOADALL).
> More useful is the ability to load any arbitrary base address for the segment registers without entering protected mode. Some versions of Microsoft's HIMEM.SYS did this to copy data between real and extended memory.
It is also explained at https://www.os2museum.com/wp/himem-sys-unreal-mode-and-loada...
The 286 already had 8 "segment registers" internally: ES, CS, SS, DS, GDT, LDT, IDT & TSS. Only the first four are directly accessible by the program, but to the microcode they should all be more or less identical.
Besides the layout of the saved CPU state in memory, another clue to this is that for exceptions involving both "normal" and "system" segment registers, an error code gets stored in one of the internal registers, indicating which segment caused it. The only way to read it out in software is by executing the undocumented STOREALL instruction (F1 0F 04) immediately after the reset from a triple-fault shutdown.
The codes that appear in this register are:
CS and SS should be 71h / 72h, however exceptions involving these segments seem to take a different microcode path that overwrites that register with the access rights for CS.I have written about this here: https://rep-lodsb.mataroa.blog/blog/the-286s-internal-regist...
And this article shows the bus cycles done by LOADALL on the 386, note that it also loads 10 internal registers:
http://www.rcollins.org/articles/loadall/tspec_a3_doc.html