amd64 port: mainly on the pmap headers, identify_cpu and initcpu
[dragonfly/port-amd64.git] / sys / platform / pc64 / amd64 / exception.c
blobf4b34cd31727d8ee8bb1eb01aff6f79a5a74e06d
2 /*
3 * Copyright (c) 2006 The DragonFly Project. All rights reserved.
4 *
5 * This code is derived from software contributed to The DragonFly Project
6 * by Matthew Dillon <dillon@backplane.com>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
35 * $DragonFly: src/sys/platform/pc64/amd64/exception.c,v 1.2 2007/09/24 03:24:45 yanyh Exp $
38 #include "opt_ddb.h"
39 #include <sys/types.h>
40 #include <sys/systm.h>
41 #include <sys/reboot.h>
42 #include <sys/kernel.h>
43 #include <sys/kthread.h>
44 #include <sys/reboot.h>
45 #include <sys/signal.h>
46 #include <ddb/ddb.h>
48 #include <sys/thread2.h>
50 #include <machine/trap.h>
51 #include <machine/md_var.h>
52 #include <machine/segments.h>
53 #include <machine/cpu.h>
55 int _ucodesel = LSEL(LUCODE_SEL, SEL_UPL);
56 int _udatasel = LSEL(LUDATA_SEL, SEL_UPL);
58 static void exc_segfault(int signo, siginfo_t *info, void *ctx);
59 #ifdef DDB
60 static void exc_debugger(int signo, siginfo_t *info, void *ctx);
61 #endif
64 * IPIs are 'fast' interrupts, so we deal with them directly from our
65 * signal handler.
68 #ifdef SMP
70 static
71 void
72 ipisig(int nada, siginfo_t *info, void *ctxp)
74 ++mycpu->gd_intr_nesting_level;
75 if (curthread->td_pri < TDPRI_CRIT) {
76 curthread->td_pri += TDPRI_CRIT;
77 lwkt_process_ipiq();
78 curthread->td_pri -= TDPRI_CRIT;
79 } else {
80 need_ipiq();
82 --mycpu->gd_intr_nesting_level;
85 #endif
87 void
88 init_exceptions(void)
93 * This function handles a segmentation fault.
95 * XXX We assume that trapframe is a subset of ucontext. It is as of
96 * this writing.
98 static void
99 exc_segfault(int signo, siginfo_t *info, void *ctxp)
101 ucontext_t *ctx = ctxp;
103 #if 0
104 kprintf("CAUGHT SEGFAULT EIP %08x ERR %08x TRAPNO %d err %d\n",
105 ctx->uc_mcontext.mc_eip,
106 ctx->uc_mcontext.mc_err,
107 ctx->uc_mcontext.mc_trapno & 0xFFFF,
108 ctx->uc_mcontext.mc_trapno >> 16);
109 kern_trap((struct trapframe *)&ctx->uc_mcontext.mc_gs);
110 #endif
111 splz();
114 #ifdef DDB
116 static void
117 exc_debugger(int signo, siginfo_t *info, void *ctx)
119 Debugger("interrupt from console");
122 #endif