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  * Copyright 2018 Joyent, Inc.
  26  */
  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  * Generic trap and interrupt handlers.
  51  */
  52 
  53 #if defined(__xpv) && defined(__amd64)
  54 
  55 /*
  56  * The hypervisor places r11 and rcx on the stack.
  57  */
  58 
  59 #define TRAP_NOERR(trapno) \
  60         popq    %rcx;           \
  61         popq    %r11;           \
  62         pushq   $trapno
  63 
  64 #define TRAP_ERR(trapno)        \
  65         popq    %rcx;           \
  66         popq    %r11;           \
  67         pushq   $0;             \
  68         pushq   $trapno
  69 
  70 #else
  71 
  72 #define TRAP_NOERR(trapno)      \
  73         push    $trapno
  74 
  75 #define TRAP_ERR(trapno)        \
  76         push    $0;             \
  77         push    $trapno
  78 
  79 #endif  /* __xpv && __amd64 */
  80 
  81 
  82 #define MKIVCT(n) \
  83         ENTRY_NP(kdi_ivct/**/n/**/);    \
  84         TRAP_ERR(n);                    \
  85         jmp     kdi_cmnint;             \
  86         SET_SIZE(kdi_ivct/**/n/**/)
  87 
  88 #define MKTRAPHDLR(n) \
  89         ENTRY_NP(kdi_trap/**/n);        \
  90         TRAP_ERR(n);                    \
  91         jmp     kdi_cmnint;             \
  92         SET_SIZE(kdi_trap/**/n/**/)
  93 
  94 #define MKTRAPERRHDLR(n) \
  95         ENTRY_NP(kdi_traperr/**/n);     \
  96         TRAP_NOERR(n);                  \
  97         jmp     kdi_cmnint;             \
  98         SET_SIZE(kdi_traperr/**/n)
  99 
 100 #define MKNMIHDLR \
 101         ENTRY_NP(kdi_int2);             \
 102         TRAP_NOERR(2);                  \
 103         jmp     kdi_nmiint;             \
 104         SET_SIZE(kdi_int2)
 105 
 106 #define MKINVALHDLR \
 107         ENTRY_NP(kdi_invaltrap);        \
 108         TRAP_NOERR(255);                \
 109         jmp     kdi_cmnint;             \
 110         SET_SIZE(kdi_invaltrap)
 111 
 112 /*
 113  * The handlers themselves
 114  */
 115 
 116         MKINVALHDLR
 117         MKTRAPHDLR(0)
 118         MKTRAPHDLR(1)
 119         MKNMIHDLR/*2*/
 120         MKTRAPHDLR(3)
 121         MKTRAPHDLR(4)
 122         MKTRAPHDLR(5)
 123         MKTRAPHDLR(6)
 124         MKTRAPHDLR(7)
 125         MKTRAPHDLR(9)
 126         MKTRAPHDLR(15)
 127         MKTRAPHDLR(16)
 128         MKTRAPHDLR(17)
 129         MKTRAPHDLR(18)
 130         MKTRAPHDLR(19)
 131         MKTRAPHDLR(20)
 132 
 133         MKTRAPERRHDLR(8)
 134         MKTRAPERRHDLR(10)
 135         MKTRAPERRHDLR(11)
 136         MKTRAPERRHDLR(12)
 137         MKTRAPERRHDLR(13)
 138         MKTRAPERRHDLR(14)
 139 
 140         .globl  kdi_ivct_size
 141 kdi_ivct_size:
 142         .NWORD [kdi_ivct33-kdi_ivct32]
 143         
 144         /* 10 billion and one interrupt handlers */
 145 kdi_ivct_base:
 146         MKIVCT(32);     MKIVCT(33);     MKIVCT(34);     MKIVCT(35);
 147         MKIVCT(36);     MKIVCT(37);     MKIVCT(38);     MKIVCT(39);
 148         MKIVCT(40);     MKIVCT(41);     MKIVCT(42);     MKIVCT(43);
 149         MKIVCT(44);     MKIVCT(45);     MKIVCT(46);     MKIVCT(47);
 150         MKIVCT(48);     MKIVCT(49);     MKIVCT(50);     MKIVCT(51);
 151         MKIVCT(52);     MKIVCT(53);     MKIVCT(54);     MKIVCT(55);
 152         MKIVCT(56);     MKIVCT(57);     MKIVCT(58);     MKIVCT(59);
 153         MKIVCT(60);     MKIVCT(61);     MKIVCT(62);     MKIVCT(63);
 154         MKIVCT(64);     MKIVCT(65);     MKIVCT(66);     MKIVCT(67);
 155         MKIVCT(68);     MKIVCT(69);     MKIVCT(70);     MKIVCT(71);
 156         MKIVCT(72);     MKIVCT(73);     MKIVCT(74);     MKIVCT(75);
 157         MKIVCT(76);     MKIVCT(77);     MKIVCT(78);     MKIVCT(79);
 158         MKIVCT(80);     MKIVCT(81);     MKIVCT(82);     MKIVCT(83);
 159         MKIVCT(84);     MKIVCT(85);     MKIVCT(86);     MKIVCT(87);
 160         MKIVCT(88);     MKIVCT(89);     MKIVCT(90);     MKIVCT(91);
 161         MKIVCT(92);     MKIVCT(93);     MKIVCT(94);     MKIVCT(95);
 162         MKIVCT(96);     MKIVCT(97);     MKIVCT(98);     MKIVCT(99);
 163         MKIVCT(100);    MKIVCT(101);    MKIVCT(102);    MKIVCT(103);
 164         MKIVCT(104);    MKIVCT(105);    MKIVCT(106);    MKIVCT(107);
 165         MKIVCT(108);    MKIVCT(109);    MKIVCT(110);    MKIVCT(111);
 166         MKIVCT(112);    MKIVCT(113);    MKIVCT(114);    MKIVCT(115);
 167         MKIVCT(116);    MKIVCT(117);    MKIVCT(118);    MKIVCT(119);
 168         MKIVCT(120);    MKIVCT(121);    MKIVCT(122);    MKIVCT(123);
 169         MKIVCT(124);    MKIVCT(125);    MKIVCT(126);    MKIVCT(127);
 170         MKIVCT(128);    MKIVCT(129);    MKIVCT(130);    MKIVCT(131);
 171         MKIVCT(132);    MKIVCT(133);    MKIVCT(134);    MKIVCT(135);
 172         MKIVCT(136);    MKIVCT(137);    MKIVCT(138);    MKIVCT(139);
 173         MKIVCT(140);    MKIVCT(141);    MKIVCT(142);    MKIVCT(143);
 174         MKIVCT(144);    MKIVCT(145);    MKIVCT(146);    MKIVCT(147);
 175         MKIVCT(148);    MKIVCT(149);    MKIVCT(150);    MKIVCT(151);
 176         MKIVCT(152);    MKIVCT(153);    MKIVCT(154);    MKIVCT(155);
 177         MKIVCT(156);    MKIVCT(157);    MKIVCT(158);    MKIVCT(159);
 178         MKIVCT(160);    MKIVCT(161);    MKIVCT(162);    MKIVCT(163);
 179         MKIVCT(164);    MKIVCT(165);    MKIVCT(166);    MKIVCT(167);
 180         MKIVCT(168);    MKIVCT(169);    MKIVCT(170);    MKIVCT(171);
 181         MKIVCT(172);    MKIVCT(173);    MKIVCT(174);    MKIVCT(175);
 182         MKIVCT(176);    MKIVCT(177);    MKIVCT(178);    MKIVCT(179);
 183         MKIVCT(180);    MKIVCT(181);    MKIVCT(182);    MKIVCT(183);
 184         MKIVCT(184);    MKIVCT(185);    MKIVCT(186);    MKIVCT(187);
 185         MKIVCT(188);    MKIVCT(189);    MKIVCT(190);    MKIVCT(191);
 186         MKIVCT(192);    MKIVCT(193);    MKIVCT(194);    MKIVCT(195);
 187         MKIVCT(196);    MKIVCT(197);    MKIVCT(198);    MKIVCT(199);
 188         MKIVCT(200);    MKIVCT(201);    MKIVCT(202);    MKIVCT(203);
 189         MKIVCT(204);    MKIVCT(205);    MKIVCT(206);    MKIVCT(207);
 190         MKIVCT(208);    MKIVCT(209);    MKIVCT(210);    MKIVCT(211);
 191         MKIVCT(212);    MKIVCT(213);    MKIVCT(214);    MKIVCT(215);
 192         MKIVCT(216);    MKIVCT(217);    MKIVCT(218);    MKIVCT(219);
 193         MKIVCT(220);    MKIVCT(221);    MKIVCT(222);    MKIVCT(223);
 194         MKIVCT(224);    MKIVCT(225);    MKIVCT(226);    MKIVCT(227);
 195         MKIVCT(228);    MKIVCT(229);    MKIVCT(230);    MKIVCT(231);
 196         MKIVCT(232);    MKIVCT(233);    MKIVCT(234);    MKIVCT(235);
 197         MKIVCT(236);    MKIVCT(237);    MKIVCT(238);    MKIVCT(239);
 198         MKIVCT(240);    MKIVCT(241);    MKIVCT(242);    MKIVCT(243);
 199         MKIVCT(244);    MKIVCT(245);    MKIVCT(246);    MKIVCT(247);
 200         MKIVCT(248);    MKIVCT(249);    MKIVCT(250);    MKIVCT(251);
 201         MKIVCT(252);    MKIVCT(253);    MKIVCT(254);    MKIVCT(255);
 202 
 203 #endif