Print this page
8956 Implement KPTI
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.

  25  */
  26 
  27 
  28 #if defined(__lint)
  29 
  30 int fb_swtch_silence_lint = 0;
  31 
  32 #else
  33 
  34 #include <sys/asm_linkage.h>
  35 #include <sys/segments.h>
  36 #include <sys/controlregs.h>
  37 #include <sys/machparam.h>
  38 #include <sys/multiboot.h>
  39 #include <sys/fastboot.h>
  40 #include "assym.h"
  41 
  42 /*
  43  * This code is to switch from 64-bit or 32-bit to protected mode.
  44  */
  45 
  46 /*
  47  * For debugging with LEDs
  48  */
  49 #define FB_OUTB_ASM(val)        \
  50     movb        val, %al;       \
  51     outb        $0x80;
  52 
  53 
  54 #define DISABLE_PAGING                                                  \



  55         movl    %cr0, %eax                                              ;\
  56         btrl    $31, %eax       /* clear PG bit */                      ;\
  57         movl    %eax, %cr0
  58 
  59 /*
  60  * This macro contains common code for 64/32-bit versions of copy_sections().
  61  * On entry:
  62  *      fbf points to the fboot_file_t
  63  *      snum contains the number of sections
  64  * Registers that would be clobbered:
  65  *      fbs, snum, %eax, %ecx, %edi, %esi.
  66  * NOTE: fb_dest_pa is supposed to be in the first 1GB,
  67  * therefore it is safe to use 32-bit register to hold it's value
  68  * even for 64-bit code.
  69  */
  70 
  71 #define COPY_SECT(fbf, fbs, snum)               \
  72         lea     FB_SECTIONS(fbf), fbs;          \
  73         xorl    %eax, %eax;                     \
  74 1:      movl    FB_DEST_PA(fbf), %esi;          \


 205         pushq   $B32DATA_SEL
 206         pushq   %rax
 207         pushf
 208         pushq   $B32CODE_SEL
 209         pushq   $1f
 210         iretq
 211 
 212         .code32
 213 1:
 214         movl    $B32DATA_SEL, %eax
 215         movw    %ax, %ss
 216         movw    %ax, %ds
 217         movw    %ax, %es
 218         movw    %ax, %fs
 219         movw    %ax, %gs
 220 
 221         /*
 222          * Disable long mode by:
 223          * - shutting down paging (bit 31 of cr0).  This will flush the
 224          *   TLBs.

 225          * - disabling LME (long mode enable) in EFER (extended feature reg)
 226          */
 227 #endif
 228         DISABLE_PAGING          /* clobbers %eax */
 229 
 230 #if defined(__amd64)
 231         ljmp    $B32CODE_SEL, $1f
 232 1:
 233 #endif
 234 
 235         /*
 236          * Clear PGE, PAE and PSE flags as dboot expects them to be
 237          * cleared.
 238          */
 239         movl    %cr4, %eax
 240         andl    $_BITNOT(CR4_PGE | CR4_PAE | CR4_PSE), %eax
 241         movl    %eax, %cr4
 242 
 243 #if defined(__amd64)
 244         movl    $MSR_AMD_EFER, %ecx     /* Extended Feature Enable */




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  * Copyright 2018 Joyent, Inc.
  26  */
  27 
  28 
  29 #if defined(__lint)
  30 
  31 int fb_swtch_silence_lint = 0;
  32 
  33 #else
  34 
  35 #include <sys/asm_linkage.h>
  36 #include <sys/segments.h>
  37 #include <sys/controlregs.h>
  38 #include <sys/machparam.h>
  39 #include <sys/multiboot.h>
  40 #include <sys/fastboot.h>
  41 #include "assym.h"
  42 
  43 /*
  44  * This code is to switch from 64-bit or 32-bit to protected mode.
  45  */
  46 
  47 /*
  48  * For debugging with LEDs
  49  */
  50 #define FB_OUTB_ASM(val)        \
  51     movb        val, %al;       \
  52     outb        $0x80;
  53 
  54 
  55 #define DISABLE_PAGING                                                  \
  56         movl    %cr4, %eax                                              ;\
  57         btrl    $17, %eax       /* clear PCIDE bit */                   ;\
  58         movl    %eax, %cr4                                              ;\
  59         movl    %cr0, %eax                                              ;\
  60         btrl    $31, %eax       /* clear PG bit */                      ;\
  61         movl    %eax, %cr0
  62 
  63 /*
  64  * This macro contains common code for 64/32-bit versions of copy_sections().
  65  * On entry:
  66  *      fbf points to the fboot_file_t
  67  *      snum contains the number of sections
  68  * Registers that would be clobbered:
  69  *      fbs, snum, %eax, %ecx, %edi, %esi.
  70  * NOTE: fb_dest_pa is supposed to be in the first 1GB,
  71  * therefore it is safe to use 32-bit register to hold it's value
  72  * even for 64-bit code.
  73  */
  74 
  75 #define COPY_SECT(fbf, fbs, snum)               \
  76         lea     FB_SECTIONS(fbf), fbs;          \
  77         xorl    %eax, %eax;                     \
  78 1:      movl    FB_DEST_PA(fbf), %esi;          \


 209         pushq   $B32DATA_SEL
 210         pushq   %rax
 211         pushf
 212         pushq   $B32CODE_SEL
 213         pushq   $1f
 214         iretq
 215 
 216         .code32
 217 1:
 218         movl    $B32DATA_SEL, %eax
 219         movw    %ax, %ss
 220         movw    %ax, %ds
 221         movw    %ax, %es
 222         movw    %ax, %fs
 223         movw    %ax, %gs
 224 
 225         /*
 226          * Disable long mode by:
 227          * - shutting down paging (bit 31 of cr0).  This will flush the
 228          *   TLBs.
 229          * - turning off PCID in cr4
 230          * - disabling LME (long mode enable) in EFER (extended feature reg)
 231          */
 232 #endif
 233         DISABLE_PAGING          /* clobbers %eax */
 234 
 235 #if defined(__amd64)
 236         ljmp    $B32CODE_SEL, $1f
 237 1:
 238 #endif
 239 
 240         /*
 241          * Clear PGE, PAE and PSE flags as dboot expects them to be
 242          * cleared.
 243          */
 244         movl    %cr4, %eax
 245         andl    $_BITNOT(CR4_PGE | CR4_PAE | CR4_PSE), %eax
 246         movl    %eax, %cr4
 247 
 248 #if defined(__amd64)
 249         movl    $MSR_AMD_EFER, %ecx     /* Extended Feature Enable */