another thing also with pmode is that when switching back to real mode any 16 bit segments that are used should have their limits set to full 64k for the segment limit, i.e. 0FFFFh, otherwise the pc will hang or reboot
and also disable any interrupts during pmode switching , etc, hope this helps