[comp.sys.ibm.pc] Help switch to real-mode on AT class micro

wei@hpctdls.HP.COM (Bill Ives) (04/13/89)

    I have written code to switch an AT class machine ( namely
    an HP ES/12 ) to protected mode and back.  I manage to
    get into protected mode and even am able to set up
    valid descriptors in my global discriptor table -- for
    writing directly to the screen etc.  I have not as yet
    set up a task state segment since I do not intend to switch
    to another task.  For lack of anything better to do when
    I have finished with my tests -- I have paused with wait loops
    then triggered a reset via int 0 -- this works since I was
    nulling out my interrupt descritor table register.  In the
    hopes of avoiding this reset time ( and because I know its possible )
    I have modified my code to switch back to real mode in a more
    graceful manner -- namely via the shut-down vector for a soft-reset.
    The procedure for this is as follows:

       In real mode at start of program
            move target address(seg:off) for return from
               protected mode into address 40h:67h.
            set cmos shut-down byte ( cmos addr 0fh ) to 5 so
               that the reset jumps via the address at 40h:67h
               when returning to real mode.
            disable the keyboard interface controller so
               that it does not interrupt while in protected mode.
               This is the 8041 chip, and is accomplished by
               writting 0adh to port 64h.
            move into protected mode by switching PE bit and
               setting up IDT to null. I do not set up the GDTR
               or LDTR for this simple case since I immediately
               switch back to real mode.
      In protected mode
            print out message saying I made it. ( this works )
            enable address line 20 ( for use in prot mode ) by
               using 8041 again. write 0dfh to port 64h.
            force shut-down reset to return to real mode by
               pulsing the system reset line using the 8041.
               write 0f7h to port 64h
     target for return from protected mode.
            disable interrupts
            retore stack etc.
            disable address line 20 for real mode. write 0ddh to port 64h
            enable keyboard interface. write 0aeh to port 64h
            see if keyboard is okay by issuing self test command
                to the 8041 - write 0aah to 64h then look for 55h in
                              port 60h
                ( the self test report no problem )
           enable interrupts
           restore cmos shut-down byte so that next reset causes POST
              to occur.        
           return to DOS via int 20h

    The current behavior shows the DOS prompt returning to the screen
    then locks up the system. At first I thought it was the keyboard controller
    not being correctly configured - but the selftest checked this as well as
    a keyboard power-on reset command I issued to the 8041.  I also thought
    it might be the interrupt controllers -- namely the 8259s, but when
    I included initialization code for them after the return to real mode,
    the system not only hung - but its entire CMOS was blanked out. I have
    attempted to eliminate the interrupt problem in protected mode by
    nulling out the IDTR as well as disabling interrupts for the entire
    time I was in protected mode.  I do not write to any memory - other
    than screen memory - while in prot mode so I believe the real mode
    interrupt vector table should be uncorrupted -- my return to DOS via
    int 20h and the subsequent display of the DOS prompt lead me to believe
    the table is okay.   As an aside, my code is written in COM file format
    and like I said earlier all my prot mode stuff works fine in a more
    complete version of this code - I took out the test stuff to simplify
    this code.   Any help from anyone with experience doing this switch
    would be greatly appreciated. If it has been covered before -- I'm sorry.
    Postings to this news group or mail is fine -- I do read this group
    nearly everyday.  Sorry for the long note too...
       
        Thanx
        Bill Ives
        HP CTD