home *** CD-ROM | disk | FTP | other *** search
/ 98 Driver Collection MD-0164 / DRIVER_KING_98.iso / CPU / cyrix / AORB.C next >
Encoding:
C/C++ Source or Header  |  1997-01-12  |  5.8 KB  |  185 lines

  1. #define TRUE  1
  2. #define FALSE 0 
  3.  
  4. #define _SVDC_ db 36h, 0fh, 78h, 1fh
  5.  
  6. int old_off;
  7. int old_seg;
  8. extern ill_op();
  9.  
  10. /*****************************************************************************
  11. *   Function:  isb()
  12. *                                                                        
  13. *   Purpose:   Determine if 486SLC/DLC is rev. A or B
  14. *
  15. *   Technique: A step devices do not support SMM.  By executing an SMM
  16. *              instruction without an invalid opcode exception the device
  17. *              is a B step device or later.  To execute the SMM instruction
  18. *              this routine must be operating at CPL 0 or REAL mode.  V86
  19. *              mode, CPL 1,2, and 3 are NOT permissable.  A check for V86
  20. *              should be done before calling this routine.
  21. *                                                                            
  22. *   Parameters:   Nothing                                                    
  23. *                                                                            
  24. *   Returns:      0 if A step
  25. *                 1 if B step device
  26. *                                                                            
  27. *   Calls:        DOS via int 21 function 35,25
  28. *                    - To load new invalid opcode handler
  29. *****************************************************************************/            
  30. isb ()
  31.    {
  32.    int i, b_step;
  33.    char mem[10];
  34.    char save_ccr1, save_cf, save_ce, save_cd;
  35.  
  36.    for (i=0; i<10; mem[i++]=0);
  37.  
  38.    asm   {
  39.  
  40.          .386
  41.          extrn _ill_op:near
  42.  
  43.             ;***** save flag and turn off interrupts *****
  44.             pushf
  45.             cli
  46.  
  47.             ;*********************************************      
  48.             ;****** get present invalid opcode handler
  49.             ;*********************************************
  50.  
  51.             push  es
  52.             mov   ax, 3506h      
  53.             int   21h
  54.             mov   old_seg, es    
  55.             mov   old_off, bx    
  56.             pop   es
  57.  
  58.             ;*********************************************      
  59.             ;****** install new invalid opcode handler
  60.             ;*********************************************      
  61.             push  ds
  62.             mov   ax, 2506h          
  63.             mov   dx, OFFSET _ill_op
  64.             mov   bx, cs
  65.             mov   ds, bx
  66.             int   21h
  67.             pop   ds
  68.  
  69.             ;*************************************************************      
  70.             ;****** Set SM4 and SMAC and SMI bit to allow SMM instructions
  71.             ;*************************************************************      
  72.             mov   al, 0c1h
  73.             out   22h,  al
  74.             in    al, 23h
  75.             mov   byte ptr [save_ccr1], al
  76.             or    al, 86h
  77.             mov   ah, al
  78.             mov   al, 0c1h
  79.             out   22h,  al
  80.             mov   al, ah
  81.             out   23h, al
  82.  
  83.             ;************************************************************
  84.             ;***** Setup non-zero SMM region
  85.             ;************************************************************
  86.             mov   al, 0cfh
  87.             out   22h, al
  88.             in    al, 23h
  89.             mov   byte ptr [save_cf], al
  90.  
  91.             mov   al, 0cfh
  92.             out   22h, al
  93.             mov   al, 1
  94.             out   23h, al
  95.             
  96.             ;********************************************
  97.             ;**** Set SMM region to the top of memory to
  98.             ;**** avoid overlapping with this program.
  99.             ;********************************************
  100.             mov   al, 0cdh
  101.             out   22h, al
  102.             in    al, 23h
  103.             mov   byte ptr [save_cd], al
  104.  
  105.             mov   al, 0ceh
  106.             out   22h, al
  107.             in    al, 23h
  108.             mov   byte ptr [save_ce], al
  109.  
  110.             mov   al, 0cdh
  111.             out   22h, al
  112.             mov   al, 0ffh
  113.             out   23h, al
  114.  
  115.             mov   al, 0ceh
  116.             out   22h, al
  117.             mov   al, 0h
  118.             out   23h, al
  119.  
  120.             mov   al, 0cfh
  121.             out   22h, al
  122.             in    al, 23h
  123.             and   al, 0fh
  124.             out   23h, al
  125.             ;********************* flush instruction cache **************
  126.             jmp   $+2
  127.  
  128.             ;*********************************************
  129.             ;****** Execute SMM instruction svdc
  130.             ;*********************************************      
  131.             ;svdc word ptr mem, ds
  132.             ;     word ptr mem == ss:[bx]
  133.             lea   bx, mem
  134.             _SVDC_
  135.  
  136.             ;**********************************************
  137.             ;***** restore configuration registers
  138.             ;**********************************************
  139.             mov   al, 0cdh
  140.             out   22h, al
  141.             mov   al, byte ptr save_cd
  142.             out   23h, al
  143.  
  144.             mov   al, 0ceh
  145.             out   22h, al
  146.             mov   al, byte ptr save_ce
  147.             out   23h, al
  148.  
  149.             mov   al, 0cfh
  150.             out   22h, al
  151.             mov   al, byte ptr save_cf
  152.             out   23h, al
  153.  
  154.             mov   al, 0c1h
  155.             out   22h, al
  156.             mov   al, byte ptr save_ccr1
  157.             out   23h, al
  158.  
  159.             ;*********************************************      
  160.             ;****** restore old invalid opcode handler
  161.             ;*********************************************      
  162.             push  ds
  163.             mov   ax, 2506h          
  164.             mov   dx, [old_off]
  165.             mov   bx, [old_seg]
  166.             mov   ds, bx
  167.             int   21h
  168.             pop   ds
  169.  
  170.             ;****** restore flags ******
  171.             popf          
  172.  
  173.        }  // isb asm region
  174.  
  175.    for (i=0,b_step=FALSE; i<10; ++i)
  176.       if (mem[i] != 0)
  177.          {
  178.          b_step = TRUE;
  179.          break;
  180.          }
  181.  
  182.    return (b_step);
  183.    }  // isb ()  
  184.  
  185.