mcontext.h revision 1.9.6.1 1 /* $NetBSD: mcontext.h,v 1.9.6.1 2008/06/02 13:21:49 mjf Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Klaus Klein.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _AMD64_MCONTEXT_H_
33 #define _AMD64_MCONTEXT_H_
34
35 #include <machine/frame_regs.h>
36
37 /*
38 * General register state
39 */
40 #define GREG_OFFSETS(reg, REG, idx) _REG_##REG = idx,
41 enum { _FRAME_GREG(GREG_OFFSETS) _NGREG = 26 };
42 #undef GREG_OFFSETS
43
44 typedef unsigned long __greg_t;
45 typedef __greg_t __gregset_t[_NGREG];
46
47 /* These names are for compatibility */
48 #define _REG_URSP _REG_RSP
49 #define _REG_RFL _REG_RFLAGS
50
51 /*
52 * Floating point register state
53 */
54 typedef char __fpregset_t[512];
55
56 /*
57 * The padding below is to make __fpregs have a 16-byte aligned offset
58 * within ucontext_t.
59 */
60
61 typedef struct {
62 __gregset_t __gregs;
63 long __pad;
64 __fpregset_t __fpregs;
65 } mcontext_t;
66
67 #define _UC_UCONTEXT_ALIGN (~0xf)
68
69 #define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_RSP] - 128)
70 #define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_RIP])
71 #define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_RAX])
72
73 #define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc)
74
75 /*
76 * mcontext extensions to handle signal delivery.
77 */
78 #define _UC_SETSTACK 0x00010000
79 #define _UC_CLRSTACK 0x00020000
80
81
82 #ifdef _KERNEL
83
84 /*
85 * 32bit context definitions.
86 */
87
88 #define _NGREG32 19
89 typedef unsigned int __greg32_t;
90 typedef __greg32_t __gregset32_t[_NGREG32];
91
92 #define _REG32_GS 0
93 #define _REG32_FS 1
94 #define _REG32_ES 2
95 #define _REG32_DS 3
96 #define _REG32_EDI 4
97 #define _REG32_ESI 5
98 #define _REG32_EBP 6
99 #define _REG32_ESP 7
100 #define _REG32_EBX 8
101 #define _REG32_EDX 9
102 #define _REG32_ECX 10
103 #define _REG32_EAX 11
104 #define _REG32_TRAPNO 12
105 #define _REG32_ERR 13
106 #define _REG32_EIP 14
107 #define _REG32_CS 15
108 #define _REG32_EFL 16
109 #define _REG32_UESP 17
110 #define _REG32_SS 18
111
112 #define _UC_MACHINE32_SP(uc) ((uc)->uc_mcontext.__gregs[_REG32_UESP])
113
114 /*
115 * Floating point register state
116 */
117 typedef struct fxsave64 __fpregset32_t;
118
119 typedef struct {
120 __gregset32_t __gregs;
121 __fpregset32_t __fpregs;
122 } mcontext32_t;
123
124 #define _UC_MACHINE_PAD32 5
125
126 struct trapframe;
127 struct lwp;
128 int check_mcontext(struct lwp *, const mcontext_t *, struct trapframe *);
129
130 #endif /* _KERNEL */
131
132 #endif /* !_AMD64_MCONTEXT_H_ */
133