8956 Implement KPTI
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
9210 remove KMDB branch debugging support
9211 ::crregs could do with cr2/cr3 support
9209 ::ttrace should be able to filter by thread
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Yuri Pankov <yuripv@yuripv.net>

   1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.


  24  */
  25 
  26 #pragma ident   "%Z%%M% %I%     %E% SMI"
  27 
  28 /*
  29  * Companion to kdi_idt.c - the implementation of the trap and interrupt
  30  * handlers.  For the most part, these handlers do the same thing - they
  31  * push a trap number onto the stack, followed by a jump to kdi_cmnint.
  32  * Each trap and interrupt has its own handler because each one pushes a
  33  * different number.
  34  */
  35 




  36 #include <sys/asm_linkage.h>



  37 #include <sys/kdi_regs.h>


  38 
  39 /* Nothing in this file is of interest to lint. */
  40 #if !defined(__lint)
  41 
  42 /* 
  43  * The default ASM_ENTRY_ALIGN (16) wastes far too much space.  Pay no
  44  * attention to the fleet of nop's we're adding to each handler.
  45  */
  46 #undef  ASM_ENTRY_ALIGN
  47 #define ASM_ENTRY_ALIGN 8
  48 
  49 /*
  50  * We need the .align in ENTRY_NP (defined to be ASM_ENTRY_ALIGN) to match our
  51  * manual .align (KDI_MSR_PATCHOFF) in order to ensure that the space reserved
  52  * at the beginning of the handler for code is exactly KDI_MSR_PATCHOFF bytes
  53  * long.  Note that the #error below isn't supported by the preprocessor invoked
  54  * by as(1), and won't stop the build, but it'll emit a noticeable error message
  55  * which won't escape the filters.
  56  */
  57 #if ASM_ENTRY_ALIGN != KDI_MSR_PATCHOFF
  58 #error "ASM_ENTRY_ALIGN != KDI_MSR_PATCHOFF"
  59 this won't assemble
  60 #endif
  61 
  62 /*
  63  * kdi_idt_patch will, on certain processors, replace the patch points below
  64  * with MSR-clearing code.  kdi_id_patch has intimate knowledge of the size of
  65  * the nop hole, as well as the structure of the handlers.  Do not change
  66  * anything here without also changing kdi_idt_patch.
  67  */
  68 
  69 /*
  70  * Generic trap and interrupt handlers.
  71  */
  72 
  73 #if defined(__xpv) && defined(__amd64)
  74 
  75 /*
  76  * The hypervisor places r11 and rcx on the stack.


  77  */
  78 
  79 #define TRAP_NOERR(trapno) \
  80         popq    %rcx;           \
  81         popq    %r11;           \
  82         pushq   $trapno
























































  83 
  84 #define TRAP_ERR(trapno)        \
  85         popq    %rcx;           \
  86         popq    %r11;           \
  87         pushq   $0;             \
  88         pushq   $trapno
  89 
  90 #else
  91 
  92 #define TRAP_NOERR(trapno)      \
  93         push    $trapno
  94 
  95 #define TRAP_ERR(trapno)        \
  96         push    $0;             \
  97         push    $trapno
  98 
  99 #endif  /* __xpv && __amd64 */
 100 
 101 
 102 #define MKIVCT(n) \
 103         ENTRY_NP(kdi_ivct/**/n/**/);    \
 104         TRAP_ERR(n);                    \
 105         .align  KDI_MSR_PATCHOFF;       \
 106         KDI_MSR_PATCH;                  \

 107         jmp     kdi_cmnint;             \
 108         SET_SIZE(kdi_ivct/**/n/**/)
 109 
 110 #define MKTRAPHDLR(n) \
 111         ENTRY_NP(kdi_trap/**/n);        \
 112         TRAP_ERR(n);                    \
 113         .align  KDI_MSR_PATCHOFF;       \
 114         KDI_MSR_PATCH;                  \

 115         jmp     kdi_cmnint;             \
 116         SET_SIZE(kdi_trap/**/n/**/)
 117 
 118 #define MKTRAPERRHDLR(n) \
 119         ENTRY_NP(kdi_traperr/**/n);     \
 120         TRAP_NOERR(n);                  \
 121         .align  KDI_MSR_PATCHOFF;       \
 122         KDI_MSR_PATCH;                  \
 123         jmp     kdi_cmnint;             \
 124         SET_SIZE(kdi_traperr/**/n)
 125 

 126 #define MKNMIHDLR \
 127         ENTRY_NP(kdi_int2);             \
 128         TRAP_NOERR(2);                  \
 129         .align  KDI_MSR_PATCHOFF;       \
 130         KDI_MSR_PATCH;                  \



 131         jmp     kdi_nmiint;             \
 132         SET_SIZE(kdi_int2)
 133 






























 134 #define MKINVALHDLR \
 135         ENTRY_NP(kdi_invaltrap);        \
 136         TRAP_NOERR(255);                \
 137         .align  KDI_MSR_PATCHOFF;       \
 138         KDI_MSR_PATCH;                  \

 139         jmp     kdi_cmnint;             \
 140         SET_SIZE(kdi_invaltrap)
 141 















 142 /*
 143  * The handlers themselves
 144  */
 145 
 146         MKINVALHDLR
 147         MKTRAPHDLR(0)
 148         MKTRAPHDLR(1)
 149         MKNMIHDLR/*2*/
 150         MKTRAPHDLR(3)
 151         MKTRAPHDLR(4)
 152         MKTRAPHDLR(5)
 153         MKTRAPHDLR(6)
 154         MKTRAPHDLR(7)
 155         MKTRAPHDLR(9)
 156         MKTRAPHDLR(15)
 157         MKTRAPHDLR(16)
 158         MKTRAPHDLR(17)
 159         MKTRAPHDLR(18)
 160         MKTRAPHDLR(19)
 161         MKTRAPHDLR(20)
 162 
 163         MKTRAPERRHDLR(8)
 164         MKTRAPERRHDLR(10)
 165         MKTRAPERRHDLR(11)
 166         MKTRAPERRHDLR(12)
 167         MKTRAPERRHDLR(13)
 168         MKTRAPERRHDLR(14)

 169 
 170         .globl  kdi_ivct_size
 171 kdi_ivct_size:
 172         .NWORD [kdi_ivct33-kdi_ivct32]
 173         
 174         /* 10 billion and one interrupt handlers */
 175 kdi_ivct_base:
 176         MKIVCT(32);     MKIVCT(33);     MKIVCT(34);     MKIVCT(35);
 177         MKIVCT(36);     MKIVCT(37);     MKIVCT(38);     MKIVCT(39);
 178         MKIVCT(40);     MKIVCT(41);     MKIVCT(42);     MKIVCT(43);
 179         MKIVCT(44);     MKIVCT(45);     MKIVCT(46);     MKIVCT(47);
 180         MKIVCT(48);     MKIVCT(49);     MKIVCT(50);     MKIVCT(51);
 181         MKIVCT(52);     MKIVCT(53);     MKIVCT(54);     MKIVCT(55);
 182         MKIVCT(56);     MKIVCT(57);     MKIVCT(58);     MKIVCT(59);
 183         MKIVCT(60);     MKIVCT(61);     MKIVCT(62);     MKIVCT(63);
 184         MKIVCT(64);     MKIVCT(65);     MKIVCT(66);     MKIVCT(67);
 185         MKIVCT(68);     MKIVCT(69);     MKIVCT(70);     MKIVCT(71);
 186         MKIVCT(72);     MKIVCT(73);     MKIVCT(74);     MKIVCT(75);
 187         MKIVCT(76);     MKIVCT(77);     MKIVCT(78);     MKIVCT(79);
 188         MKIVCT(80);     MKIVCT(81);     MKIVCT(82);     MKIVCT(83);
 189         MKIVCT(84);     MKIVCT(85);     MKIVCT(86);     MKIVCT(87);
 190         MKIVCT(88);     MKIVCT(89);     MKIVCT(90);     MKIVCT(91);
 191         MKIVCT(92);     MKIVCT(93);     MKIVCT(94);     MKIVCT(95);
 192         MKIVCT(96);     MKIVCT(97);     MKIVCT(98);     MKIVCT(99);
 193         MKIVCT(100);    MKIVCT(101);    MKIVCT(102);    MKIVCT(103);
 194         MKIVCT(104);    MKIVCT(105);    MKIVCT(106);    MKIVCT(107);
 195         MKIVCT(108);    MKIVCT(109);    MKIVCT(110);    MKIVCT(111);
 196         MKIVCT(112);    MKIVCT(113);    MKIVCT(114);    MKIVCT(115);
 197         MKIVCT(116);    MKIVCT(117);    MKIVCT(118);    MKIVCT(119);
 198         MKIVCT(120);    MKIVCT(121);    MKIVCT(122);    MKIVCT(123);
 199         MKIVCT(124);    MKIVCT(125);    MKIVCT(126);    MKIVCT(127);
 200         MKIVCT(128);    MKIVCT(129);    MKIVCT(130);    MKIVCT(131);
 201         MKIVCT(132);    MKIVCT(133);    MKIVCT(134);    MKIVCT(135);
 202         MKIVCT(136);    MKIVCT(137);    MKIVCT(138);    MKIVCT(139);
 203         MKIVCT(140);    MKIVCT(141);    MKIVCT(142);    MKIVCT(143);
 204         MKIVCT(144);    MKIVCT(145);    MKIVCT(146);    MKIVCT(147);
 205         MKIVCT(148);    MKIVCT(149);    MKIVCT(150);    MKIVCT(151);
 206         MKIVCT(152);    MKIVCT(153);    MKIVCT(154);    MKIVCT(155);
 207         MKIVCT(156);    MKIVCT(157);    MKIVCT(158);    MKIVCT(159);
 208         MKIVCT(160);    MKIVCT(161);    MKIVCT(162);    MKIVCT(163);
 209         MKIVCT(164);    MKIVCT(165);    MKIVCT(166);    MKIVCT(167);
 210         MKIVCT(168);    MKIVCT(169);    MKIVCT(170);    MKIVCT(171);
 211         MKIVCT(172);    MKIVCT(173);    MKIVCT(174);    MKIVCT(175);
 212         MKIVCT(176);    MKIVCT(177);    MKIVCT(178);    MKIVCT(179);
 213         MKIVCT(180);    MKIVCT(181);    MKIVCT(182);    MKIVCT(183);
 214         MKIVCT(184);    MKIVCT(185);    MKIVCT(186);    MKIVCT(187);
 215         MKIVCT(188);    MKIVCT(189);    MKIVCT(190);    MKIVCT(191);
 216         MKIVCT(192);    MKIVCT(193);    MKIVCT(194);    MKIVCT(195);
 217         MKIVCT(196);    MKIVCT(197);    MKIVCT(198);    MKIVCT(199);
 218         MKIVCT(200);    MKIVCT(201);    MKIVCT(202);    MKIVCT(203);
 219         MKIVCT(204);    MKIVCT(205);    MKIVCT(206);    MKIVCT(207);
 220         MKIVCT(208);    MKIVCT(209);    MKIVCT(210);    MKIVCT(211);
 221         MKIVCT(212);    MKIVCT(213);    MKIVCT(214);    MKIVCT(215);
 222         MKIVCT(216);    MKIVCT(217);    MKIVCT(218);    MKIVCT(219);
 223         MKIVCT(220);    MKIVCT(221);    MKIVCT(222);    MKIVCT(223);
 224         MKIVCT(224);    MKIVCT(225);    MKIVCT(226);    MKIVCT(227);
 225         MKIVCT(228);    MKIVCT(229);    MKIVCT(230);    MKIVCT(231);
 226         MKIVCT(232);    MKIVCT(233);    MKIVCT(234);    MKIVCT(235);
 227         MKIVCT(236);    MKIVCT(237);    MKIVCT(238);    MKIVCT(239);
 228         MKIVCT(240);    MKIVCT(241);    MKIVCT(242);    MKIVCT(243);
 229         MKIVCT(244);    MKIVCT(245);    MKIVCT(246);    MKIVCT(247);
 230         MKIVCT(248);    MKIVCT(249);    MKIVCT(250);    MKIVCT(251);
 231         MKIVCT(252);    MKIVCT(253);    MKIVCT(254);    MKIVCT(255);
 232 






 233 #endif


--- EOF ---