Print this page
11787 Kernel needs to be built with retpolines
11788 Kernel needs to generally use RSB stuffing
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: John Levon <john.levon@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/i86pc/ml/cpr_wakecode.s
          +++ new/usr/src/uts/i86pc/ml/cpr_wakecode.s
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
       23 + * Copyright 2019 Joyent, Inc.
  23   24   */
  24      -        
       25 +
  25   26  #include <sys/asm_linkage.h>
  26   27  #include <sys/asm_misc.h>
  27   28  #include <sys/regset.h>
  28   29  #include <sys/privregs.h>
  29   30  #include <sys/x86_archext.h>
  30   31  #include <sys/cpr_wakecode.h>
  31   32  
  32   33  #if !defined(__lint)
  33   34  #include <sys/segments.h>
  34   35  #include "assym.h"
↓ open down ↓ 297 lines elided ↑ open up ↑
 332  333          outb    (%dx)
 333  334  #endif
 334  335  
 335  336  #if     SERIAL
 336  337          D16 movl        $WC_COM, %edx
 337  338          D16 movb        $0x63, %al
 338  339          outb    (%dx)
 339  340  #endif
 340  341  
 341  342          /*
 342      -         * Add any initial cr4 bits
      343 +         * Add any initial cr4 bits
 343  344           */
 344  345          movl            %cr4, %eax
 345  346          A16 D16 orl     CR4OFF, %eax
 346  347  
 347  348          /*
 348  349           * Enable PAE mode (CR4.PAE)
 349  350           */
 350  351          D16 orl         $CR4_PAE, %eax
 351  352          movl            %eax, %cr4
 352  353  
↓ open down ↓ 74 lines elided ↑ open up ↑
 427  428           * in 32-bit space before we can use the kernel's GDT and IDT, which
 428  429           * may be in the 64-bit address space, and since we're in compatability
 429  430           * mode, we only have access to 16 and 32-bit instructions at the
 430  431           * moment.
 431  432           */
 432  433          A16 D16 lgdt    TEMPGDTOFF      /* load temporary GDT */
 433  434          A16 D16 lidt    TEMPIDTOFF      /* load temporary IDT */
 434  435  
 435  436  
 436  437          /*
 437      -         * Do a far transfer to 64-bit mode.  Set the CS selector to a 64-bit
      438 +         * Do a far transfer to 64-bit mode.  Set the CS selector to a 64-bit
 438  439           * long mode selector (CS.L=1) in the temporary 32-bit GDT and jump
 439  440           * to the real mode platter address of wc_long_mode_64 as until the
 440  441           * 64-bit CS is in place we don't have access to 64-bit instructions
 441  442           * and thus can't reference a 64-bit %rip.
 442  443           */
 443  444  
 444  445  #if     LED
 445  446          D16 movl        $WC_LED, %edx
 446  447          D16 movb        $0xd7, %al
 447  448          outb    (%dx)
 448  449  #endif
 449  450  
 450  451  #if     SERIAL
 451  452          D16 movl        $WC_COM, %edx
 452  453          D16 movb        $0x67, %al
 453  454          outb    (%dx)
 454  455  #endif
 455  456  
 456      -        D16     pushl   $TEMP_CS64_SEL
      457 +        D16     pushl   $TEMP_CS64_SEL
 457  458          A16 D16 pushl   LM64OFF
 458  459  
 459  460          D16 lret
 460  461  
 461  462  
 462  463  /*
 463  464   * Support routine to re-initialize VGA subsystem
 464  465   */
 465  466  vgainit:
 466  467          D16 ret
↓ open down ↓ 2 lines elided ↑ open up ↑
 469  470   * Support routine to re-initialize keyboard (which is USB - help!)
 470  471   */
 471  472  kbdinit:
 472  473          D16 ret
 473  474  
 474  475  /*
 475  476   * Support routine to re-initialize COM ports to something sane
 476  477   */
 477  478  cominit:
 478  479          / init COM1 & COM2
 479      -        
      480 +
 480  481  #if     DEBUG
 481  482  /*
 482  483   * on debug kernels we need to initialize COM1 & COM2 here, so that
 483  484   * we can get debug output before the asy driver has resumed
 484  485   */
 485  486  
 486  487  / select COM1
 487  488          D16 movl        $_CONST(COM1+LCR), %edx
 488  489          D16 movb        $DLAB, %al              / divisor latch
 489  490          outb    (%dx)
↓ open down ↓ 181 lines elided ↑ open up ↑
 671  672  1:
 672  673  
 673  674          movq    WC_CR4(%rbx), %rax      / restore full cr4 (with Global Enable)
 674  675          movq    %rax, %cr4
 675  676  
 676  677          lldt    WC_LDT(%rbx)
 677  678          movzwq  WC_TR(%rbx), %rax       / clear TSS busy bit
 678  679          addq    WC_GDT+2(%rbx), %rax
 679  680          andl    $0xfffffdff, 4(%rax)
 680  681          movq    4(%rax), %rcx
 681      -        ltr     WC_TR(%rbx)             
      682 +        ltr     WC_TR(%rbx)
 682  683  
 683  684  #if     LED
 684  685          movw        $WC_LED, %dx
 685  686          movb        $0xdd, %al
 686  687          outb    (%dx)
 687  688  #endif
 688  689  
 689  690  #if     SERIAL
 690  691          movw        $WC_COM, %dx
 691  692          movw        $0x6d, %ax
