1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/*
** Copyright (c) 1996
** Michael Smith. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
**
** THIS SOFTWARE IS PROVIDED BY Michael Smith ``AS IS'' AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL Michael Smith BE LIABLE
** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
** SUCH DAMAGE.
**
** $FreeBSD$
*/
/******************************************************************************
** Abstractions to hide register access methods across different platforms.
**
*/
#ifndef _MACHINE_VM86_H_
/* standard register representation */
typedef union
{
u_long r_ex;
struct
{
u_short r_x;
u_short :16;
} r_w;
struct
{
u_char r_l;
u_char r_h;
u_short :16;
} r_b;
} reg86_t;
#endif
#ifdef __FreeBSD__
/* layout must match definition of struct sigcontext in <machine/signal.h> */
typedef struct
{
int onstack;
reg86_t gs;
reg86_t fs;
reg86_t es;
reg86_t ds;
reg86_t edi;
reg86_t esi;
reg86_t ebp;
reg86_t isp;
reg86_t ebx;
reg86_t edx;
reg86_t ecx;
reg86_t eax;
int pad[2];
reg86_t eip;
reg86_t cs;
reg86_t efl;
reg86_t esp;
reg86_t ss;
} registers_t;
typedef union
{
mcontext_t sc;
registers_t r;
} regcontext_t;
/*
** passed around as a reference to the registers. This must be in
** scope for the following register macros to work.
*/
/* register shorthands */
#define R_ESP (REGS->r.esp.r_ex)
#define R_SP (REGS->r.esp.r_w.r_x)
#define R_EBP (REGS->r.ebp.r_ex)
#define R_BP (REGS->r.ebp.r_w.r_x)
#define R_ISP (REGS->r.isp.r_ex)
#define R_EIP (REGS->r.eip.r_ex)
#define R_IP (REGS->r.eip.r_w.r_x)
#define R_EFLAGS (REGS->r.efl.r_ex)
#define R_FLAGS (REGS->r.efl.r_w.r_x)
#define R_EES (REGS->r.es.r_ex)
#define R_ES (REGS->r.es.r_w.r_x)
#define R_EDS (REGS->r.ds.r_ex)
#define R_DS (REGS->r.ds.r_w.r_x)
#define R_ECS (REGS->r.cs.r_ex)
#define R_CS (REGS->r.cs.r_w.r_x)
#define R_ESS (REGS->r.ss.r_ex)
#define R_SS (REGS->r.ss.r_w.r_x)
#define R_EDI (REGS->r.edi.r_ex)
#define R_DI (REGS->r.edi.r_w.r_x)
#define R_ESI (REGS->r.esi.r_ex)
#define R_SI (REGS->r.esi.r_w.r_x)
#define R_EBX (REGS->r.ebx.r_ex)
#define R_BX (REGS->r.ebx.r_w.r_x)
#define R_BL (REGS->r.ebx.r_b.r_l)
#define R_BH (REGS->r.ebx.r_b.r_h)
#define R_EDX (REGS->r.edx.r_ex)
#define R_DX (REGS->r.edx.r_w.r_x)
#define R_DL (REGS->r.edx.r_b.r_l)
#define R_DH (REGS->r.edx.r_b.r_h)
#define R_ECX (REGS->r.ecx.r_ex)
#define R_CX (REGS->r.ecx.r_w.r_x)
#define R_CL (REGS->r.ecx.r_b.r_l)
#define R_CH (REGS->r.ecx.r_b.r_h)
#define R_EAX (REGS->r.eax.r_ex)
#define R_AX (REGS->r.eax.r_w.r_x)
#define R_AL (REGS->r.eax.r_b.r_l)
#define R_AH (REGS->r.eax.r_b.r_h)
#define R_EGS (REGS->r.gs.r_ex)
#define R_GS (REGS->r.gs.r_w.r_x)
#define R_EFS (REGS->r.fs.r_ex)
#define R_FS (REGS->r.fs.r_w.r_x)
#endif
#ifdef __bsdi__
#endif
#ifdef __NetBSD__
#endif
/*
** register manipulation macros
*/
#define PUTVEC(s, o, x) ((s) = ((x) >> 16), (o) = (x) & 0xffff)
#define MAKEVEC(s, o) (((s) << 16) + (o))
#define PUTPTR(s, o, x) (((s) = ((x) & 0xf0000) >> 4), (o) = (x) & 0xffff)
#define MAKEPTR(s, o) (((s) << 4) + (o))
#define VECPTR(x) MAKEPTR((x) >> 16, (x) & 0xffff)
#define REGISTERS regcontext_t *REGS
inline static void
PUSH(u_short x, REGISTERS)
{
R_SP -= 2;
*(u_short *)MAKEPTR(R_SS, R_SP) = (x);
}
inline static u_short
POP(REGISTERS)
{
u_short x;
x = *(u_short *)MAKEPTR(R_SS, R_SP);
R_SP += 2;
return(x);
}
# ifndef PSL_ALLCC /* Grr, FreeBSD doesn't have this */
# define PSL_ALLCC (PSL_C|PSL_PF|PSL_AF|PSL_Z|PSL_N)
# endif
|