Print this page
9685 KPTI %cr3 handling needs fixes

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/i86pc/ml/locore.s
          +++ new/usr/src/uts/i86pc/ml/locore.s
↓ open down ↓ 151 lines elided ↑ open up ↑
 152  152           * set of arguments than _start is given (see lint prototypes above).
 153  153           *
 154  154           * XXX  Make this less vile, please.
 155  155           */
 156  156          ENTRY_NP(_locore_start)
 157  157  
 158  158          /*
 159  159           * %rdi = boot services (should die someday)
 160  160           * %rdx = bootops
 161  161           * end
 162      -         */     
      162 +         */
 163  163  
 164  164          leaq    edata(%rip), %rbp       /* reference edata for ksyms */
 165  165          movq    $0, (%rbp)              /* limit stack back trace */
 166  166  
 167  167          /*
 168  168           * Initialize our stack pointer to the thread 0 stack (t0stack)
 169  169           * and leave room for a "struct regs" for lwp0.  Note that the
 170  170           * stack doesn't actually align to a 16-byte boundary until just
 171  171           * before we call mlsetup because we want to use %rsp to point at
 172  172           * our regs structure.
 173  173           */
 174  174          leaq    t0stack(%rip), %rsp
 175  175          addq    $_CONST(DEFAULTSTKSZ - REGSIZE), %rsp
 176  176  #if (REGSIZE & 15) == 0
 177  177          subq    $8, %rsp
 178  178  #endif
 179  179          /*
 180  180           * Save call back for special x86 boot services vector
 181      -         */     
      181 +         */
 182  182          movq    %rdi, sysp(%rip)
 183  183  
 184  184          movq    %rdx, bootops(%rip)             /* save bootops */
 185  185          movq    $bootops, bootopsp(%rip)
 186  186  
 187  187          /*
 188  188           * Save arguments and flags, if only for debugging ..
 189  189           */
 190  190          movq    %rdi, REGOFF_RDI(%rsp)
 191  191          movq    %rsi, REGOFF_RSI(%rsp)
↓ open down ↓ 9 lines elided ↑ open up ↑
 201  201          /*
 202  202           * Enable write protect and alignment check faults.
 203  203           */
 204  204          movq    %cr0, %rax
 205  205          orq     $_CONST(CR0_WP|CR0_AM), %rax
 206  206          andq    $_BITNOT(CR0_WT|CR0_CE), %rax
 207  207          movq    %rax, %cr0
 208  208  #endif  /* __xpv */
 209  209  
 210  210          /*
 211      -         * (We just assert this works by virtue of being here) 
      211 +         * (We just assert this works by virtue of being here)
 212  212           */
 213  213          bts     $X86FSET_CPUID, x86_featureset(%rip)
 214  214  
 215  215          /*
 216  216           * mlsetup() gets called with a struct regs as argument, while
 217  217           * main takes no args and should never return.
 218  218           */
 219  219          xorl    %ebp, %ebp
 220  220          movq    %rsp, %rdi
 221  221          pushq   %rbp
↓ open down ↓ 39 lines elided ↑ open up ↑
 261  261           * kobj_init() vectors us back to here with (note) a slightly different
 262  262           * set of arguments than _start is given (see lint prototypes above).
 263  263           *
 264  264           * XXX  Make this less vile, please.
 265  265           */
 266  266          ENTRY_NP(_locore_start)
 267  267  
 268  268          /*
 269  269           *      %ecx = boot services (should die someday)
 270  270           *      %ebx = bootops
 271      -         */     
      271 +         */
 272  272          mov     $edata, %ebp            / edata needs to be defined for ksyms
 273  273          movl    $0, (%ebp)              / limit stack back trace
 274  274  
 275  275          /*
 276  276           * Initialize our stack pointer to the thread 0 stack (t0stack)
 277  277           * and leave room for a phony "struct regs".
 278  278           */
 279  279          movl    $t0stack + DEFAULTSTKSZ - REGSIZE, %esp
 280  280  
 281  281          /*
 282  282           * Save call back for special x86 boot services vector
 283  283           */
 284  284          mov     %ecx, sysp              / save call back for boot services
 285  285  
 286      -        mov     %ebx, bootops           / save bootops
      286 +        mov     %ebx, bootops           / save bootops
 287  287          movl    $bootops, bootopsp
 288  288  
 289  289  
 290  290          /*
 291  291           * Save all registers and flags
 292  292           */
 293      -        pushal  
      293 +        pushal
 294  294          pushfl
 295  295  
 296  296  #if !defined(__xpv)
 297  297          /*
 298  298           * Override bios settings and enable write protect and
 299  299           * alignment check faults.
 300  300           */
 301  301          movl    %cr0, %eax
 302  302  
 303  303          /*
↓ open down ↓ 132 lines elided ↑ open up ↑
 436  436           */
 437  437  
 438  438          movb    $CYRIX_CCR3, %al
 439  439          outb    $CYRIX_CRI
 440  440  
 441  441          /*
 442  442           * If we are not a Cyrix cpu, then we have performed an external I/O
 443  443           * cycle. If the CCR index was not valid for this Cyrix model, we may
 444  444           * have performed an external I/O cycle as well. In these cases and
 445  445           * if the motherboard/chipset vendor ignores I/O address line A1,
 446      -         * then the PIC will have IRQ3 set at the lowest priority as a side     
      446 +         * then the PIC will have IRQ3 set at the lowest priority as a side
 447  447           * effect of the above outb. We are reasonalbly confident that there
 448  448           * is not an unknown device on I/O port 0x22, so there should have been
 449  449           * no unpredictable side-effect of the above outb.
 450  450           */
 451  451  
 452  452          /*
 453  453           * read CCR3
 454  454           */
 455  455          inb     $CYRIX_CRD
 456  456  