↓ open down ↓ 2 lines elided ↑ open up ↑
 694  695  
 695  696  / restore %fsbase %gsbase %kgbase registers using wrmsr instruction
 696  697  
 697  698          movq    WC_FS(%rbx), %rcx       / restore fs register
 698  699          movw    %cx, %fs
 699  700  
 700  701          movl    $MSR_AMD_FSBASE, %ecx
 701  702          movl    WC_FSBASE(%rbx), %eax
 702  703          movl    WC_FSBASE+4(%rbx), %edx
 703  704          wrmsr
 704      -        
      705 +
 705  706          movq    WC_GS(%rbx), %rcx       / restore gs register
 706  707          movw    %cx, %gs
 707  708  
 708  709          movl    $MSR_AMD_GSBASE, %ecx   / restore gsbase msr
 709  710          movl    WC_GSBASE(%rbx), %eax
 710  711          movl    WC_GSBASE+4(%rbx), %edx
 711  712          wrmsr
 712  713  
 713  714          movl    $MSR_AMD_KGSBASE, %ecx  / restore kgsbase msr
 714  715          movl    WC_KGSBASE(%rbx), %eax
↓ open down ↓ 38 lines elided ↑ open up ↑
 753  754          /*
 754  755           * APIC initialization
 755  756           */
 756  757          movq    %rsp, %rbp
 757  758  
 758  759          /*
 759  760           * skip iff function pointer is NULL
 760  761           */
 761  762          cmpq    $0, ap_mlsetup
 762  763          je      3f
 763      -        call    *ap_mlsetup
      764 +        leaq    ap_mlsetup, %rax
      765 +        INDIRECT_CALL_REG(rax)
 764  766  3:
 765  767  
 766      -        call    *cpr_start_cpu_func
      768 +        leaq    cpr_start_cpu_func, %rax
      769 +        INDIRECT_CALL_REG(rax)
 767  770  
 768  771  / restore %rbx to the value it ahd before we called the functions above
 769  772          movq    rm_platter_va, %rbx
 770  773          addq    $WC_CPU, %rbx
 771  774  
 772  775          movq    WC_R8(%rbx), %r8
 773  776          movq    WC_R9(%rbx), %r9
 774  777          movq    WC_R10(%rbx), %r10
 775  778          movq    WC_R11(%rbx), %r11
 776  779          movq    WC_R12(%rbx), %r12
↓ open down ↓ 274 lines elided ↑ open up ↑
1051 1054  
1052 1055          .globl wc_rm_end
1053 1056  wc_rm_end:
1054 1057          nop
1055 1058  
1056 1059          .globl  kernel_wc_code
1057 1060  kernel_wc_code:
1058 1061          / At this point we are with kernel's cs and proper eip.
1059 1062          / We will be executing not from the copy in real mode platter,
1060 1063          / but from the original code where boot loaded us.
1061      -        / By this time GDT and IDT are loaded as is cr0, cr3 and cr4. 
     1064 +        / By this time GDT and IDT are loaded as is cr0, cr3 and cr4.
1062 1065          / %ebx is wc_cpu
1063 1066          / %dx is our ds
1064 1067  
1065 1068  #if     LED
1066 1069          D16 movb        $0xdb, %al
1067 1070          outb    $WC_LED
1068 1071  #endif
1069 1072  
1070 1073  / got here OK
1071 1074  
↓ open down ↓ 27 lines elided ↑ open up ↑
1099 1102          andl    $_BITNOT(0x200), 4(%eax)
1100 1103          ltr     WC_TR(%ebx)             / $UTSS_SEL
1101 1104  
1102 1105          movw    WC_SS(%ebx), %ss        / restore segment registers
1103 1106          movw    WC_ES(%ebx), %es
1104 1107          movw    WC_FS(%ebx), %fs
1105 1108          movw    WC_GS(%ebx), %gs
1106 1109  
1107 1110          /*
1108 1111           * set the stack pointer to point into the identity mapped page
1109      -         * temporarily, so we can make function calls 
     1112 +         * temporarily, so we can make function calls
1110 1113           */
1111 1114          .globl  rm_platter_va
1112 1115          movl    rm_platter_va, %eax
1113 1116          movl    $WC_STKSTART, %esp
1114 1117          addl    %eax, %esp
1115 1118          movl    %esp, %ebp
1116 1119  
1117 1120          /*
1118 1121           * if we are not running on the boot CPU restore stack contents by
1119 1122           * calling i_cpr_restore_stack(curthread, save_stack);
↓ open down ↓ 15 lines elided ↑ open up ↑
1135 1138          movl    %eax, (%esp)
1136 1139  
1137 1140          /*
1138 1141           * APIC initialization, skip iff function pointer is NULL
1139 1142           */
1140 1143          cmpl    $0, ap_mlsetup
1141 1144          je      3f
1142 1145          call    *ap_mlsetup
1143 1146  3:
1144 1147  
1145      -        call    *cpr_start_cpu_func
     1148 +        call    *cpr_start_cpu_func
1146 1149  
1147 1150          pushl   WC_EFLAGS(%ebx)         / restore flags
1148 1151          popfl
1149 1152  
1150 1153          movl    WC_EDI(%ebx), %edi      / restore general registers
1151 1154          movl    WC_ESI(%ebx), %esi
1152 1155          movl    WC_EBP(%ebx), %ebp
1153 1156          movl    WC_EBX(%ebx), %ebx
1154 1157  
1155 1158  /exit:  jmp     exit                    / stop here for HDT
↓ open down ↓ 11 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX