1 /* $NetBSD: vm86.h,v 1.19 2009/11/21 03:11:01 rmind Exp $ */
6 * Copyright (c) 1996 The NetBSD Foundation, Inc.
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by John T. Kohl and Charles M. Hannum.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 #define SETFLAGS(targ, new, newmask) (targ) = ((targ) & ~(newmask)) | ((new) & (newmask))
36 #define VM86_TYPE(x) ((x) & 0xff)
37 #define VM86_ARG(x) (((x) & 0xff00) >> 8)
38 #define VM86_MAKEVAL(type,arg) ((type) | (((arg) & 0xff) << 8))
42 #define VM86_UNKNOWN 3
44 #define VM86_REALFLAGS (~PSL_USERSTATIC)
45 #define VM86_VIRTFLAGS (PSL_USERSTATIC & ~(PSL_MBO | PSL_MBZ))
47 struct vm86_kern
{ /* kernel uses this stuff */
49 unsigned long ss_cpu_type
;
51 #define cpu_type substr.ss_cpu_type
54 * Kernel keeps copy of user-mode address of this, but doesn't copy it in.
57 struct vm86_kern substr
;
58 unsigned long screen_bitmap
; /* not used/supported (yet) */
59 unsigned long flags
; /* not used/supported (yet) */
60 unsigned char int_byuser
[32]; /* 256 bits each: pass control to user */
61 unsigned char int21_byuser
[32]; /* otherwise, handle directly */
72 int x86_vm86(struct lwp
*, char *, register_t
*);
73 int compat_16_x86_vm86(struct lwp
*, char *, register_t
*);
74 void vm86_gpfault(struct lwp
*, int);
75 void vm86_return(struct lwp
*, int);
76 static __inline
void clr_vif(struct lwp
*);
77 static __inline
void set_vif(struct lwp
*);
78 static __inline
void set_vflags(struct lwp
*, int);
79 static __inline
int get_vflags(struct lwp
*);
80 static __inline
void set_vflags_short(struct lwp
*, int);
81 static __inline
int get_vflags_short(struct lwp
*);
84 clr_vif(struct lwp
*l
)
86 struct pcb
*pcb
= lwp_getpcb(l
);
89 pcb
->vm86_eflags
&= ~PSL_I
;
91 pcb
->vm86_eflags
&= ~PSL_VIF
;
96 set_vif(struct lwp
*l
)
98 struct pcb
*pcb
= lwp_getpcb(l
);
101 pcb
->vm86_eflags
|= PSL_I
;
102 if ((pcb
->vm86_eflags
& (PSL_I
|PSL_VIP
)) == (PSL_I
|PSL_VIP
))
104 pcb
->vm86_eflags
|= PSL_VIF
;
105 if ((pcb
->vm86_eflags
& (PSL_VIF
|PSL_VIP
)) == (PSL_VIF
|PSL_VIP
))
107 vm86_return(l
, VM86_STI
);
111 set_vflags(struct lwp
*l
, int flags
)
113 struct trapframe
*tf
= l
->l_md
.md_regs
;
114 struct pcb
*pcb
= lwp_getpcb(l
);
116 flags
&= ~pcb
->vm86_flagmask
;
117 SETFLAGS(pcb
->vm86_eflags
, flags
, VM86_VIRTFLAGS
);
118 SETFLAGS(tf
->tf_eflags
, flags
, VM86_REALFLAGS
);
120 if ((pcb
->vm86_eflags
& (PSL_I
|PSL_VIP
)) == (PSL_I
|PSL_VIP
))
122 if ((pcb
->vm86_eflags
& (PSL_VIF
|PSL_VIP
)) == (PSL_VIF
|PSL_VIP
))
124 vm86_return(l
, VM86_STI
);
128 get_vflags(struct lwp
*l
)
130 struct trapframe
*tf
= l
->l_md
.md_regs
;
131 struct pcb
*pcb
= lwp_getpcb(l
);
134 SETFLAGS(flags
, pcb
->vm86_eflags
, VM86_VIRTFLAGS
);
135 SETFLAGS(flags
, tf
->tf_eflags
, VM86_REALFLAGS
);
140 set_vflags_short(struct lwp
*l
, int flags
)
142 struct trapframe
*tf
= l
->l_md
.md_regs
;
143 struct pcb
*pcb
= lwp_getpcb(l
);
145 flags
&= ~pcb
->vm86_flagmask
;
146 SETFLAGS(pcb
->vm86_eflags
, flags
, VM86_VIRTFLAGS
& 0xffff);
147 SETFLAGS(tf
->tf_eflags
, flags
, VM86_REALFLAGS
& 0xffff);
149 if ((pcb
->vm86_eflags
& (PSL_I
|PSL_VIP
)) == (PSL_I
|PSL_VIP
))
150 vm86_return(l
, VM86_STI
);
155 get_vflags_short(struct lwp
*l
)
157 struct trapframe
*tf
= l
->l_md
.md_regs
;
158 struct pcb
*pcb
= lwp_getpcb(l
);
161 SETFLAGS(flags
, pcb
->vm86_eflags
, VM86_VIRTFLAGS
& 0xffff);
162 SETFLAGS(flags
, tf
->tf_eflags
, VM86_REALFLAGS
& 0xffff);
166 int i386_vm86(struct vm86_struct
*vmcp
);