↓ open down ↓ 428 lines elided ↑ open up ↑
 885  885          jmp     MII
 886  886  
 887  887  likelyM3:
 888  888          /*
 889  889           * DIR0 with values from 0x80 to 0x8f indicates a VIA Cyrix III, aka
 890  890           * the Cyrix MIII. There may be parts later that use the same ranges
 891  891           * for DIR0 with special values in DIR1, maybe the VIA CIII, but for
 892  892           * now we will call anything with a DIR0 of 0x80 or higher an MIII.
 893  893           * The MIII is supposed to support large pages, but we will believe
 894  894           * it when we see it. For now we just enable and test for MII features.
 895      -         */     
      895 +         */
 896  896          movl    $X86_TYPE_VIA_CYRIX_III, x86_type
 897  897          jmp     likeMII
 898  898  
 899  899  coma_bug:
 900  900  
 901  901  /*
 902  902   * With NO_LOCK set to 0 in CCR1, the usual state that BIOS enforces, some
 903  903   * bus cycles are issued with LOCK# asserted. With NO_LOCK set to 1, all bus
 904  904   * cycles except page table accesses and interrupt ACK cycles do not assert
 905  905   * LOCK#. xchgl is an instruction that asserts LOCK# if NO_LOCK is set to 0.
↓ open down ↓ 17 lines elided ↑ open up ↑
 923  923   * There is now some added penalty for the xchgl instruction, but the usual
 924  924   * bus locking is preserved. This ingenious workaround was discovered by
 925  925   * disassembling a binary provided by Cyrix as a workaround for this bug on
 926  926   * Windows, but its not documented anywhere by Cyrix, nor is the bug actually
 927  927   * mentioned in any public errata! The only concern for this workaround is
 928  928   * that there may be similar undiscovered bugs with other instructions that
 929  929   * assert LOCK# that may be leveraged to similar ends. The fact that Cyrix
 930  930   * fixed this bug sometime late in 1997 and no other exploits other than
 931  931   * xchgl have been discovered is good indication that this workaround is
 932  932   * reasonable.
 933      - */     
      933 + */
 934  934  
 935  935          .set    CYRIX_DBR0, 0x30        / Debug Register 0
 936  936          .set    CYRIX_DBR1, 0x31        / Debug Register 1
 937  937          .set    CYRIX_DBR2, 0x32        / Debug Register 2
 938  938          .set    CYRIX_DBR3, 0x33        / Debug Register 3
 939  939          .set    CYRIX_DOR, 0x3c         / Debug Opcode Register
 940  940  
 941  941          /*
 942      -         * What is known about DBR1, DBR2, DBR3, and DOR is that for normal
      942 +         * What is known about DBR1, DBR2, DBR3, and DOR is that for normal
 943  943           * cpu execution DBR1, DBR2, and DBR3 are set to 0. To obtain opcode
 944  944           * serialization, DBR1, DBR2, and DBR3 are loaded with 0xb8, 0x7f,
 945  945           * and 0xff. Then, DOR is loaded with the one byte opcode.
 946  946           */
 947  947  
 948  948          /*
 949  949           * select CCR3
 950  950           */
 951  951          movb    $CYRIX_CCR3, %al
 952  952          outb    $CYRIX_CRI
↓ open down ↓ 39 lines elided ↑ open up ↑
 992  992           * write DBR0
 993  993           */
 994  994          movb    $CYRIX_DBR0, %al
 995  995          outb    $CYRIX_CRI
 996  996          movb    %bh, %al
 997  997          outb    $CYRIX_CRD
 998  998  
 999  999          /*
1000 1000           * write DBR1
1001 1001           */
1002      -        movb    $CYRIX_DBR1, %al 
     1002 +        movb    $CYRIX_DBR1, %al
1003 1003          outb    $CYRIX_CRI
1004 1004          movb    $0xf8, %al
1005 1005          outb    $CYRIX_CRD
1006 1006  
1007 1007          /*
1008 1008           * write DBR2
1009 1009           */
1010 1010          movb    $CYRIX_DBR2, %al
1011 1011          outb    $CYRIX_CRI
1012 1012          movb    $0x7f, %al
↓ open down ↓ 181 lines elided ↑ open up ↑
1194 1194          jmp     tr_iret_auto
1195 1195          /*NOTREACHED*/
1196 1196  3:
1197 1197          leaq    dtrace_badflags(%rip), %rdi
1198 1198          xorl    %eax, %eax
1199 1199          call    panic
1200 1200  4:
1201 1201          leaq    dtrace_badtrap(%rip), %rdi
1202 1202          xorl    %eax, %eax
1203 1203          call    panic
     1204 +        SET_SIZE(cmntrap_pushed)
1204 1205          SET_SIZE(cmntrap)
1205 1206          SET_SIZE(_cmntrap)
1206 1207  
1207 1208  #elif defined(__i386)
1208 1209  
1209 1210  
1210 1211          ENTRY_NP2(cmntrap, _cmntrap)
1211 1212  
1212 1213          INTR_PUSH
1213 1214  
↓ open down ↓ 1059 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX