1*87531432Sknakahara/* $NetBSD: i386_trap.S,v 1.23 2022/09/07 00:40:18 knakahara Exp $ */ 254b0c8d9Suebayasi 354b0c8d9Suebayasi/* 454b0c8d9Suebayasi * Copyright 2002 (c) Wasabi Systems, Inc. 554b0c8d9Suebayasi * All rights reserved. 654b0c8d9Suebayasi * 754b0c8d9Suebayasi * Written by Frank van der Linden for Wasabi Systems, Inc. 854b0c8d9Suebayasi * 954b0c8d9Suebayasi * Redistribution and use in source and binary forms, with or without 1054b0c8d9Suebayasi * modification, are permitted provided that the following conditions 1154b0c8d9Suebayasi * are met: 1254b0c8d9Suebayasi * 1. Redistributions of source code must retain the above copyright 1354b0c8d9Suebayasi * notice, this list of conditions and the following disclaimer. 1454b0c8d9Suebayasi * 2. Redistributions in binary form must reproduce the above copyright 1554b0c8d9Suebayasi * notice, this list of conditions and the following disclaimer in the 1654b0c8d9Suebayasi * documentation and/or other materials provided with the distribution. 1754b0c8d9Suebayasi * 3. All advertising materials mentioning features or use of this software 1854b0c8d9Suebayasi * must display the following acknowledgement: 1954b0c8d9Suebayasi * This product includes software developed for the NetBSD Project by 2054b0c8d9Suebayasi * Wasabi Systems, Inc. 2154b0c8d9Suebayasi * 4. The name of Wasabi Systems, Inc. may not be used to endorse 2254b0c8d9Suebayasi * or promote products derived from this software without specific prior 2354b0c8d9Suebayasi * written permission. 2454b0c8d9Suebayasi * 2554b0c8d9Suebayasi * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 2654b0c8d9Suebayasi * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2754b0c8d9Suebayasi * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2854b0c8d9Suebayasi * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 2954b0c8d9Suebayasi * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3054b0c8d9Suebayasi * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3154b0c8d9Suebayasi * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3254b0c8d9Suebayasi * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3354b0c8d9Suebayasi * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3454b0c8d9Suebayasi * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3554b0c8d9Suebayasi * POSSIBILITY OF SUCH DAMAGE. 3654b0c8d9Suebayasi */ 3754b0c8d9Suebayasi 3803b96c31Smaxv/* 3954b0c8d9Suebayasi * Copyright (c) 1998, 2007, 2009 The NetBSD Foundation, Inc. 4054b0c8d9Suebayasi * All rights reserved. 4154b0c8d9Suebayasi * 4254b0c8d9Suebayasi * This code is derived from software contributed to The NetBSD Foundation 4354b0c8d9Suebayasi * by Charles M. Hannum, and by Andrew Doran. 4454b0c8d9Suebayasi * 4554b0c8d9Suebayasi * Redistribution and use in source and binary forms, with or without 4654b0c8d9Suebayasi * modification, are permitted provided that the following conditions 4754b0c8d9Suebayasi * are met: 4854b0c8d9Suebayasi * 1. Redistributions of source code must retain the above copyright 4954b0c8d9Suebayasi * notice, this list of conditions and the following disclaimer. 5054b0c8d9Suebayasi * 2. Redistributions in binary form must reproduce the above copyright 5154b0c8d9Suebayasi * notice, this list of conditions and the following disclaimer in the 5254b0c8d9Suebayasi * documentation and/or other materials provided with the distribution. 5354b0c8d9Suebayasi * 5454b0c8d9Suebayasi * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 5554b0c8d9Suebayasi * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 5654b0c8d9Suebayasi * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 5754b0c8d9Suebayasi * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 5854b0c8d9Suebayasi * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 5954b0c8d9Suebayasi * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 6054b0c8d9Suebayasi * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 6154b0c8d9Suebayasi * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 6254b0c8d9Suebayasi * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 6354b0c8d9Suebayasi * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 6454b0c8d9Suebayasi * POSSIBILITY OF SUCH DAMAGE. 6554b0c8d9Suebayasi */ 6654b0c8d9Suebayasi 6754b0c8d9Suebayasi#if 0 6854b0c8d9Suebayasi#include <machine/asm.h> 69*87531432Sknakahara__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.23 2022/09/07 00:40:18 knakahara Exp $"); 7054b0c8d9Suebayasi#endif 7154b0c8d9Suebayasi 7254b0c8d9Suebayasi/* 7354b0c8d9Suebayasi * Trap and fault vector routines 7454b0c8d9Suebayasi * 7554b0c8d9Suebayasi * On exit from the kernel to user mode, we always need to check for ASTs. In 7654b0c8d9Suebayasi * addition, we need to do this atomically; otherwise an interrupt may occur 7754b0c8d9Suebayasi * which causes an AST, but it won't get processed until the next kernel entry 7854b0c8d9Suebayasi * (possibly the next clock tick). Thus, we disable interrupt before checking, 7954b0c8d9Suebayasi * and only enable them again on the final `iret' or before calling the AST 8054b0c8d9Suebayasi * handler. 8154b0c8d9Suebayasi */ 8254b0c8d9Suebayasi 8354b0c8d9Suebayasi#define TRAP(a) pushl $(a) ; jmp _C_LABEL(alltraps) 8454b0c8d9Suebayasi#define ZTRAP(a) pushl $0 ; TRAP(a) 8554b0c8d9Suebayasi 8654b0c8d9Suebayasi .text 8754b0c8d9SuebayasiIDTVEC(trap00) 8854b0c8d9Suebayasi ZTRAP(T_DIVIDE) 8954b0c8d9SuebayasiIDTVEC_END(trap00) 9003b96c31Smaxv 91742dfa9eSmaxv/* 92742dfa9eSmaxv * Handle the SS shadow, CVE-2018-8897. 93742dfa9eSmaxv * 94742dfa9eSmaxv * We scan the IDT to determine if we hit an entry point. If so, we leave 95742dfa9eSmaxv * without restoring the segregs, because we could fault while doing that. 96742dfa9eSmaxv */ 9754b0c8d9SuebayasiIDTVEC(trap01) 98bf5abc14Scherry#ifndef XENPV 99742dfa9eSmaxv pushl $0 100742dfa9eSmaxv pushl $T_TRCTRAP 101742dfa9eSmaxv INTRENTRY 102742dfa9eSmaxv 103742dfa9eSmaxv testb $SEL_UPL,TF_CS(%esp) 104742dfa9eSmaxv jnz .Lnormal_dbentry 105742dfa9eSmaxv 106742dfa9eSmaxv pushl %esp 107742dfa9eSmaxv call ss_shadow 108742dfa9eSmaxv addl $4,%esp 109742dfa9eSmaxv 110742dfa9eSmaxv cmpl $1,%eax 111742dfa9eSmaxv jne .Lnormal_dbentry 112742dfa9eSmaxv 113742dfa9eSmaxv /* SS shadow, ignore the exception. */ 114742dfa9eSmaxv xorl %eax,%eax 115742dfa9eSmaxv movl %eax,%dr6 116742dfa9eSmaxv 117742dfa9eSmaxv /* INTRFASTEXIT, but without segregs. */ 118742dfa9eSmaxv movl TF_EDI(%esp),%edi 119742dfa9eSmaxv movl TF_ESI(%esp),%esi 120742dfa9eSmaxv movl TF_EBP(%esp),%ebp 121742dfa9eSmaxv movl TF_EBX(%esp),%ebx 122742dfa9eSmaxv movl TF_EDX(%esp),%edx 123742dfa9eSmaxv movl TF_ECX(%esp),%ecx 124742dfa9eSmaxv movl TF_EAX(%esp),%eax 125742dfa9eSmaxv addl $(TF_PUSHSIZE+8),%esp 126742dfa9eSmaxv iret 127742dfa9eSmaxv 128742dfa9eSmaxv.Lnormal_dbentry: 129742dfa9eSmaxv STI(%eax) 130742dfa9eSmaxv jmp _C_LABEL(calltrap) 131742dfa9eSmaxv#else 1329614cf02Smaxv ZTRAP(T_TRCTRAP) 133742dfa9eSmaxv#endif 13454b0c8d9SuebayasiIDTVEC_END(trap01) 13503b96c31Smaxv 1365c26a1a4Smaxv/* 1375c26a1a4Smaxv * Non Maskable Interrupts are a special case: they can be triggered even 1385c26a1a4Smaxv * with interrupts disabled, and once triggered they block further NMIs 1395c26a1a4Smaxv * until an 'iret' instruction is executed. 1405c26a1a4Smaxv * 1415c26a1a4Smaxv * Therefore we don't enable interrupts, because the CPU could switch to 1425c26a1a4Smaxv * another LWP, call 'iret' and unintentionally leave the NMI mode. 1435c26a1a4Smaxv */ 14454b0c8d9SuebayasiIDTVEC(trap02) 14554b0c8d9Suebayasi pushl $0 14654b0c8d9Suebayasi pushl $(T_NMI) 14754b0c8d9Suebayasi INTRENTRY 1485c26a1a4Smaxv 1495c26a1a4Smaxv addl $1,CPUVAR(NTRAP) /* statistical info */ 1505c26a1a4Smaxv adcl $0,CPUVAR(NTRAP)+4 1515c26a1a4Smaxv pushl %esp 1525c26a1a4Smaxv call _C_LABEL(trap) 1535c26a1a4Smaxv addl $4,%esp 1545c26a1a4Smaxv 1555c26a1a4Smaxv INTRFASTEXIT 15654b0c8d9SuebayasiIDTVEC_END(trap02) 15703b96c31Smaxv 15854b0c8d9SuebayasiIDTVEC(trap03) 1599614cf02Smaxv ZTRAP(T_BPTFLT) 16054b0c8d9SuebayasiIDTVEC_END(trap03) 16103b96c31Smaxv 16254b0c8d9SuebayasiIDTVEC(trap04) 16354b0c8d9Suebayasi ZTRAP(T_OFLOW) 16454b0c8d9SuebayasiIDTVEC_END(trap04) 16503b96c31Smaxv 16654b0c8d9SuebayasiIDTVEC(trap05) 16754b0c8d9Suebayasi ZTRAP(T_BOUND) 16854b0c8d9SuebayasiIDTVEC_END(trap05) 16903b96c31Smaxv 170e37071faSmaxv/* 171e37071faSmaxv * Privileged instruction fault. 172e37071faSmaxv */ 173e37071faSmaxv#ifdef KDTRACE_HOOKS 174e37071faSmaxv SUPERALIGN_TEXT 175e37071faSmaxvIDTVEC(trap06) 176e37071faSmaxv /* Check if there is no DTrace hook registered. */ 1774160377bSmaxv cmpl $0,%ss:dtrace_invop_jump_addr 178e37071faSmaxv je norm_ill 179e37071faSmaxv 180e37071faSmaxv /* Check if this is a user fault. */ 181e37071faSmaxv /* XXX this was 0x0020 in FreeBSD */ 182e37071faSmaxv cmpl $GSEL(GCODE_SEL, SEL_KPL),4(%esp) /* Check code segment. */ 183e37071faSmaxv 184e37071faSmaxv /* If so, just handle it as a normal trap. */ 185e37071faSmaxv jne norm_ill 186e37071faSmaxv 187e37071faSmaxv /* 188e37071faSmaxv * This is a kernel instruction fault that might have been caused 189e37071faSmaxv * by a DTrace provider. 190e37071faSmaxv */ 191e37071faSmaxv 192e37071faSmaxv /* 193e37071faSmaxv * Set our jump address for the jump back in the event that 194e37071faSmaxv * the exception wasn't caused by DTrace at all. 195e37071faSmaxv */ 196e37071faSmaxv movl $norm_ill,dtrace_invop_calltrap_addr 197e37071faSmaxv 198e37071faSmaxv /* Jump to the code hooked in by DTrace. */ 199e37071faSmaxv jmpl *dtrace_invop_jump_addr 200e37071faSmaxv 201e37071faSmaxv /* 202e37071faSmaxv * Process the instruction fault in the normal way. 203e37071faSmaxv */ 204e37071faSmaxvnorm_ill: 205e37071faSmaxv ZTRAP(T_PRIVINFLT) 206e37071faSmaxvIDTVEC_END(trap06) 207e37071faSmaxv#else 20854b0c8d9SuebayasiIDTVEC(trap06) 20954b0c8d9Suebayasi ZTRAP(T_PRIVINFLT) 21054b0c8d9SuebayasiIDTVEC_END(trap06) 211e37071faSmaxv#endif 21203b96c31Smaxv 21354b0c8d9SuebayasiIDTVEC(trap07) 21403b96c31Smaxv pushl $0 /* dummy error code */ 21554b0c8d9Suebayasi pushl $T_DNA 21654b0c8d9Suebayasi INTRENTRY 21754b0c8d9Suebayasi#ifdef DIAGNOSTIC 218*87531432Sknakahara movzbl CPUVAR(ILEVEL),%ebx 21954b0c8d9Suebayasi#endif 22027733cfeSdsl pushl %esp 221df71dee7Sdsl call _C_LABEL(fpudna) 22254b0c8d9Suebayasi addl $4,%esp 2234bc95673Smaxv jmp .Lalltraps_checkusr 22454b0c8d9SuebayasiIDTVEC_END(trap07) 22503b96c31Smaxv 22654b0c8d9SuebayasiIDTVEC(trap08) 22754b0c8d9Suebayasi TRAP(T_DOUBLEFLT) 22854b0c8d9SuebayasiIDTVEC_END(trap08) 22903b96c31Smaxv 23054b0c8d9SuebayasiIDTVEC(trap09) 23154b0c8d9Suebayasi ZTRAP(T_FPOPFLT) 23254b0c8d9SuebayasiIDTVEC_END(trap09) 23303b96c31Smaxv 23454b0c8d9SuebayasiIDTVEC(trap0a) 23554b0c8d9Suebayasi TRAP(T_TSSFLT) 23654b0c8d9SuebayasiIDTVEC_END(trap0a) 23703b96c31Smaxv 23854b0c8d9SuebayasiIDTVEC(trap0b) 23954b0c8d9Suebayasi TRAP(T_SEGNPFLT) 24054b0c8d9SuebayasiIDTVEC_END(trap0b) 24103b96c31Smaxv 24254b0c8d9SuebayasiIDTVEC(trap0c) 24354b0c8d9Suebayasi TRAP(T_STKFLT) 24454b0c8d9SuebayasiIDTVEC_END(trap0c) 24503b96c31Smaxv 24654b0c8d9SuebayasiIDTVEC(trap0d) 24754b0c8d9Suebayasi TRAP(T_PROTFLT) 24854b0c8d9SuebayasiIDTVEC_END(trap0d) 24903b96c31Smaxv 25054b0c8d9SuebayasiIDTVEC(trap0e) 251bf5abc14Scherry#ifndef XENPV 25254b0c8d9Suebayasi pushl $T_PAGEFLT 25354b0c8d9Suebayasi INTRENTRY 25454b0c8d9Suebayasi STI(%eax) 25554b0c8d9Suebayasi testb $PGEX_U,TF_ERR(%esp) 25654b0c8d9Suebayasi jnz calltrap 25754b0c8d9Suebayasi movl %cr2,%eax 25854b0c8d9Suebayasi subl _C_LABEL(pentium_idt),%eax 25954b0c8d9Suebayasi cmpl $(6*8),%eax 26054b0c8d9Suebayasi jne calltrap 26154b0c8d9Suebayasi movb $T_PRIVINFLT,TF_TRAPNO(%esp) 26254b0c8d9Suebayasi jmp calltrap 26303b96c31Smaxv#else 26454b0c8d9Suebayasi TRAP(T_PAGEFLT) 26503b96c31Smaxv#endif 26654b0c8d9SuebayasiIDTVEC_END(trap0e) 26754b0c8d9Suebayasi 26854b0c8d9SuebayasiIDTVEC(intrspurious) 26954b0c8d9SuebayasiIDTVEC(trap0f) 27054b0c8d9Suebayasi /* 27154b0c8d9Suebayasi * The Pentium Pro local APIC may erroneously call this vector for a 27254b0c8d9Suebayasi * default IR7. Just ignore it. 27354b0c8d9Suebayasi * 27454b0c8d9Suebayasi * (The local APIC does this when CPL is raised while it's on the 27554b0c8d9Suebayasi * way to delivering an interrupt.. presumably enough has been set 27654b0c8d9Suebayasi * up that it's inconvenient to abort delivery completely..) 27754b0c8d9Suebayasi */ 27803b96c31Smaxv pushl $0 /* dummy error code */ 27954b0c8d9Suebayasi pushl $T_ASTFLT 28054b0c8d9Suebayasi INTRENTRY 28154b0c8d9Suebayasi STI(%eax) 28254b0c8d9Suebayasi#ifdef DIAGNOSTIC 283*87531432Sknakahara movzbl CPUVAR(ILEVEL),%ebx 28454b0c8d9Suebayasi#endif 2854bc95673Smaxv jmp .Lalltraps_checkusr 28654b0c8d9SuebayasiIDTVEC_END(trap0f) 28754b0c8d9SuebayasiIDTVEC_END(intrspurious) 28854b0c8d9Suebayasi 28954b0c8d9SuebayasiIDTVEC(trap10) 29054b0c8d9Suebayasi /* 29154b0c8d9Suebayasi * Handle like an interrupt so that we can call npxintr to clear the 29254b0c8d9Suebayasi * error. It would be better to handle npx interrupts as traps but 29354b0c8d9Suebayasi * this is difficult for nested interrupts. 29454b0c8d9Suebayasi */ 29503b96c31Smaxv pushl $0 /* dummy error code */ 29627733cfeSdsl pushl $T_ARITHTRAP 29727733cfeSdsl.Ldo_fputrap: 29854b0c8d9Suebayasi INTRENTRY 299*87531432Sknakahara movzbl CPUVAR(ILEVEL),%ebx 30054b0c8d9Suebayasi pushl %esp 30103b96c31Smaxv addl $1,CPUVAR(NTRAP) /* statistical info */ 30254b0c8d9Suebayasi adcl $0,CPUVAR(NTRAP)+4 30327733cfeSdsl call _C_LABEL(fputrap) 30427733cfeSdsl addl $4,%esp 3054bc95673Smaxv jmp .Lalltraps_checkusr 30654b0c8d9SuebayasiIDTVEC_END(trap10) 30703b96c31Smaxv 30854b0c8d9SuebayasiIDTVEC(trap11) 30954b0c8d9Suebayasi TRAP(T_ALIGNFLT) 31054b0c8d9SuebayasiIDTVEC_END(trap11) 31127733cfeSdsl 31254b0c8d9SuebayasiIDTVEC(trap12) 31354b0c8d9Suebayasi ZTRAP(T_MCA) 31427733cfeSdslIDTVEC_END(trap12) 31503b96c31Smaxv 31654b0c8d9SuebayasiIDTVEC(trap13) 31703b96c31Smaxv pushl $0 /* dummy error code */ 31827733cfeSdsl pushl $T_XMM 31927733cfeSdsl jmp .Ldo_fputrap 32027733cfeSdslIDTVEC_END(trap13) 32127733cfeSdsl 32254b0c8d9SuebayasiIDTVEC(trap14) 32354b0c8d9SuebayasiIDTVEC(trap15) 32454b0c8d9SuebayasiIDTVEC(trap16) 32554b0c8d9SuebayasiIDTVEC(trap17) 32654b0c8d9SuebayasiIDTVEC(trap18) 32754b0c8d9SuebayasiIDTVEC(trap19) 32854b0c8d9SuebayasiIDTVEC(trap1a) 32954b0c8d9SuebayasiIDTVEC(trap1b) 33054b0c8d9SuebayasiIDTVEC(trap1c) 33154b0c8d9SuebayasiIDTVEC(trap1d) 33254b0c8d9SuebayasiIDTVEC(trap1e) 33354b0c8d9SuebayasiIDTVEC(trap1f) 33454b0c8d9Suebayasi /* 20 - 31 reserved for future exp */ 33554b0c8d9Suebayasi ZTRAP(T_RESERVED) 33654b0c8d9SuebayasiIDTVEC_END(trap1f) 33754b0c8d9SuebayasiIDTVEC_END(trap1e) 33854b0c8d9SuebayasiIDTVEC_END(trap1d) 33954b0c8d9SuebayasiIDTVEC_END(trap1c) 34054b0c8d9SuebayasiIDTVEC_END(trap1b) 34154b0c8d9SuebayasiIDTVEC_END(trap1a) 34254b0c8d9SuebayasiIDTVEC_END(trap19) 34354b0c8d9SuebayasiIDTVEC_END(trap18) 34454b0c8d9SuebayasiIDTVEC_END(trap17) 34554b0c8d9SuebayasiIDTVEC_END(trap16) 34654b0c8d9SuebayasiIDTVEC_END(trap15) 34754b0c8d9SuebayasiIDTVEC_END(trap14) 34854b0c8d9SuebayasiIDTVEC_END(trap13) 34954b0c8d9SuebayasiIDTVEC_END(trap12) 35054b0c8d9SuebayasiIDTVEC_END(trap11) 35154b0c8d9Suebayasi 35254b0c8d9SuebayasiIDTVEC(exceptions) 35354b0c8d9Suebayasi .long _C_LABEL(Xtrap00), _C_LABEL(Xtrap01) 35454b0c8d9Suebayasi .long _C_LABEL(Xtrap02), _C_LABEL(Xtrap03) 35554b0c8d9Suebayasi .long _C_LABEL(Xtrap04), _C_LABEL(Xtrap05) 35654b0c8d9Suebayasi .long _C_LABEL(Xtrap06), _C_LABEL(Xtrap07) 35754b0c8d9Suebayasi .long _C_LABEL(Xtrap08), _C_LABEL(Xtrap09) 35854b0c8d9Suebayasi .long _C_LABEL(Xtrap0a), _C_LABEL(Xtrap0b) 35954b0c8d9Suebayasi .long _C_LABEL(Xtrap0c), _C_LABEL(Xtrap0d) 36054b0c8d9Suebayasi .long _C_LABEL(Xtrap0e), _C_LABEL(Xtrap0f) 36154b0c8d9Suebayasi .long _C_LABEL(Xtrap10), _C_LABEL(Xtrap11) 36254b0c8d9Suebayasi .long _C_LABEL(Xtrap12), _C_LABEL(Xtrap13) 36354b0c8d9Suebayasi .long _C_LABEL(Xtrap14), _C_LABEL(Xtrap15) 36454b0c8d9Suebayasi .long _C_LABEL(Xtrap16), _C_LABEL(Xtrap17) 36554b0c8d9Suebayasi .long _C_LABEL(Xtrap18), _C_LABEL(Xtrap19) 36654b0c8d9Suebayasi .long _C_LABEL(Xtrap1a), _C_LABEL(Xtrap1b) 36754b0c8d9Suebayasi .long _C_LABEL(Xtrap1c), _C_LABEL(Xtrap1d) 36854b0c8d9Suebayasi .long _C_LABEL(Xtrap1e), _C_LABEL(Xtrap1f) 36954b0c8d9SuebayasiIDTVEC_END(exceptions) 37054b0c8d9Suebayasi 37154b0c8d9Suebayasi 37254b0c8d9SuebayasiIDTVEC(tss_trap08) 37354b0c8d9Suebayasi1: 37454b0c8d9Suebayasi str %ax 37554b0c8d9Suebayasi GET_TSS 37654b0c8d9Suebayasi movzwl (%eax),%eax 37754b0c8d9Suebayasi GET_TSS 37854b0c8d9Suebayasi pushl $T_DOUBLEFLT 37954b0c8d9Suebayasi pushl %eax 38054b0c8d9Suebayasi call _C_LABEL(trap_tss) 38154b0c8d9Suebayasi addl $12,%esp 38254b0c8d9Suebayasi iret 38354b0c8d9Suebayasi jmp 1b 38454b0c8d9SuebayasiIDTVEC_END(tss_trap08) 38554b0c8d9Suebayasi 38654b0c8d9Suebayasi/* 38754b0c8d9Suebayasi * trap() calls here when it detects a fault in INTRFASTEXIT (loading the 38854b0c8d9Suebayasi * segment registers or during the iret itself). 38954b0c8d9Suebayasi * The address of the (possibly reconstructed) user trap frame is 39054b0c8d9Suebayasi * passed as an argument. 39154b0c8d9Suebayasi * Typically the code will have raised a SIGSEGV which will be actioned 39254b0c8d9Suebayasi * by the code below. 39354b0c8d9Suebayasi */ 39454b0c8d9Suebayasi .type _C_LABEL(trap_return_fault_return),@function 39554b0c8d9SuebayasiLABEL(trap_return_fault_return) 39654b0c8d9Suebayasi mov 4(%esp),%esp /* frame for user return */ 3974bc95673Smaxv jmp .Lalltraps_checkusr 39854b0c8d9SuebayasiEND(trap_return_fault_return) 39954b0c8d9Suebayasi 40054b0c8d9Suebayasi/* LINTSTUB: Ignore */ 4010c52a5deSmaxvENTRY(alltraps) 40254b0c8d9Suebayasi INTRENTRY 40354b0c8d9Suebayasi STI(%eax) 4044bc95673Smaxv 40554b0c8d9Suebayasicalltrap: 40654b0c8d9Suebayasi#ifdef DIAGNOSTIC 407*87531432Sknakahara movzbl CPUVAR(ILEVEL),%ebx 40803b96c31Smaxv#endif 40903b96c31Smaxv addl $1,CPUVAR(NTRAP) /* statistical info */ 41054b0c8d9Suebayasi adcl $0,CPUVAR(NTRAP)+4 41154b0c8d9Suebayasi pushl %esp 41254b0c8d9Suebayasi call _C_LABEL(trap) 41354b0c8d9Suebayasi addl $4,%esp 4144bc95673Smaxv 4154bc95673Smaxv.Lalltraps_checkusr: 41654b0c8d9Suebayasi testb $CHK_UPL,TF_CS(%esp) 41754b0c8d9Suebayasi jnz .Lalltraps_checkast 41854b0c8d9Suebayasi jmp 6f 4194bc95673Smaxv 42054b0c8d9Suebayasi.Lalltraps_checkast: 42154b0c8d9Suebayasi /* Check for ASTs on exit to user mode. */ 42254b0c8d9Suebayasi CLI(%eax) 42354b0c8d9Suebayasi CHECK_ASTPENDING(%eax) 42454b0c8d9Suebayasi jz 3f 4254bc95673Smaxv CLEAR_ASTPENDING(%eax) 42654b0c8d9Suebayasi STI(%eax) 42754b0c8d9Suebayasi movl $T_ASTFLT,TF_TRAPNO(%esp) 42803b96c31Smaxv addl $1,CPUVAR(NTRAP) /* statistical info */ 42954b0c8d9Suebayasi adcl $0,CPUVAR(NTRAP)+4 43054b0c8d9Suebayasi pushl %esp 43154b0c8d9Suebayasi call _C_LABEL(trap) 43254b0c8d9Suebayasi addl $4,%esp 43354b0c8d9Suebayasi jmp .Lalltraps_checkast /* re-check ASTs */ 43454b0c8d9Suebayasi3: CHECK_DEFERRED_SWITCH 43554b0c8d9Suebayasi jnz 9f 4364bc95673Smaxv 4377bc14623Sbouyer HANDLE_DEFERRED_FPU 4387bc14623Sbouyer 43922e594a0Sbouyer#ifdef XENPV 44054b0c8d9Suebayasi STIC(%eax) 44184e0feffSmaxv jz 22f 44254b0c8d9Suebayasi call _C_LABEL(stipending) 44354b0c8d9Suebayasi testl %eax,%eax 44484e0feffSmaxv jz 22f 44554b0c8d9Suebayasi /* process pending interrupts */ 44654b0c8d9Suebayasi CLI(%eax) 447*87531432Sknakahara movzbl CPUVAR(ILEVEL),%ebx 44803b96c31Smaxv movl $.Lalltraps_resume,%esi /* address to resume loop at */ 44954b0c8d9Suebayasi.Lalltraps_resume: 45003b96c31Smaxv movl %ebx,%eax /* get cpl */ 45122e594a0Sbouyer movl CPUVAR(IUNMASK)(,%eax,4),%eax 45222e594a0Sbouyer andl CPUVAR(IPENDING),%eax /* any non-masked bits left? */ 45384e0feffSmaxv jz 11f 45454b0c8d9Suebayasi bsrl %eax,%eax 45522e594a0Sbouyer btrl %eax,CPUVAR(IPENDING) 45622e594a0Sbouyer movl CPUVAR(ISOURCES)(,%eax,4),%eax 45754b0c8d9Suebayasi jmp *IS_RESUME(%eax) 458*87531432Sknakahara11: movb %bl,CPUVAR(ILEVEL) /* restore cpl */ 4594bc95673Smaxv jmp .Lalltraps_checkusr 46084e0feffSmaxv22: 46122e594a0Sbouyer#endif /* XEN */ 4624bc95673Smaxv 4634bc95673Smaxv6: 4644bc95673Smaxv#ifdef DIAGNOSTIC 465*87531432Sknakahara cmpb CPUVAR(ILEVEL),%bl 4664bc95673Smaxv jne .Lspl_error 4674bc95673Smaxv#endif 46854b0c8d9Suebayasi INTRFASTEXIT 4694bc95673Smaxv 4704bc95673Smaxv9: STI(%eax) 4714bc95673Smaxv call _C_LABEL(pmap_load) 4724bc95673Smaxv jmp .Lalltraps_checkast /* re-check ASTs */ 4734bc95673Smaxv 4744bc95673Smaxv#ifdef DIAGNOSTIC 4754bc95673Smaxv.Lspl_error: 4764bc95673Smaxv STI(%eax) 47754b0c8d9Suebayasi pushl $4f 47854b0c8d9Suebayasi call _C_LABEL(panic) 47954b0c8d9Suebayasi addl $4,%esp 48054b0c8d9Suebayasi pushl %ebx 48154b0c8d9Suebayasi call _C_LABEL(spllower) 48254b0c8d9Suebayasi addl $4,%esp 48354b0c8d9Suebayasi jmp .Lalltraps_checkast /* re-check ASTs */ 48454b0c8d9Suebayasi4: .asciz "SPL NOT LOWERED ON TRAP EXIT\n" 4854bc95673Smaxv#endif 48654b0c8d9SuebayasiEND(alltraps) 487