Deleted Added
full compact
ia32_signal.c (102808) ia32_signal.c (115084)
1/*-
2 * Copyright (c) 2002 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2002 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/ia64/ia32/ia32_signal.c 102808 2002-09-01 21:41:24Z jake $
26 * $FreeBSD: head/sys/ia64/ia32/ia32_signal.c 115084 2003-05-16 21:26:42Z marcel $
27 */
28
29#define __ELF_WORD_SIZE 32
30
31#include <sys/param.h>
32#include <sys/exec.h>
33#include <sys/fcntl.h>
34#include <sys/imgact.h>
35#include <sys/kernel.h>
36#include <sys/lock.h>
37#include <sys/malloc.h>
38#include <sys/mutex.h>
39#include <sys/mman.h>
40#include <sys/namei.h>
41#include <sys/pioctl.h>
42#include <sys/proc.h>
43#include <sys/procfs.h>
44#include <sys/resourcevar.h>
45#include <sys/systm.h>
46#include <sys/signalvar.h>
47#include <sys/stat.h>
48#include <sys/sx.h>
49#include <sys/syscall.h>
50#include <sys/sysctl.h>
51#include <sys/sysent.h>
52#include <sys/vnode.h>
53#include <sys/imgact_elf.h>
54
27 */
28
29#define __ELF_WORD_SIZE 32
30
31#include <sys/param.h>
32#include <sys/exec.h>
33#include <sys/fcntl.h>
34#include <sys/imgact.h>
35#include <sys/kernel.h>
36#include <sys/lock.h>
37#include <sys/malloc.h>
38#include <sys/mutex.h>
39#include <sys/mman.h>
40#include <sys/namei.h>
41#include <sys/pioctl.h>
42#include <sys/proc.h>
43#include <sys/procfs.h>
44#include <sys/resourcevar.h>
45#include <sys/systm.h>
46#include <sys/signalvar.h>
47#include <sys/stat.h>
48#include <sys/sx.h>
49#include <sys/syscall.h>
50#include <sys/sysctl.h>
51#include <sys/sysent.h>
52#include <sys/vnode.h>
53#include <sys/imgact_elf.h>
54
55#include <machine/frame.h>
56#include <machine/md_var.h>
57#include <machine/pcb.h>
58
55#include <vm/vm.h>
56#include <vm/vm_kern.h>
57#include <vm/vm_param.h>
58#include <vm/pmap.h>
59#include <vm/vm_map.h>
60#include <vm/vm_object.h>
61#include <vm/vm_extern.h>
62
63#include <ia64/ia32/ia32_util.h>
64#include <i386/include/psl.h>
65#include <i386/include/segments.h>
66#include <i386/include/specialreg.h>
59#include <vm/vm.h>
60#include <vm/vm_kern.h>
61#include <vm/vm_param.h>
62#include <vm/pmap.h>
63#include <vm/vm_map.h>
64#include <vm/vm_object.h>
65#include <vm/vm_extern.h>
66
67#include <ia64/ia32/ia32_util.h>
68#include <i386/include/psl.h>
69#include <i386/include/segments.h>
70#include <i386/include/specialreg.h>
67#include <machine/frame.h>
68#include <machine/md_var.h>
69
70static register_t *ia32_copyout_strings(struct image_params *imgp);
71static void ia32_setregs(struct thread *td, u_long entry, u_long stack,
72 u_long ps_strings);
73
74extern struct sysent ia32_sysent[];
75
76static char ia32_sigcode[] = {
77 0xff, 0x54, 0x24, 0x10, /* call *SIGF_HANDLER(%esp) */
78 0x8d, 0x44, 0x24, 0x14, /* lea SIGF_UC(%esp),%eax */
79 0x50, /* pushl %eax */
80 0xf7, 0x40, 0x54, 0x00, 0x00, 0x02, 0x02, /* testl $PSL_VM,UC_EFLAGS(%eax) */
81 0x75, 0x03, /* jne 9f */
82 0x8e, 0x68, 0x14, /* movl UC_GS(%eax),%gs */
83 0xb8, 0x57, 0x01, 0x00, 0x00, /* 9: movl $SYS_sigreturn,%eax */
84 0x50, /* pushl %eax */
85 0xcd, 0x80, /* int $0x80 */
86 0xeb, 0xfe, /* 0: jmp 0b */
71
72static register_t *ia32_copyout_strings(struct image_params *imgp);
73static void ia32_setregs(struct thread *td, u_long entry, u_long stack,
74 u_long ps_strings);
75
76extern struct sysent ia32_sysent[];
77
78static char ia32_sigcode[] = {
79 0xff, 0x54, 0x24, 0x10, /* call *SIGF_HANDLER(%esp) */
80 0x8d, 0x44, 0x24, 0x14, /* lea SIGF_UC(%esp),%eax */
81 0x50, /* pushl %eax */
82 0xf7, 0x40, 0x54, 0x00, 0x00, 0x02, 0x02, /* testl $PSL_VM,UC_EFLAGS(%eax) */
83 0x75, 0x03, /* jne 9f */
84 0x8e, 0x68, 0x14, /* movl UC_GS(%eax),%gs */
85 0xb8, 0x57, 0x01, 0x00, 0x00, /* 9: movl $SYS_sigreturn,%eax */
86 0x50, /* pushl %eax */
87 0xcd, 0x80, /* int $0x80 */
88 0xeb, 0xfe, /* 0: jmp 0b */
87 0, 0, 0, 0
89 0
88};
90};
89static int ia32_szsigcode = sizeof(ia32_sigcode) & ~3;
91static int ia32_szsigcode = sizeof(ia32_sigcode);
90
91struct sysentvec ia32_freebsd_sysvec = {
92 SYS_MAXSYSCALL,
93 ia32_sysent,
94 0,
95 0,
96 NULL,
97 0,
98 NULL,
99 NULL,
100 elf32_freebsd_fixup,
101 sendsig,
102 ia32_sigcode,
103 &ia32_szsigcode,
104 NULL,
105 "FreeBSD ELF",
106 elf32_coredump,
107 NULL,
92
93struct sysentvec ia32_freebsd_sysvec = {
94 SYS_MAXSYSCALL,
95 ia32_sysent,
96 0,
97 0,
98 NULL,
99 0,
100 NULL,
101 NULL,
102 elf32_freebsd_fixup,
103 sendsig,
104 ia32_sigcode,
105 &ia32_szsigcode,
106 NULL,
107 "FreeBSD ELF",
108 elf32_coredump,
109 NULL,
108 MINSIGSTKSZ,
109 4096,
110 IA32_MINSIGSTKSZ,
111 IA32_PAGE_SIZE,
110 0,
111 IA32_USRSTACK,
112 IA32_USRSTACK,
113 IA32_PS_STRINGS,
114 VM_PROT_ALL,
115 ia32_copyout_strings,
116 ia32_setregs
117};
118
119static Elf32_Brandinfo ia32_brand_info = {
120 ELFOSABI_FREEBSD,
121 EM_386,
122 "FreeBSD",
123 "/compat/ia32",
124 "/usr/libexec/ld-elf.so.1",
125 &ia32_freebsd_sysvec
126 };
127
128SYSINIT(ia32, SI_SUB_EXEC, SI_ORDER_ANY,
129 (sysinit_cfunc_t) elf32_insert_brand_entry,
130 &ia32_brand_info);
131
132static register_t *
133ia32_copyout_strings(struct image_params *imgp)
134{
135 int argc, envc;
136 u_int32_t *vectp;
137 char *stringp, *destp;
138 u_int32_t *stack_base;
139 struct ia32_ps_strings *arginfo;
140 int szsigcode;
141
142 /*
143 * Calculate string base and vector table pointers.
144 * Also deal with signal trampoline code for this exec type.
145 */
146 arginfo = (struct ia32_ps_strings *)IA32_PS_STRINGS;
147 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
112 0,
113 IA32_USRSTACK,
114 IA32_USRSTACK,
115 IA32_PS_STRINGS,
116 VM_PROT_ALL,
117 ia32_copyout_strings,
118 ia32_setregs
119};
120
121static Elf32_Brandinfo ia32_brand_info = {
122 ELFOSABI_FREEBSD,
123 EM_386,
124 "FreeBSD",
125 "/compat/ia32",
126 "/usr/libexec/ld-elf.so.1",
127 &ia32_freebsd_sysvec
128 };
129
130SYSINIT(ia32, SI_SUB_EXEC, SI_ORDER_ANY,
131 (sysinit_cfunc_t) elf32_insert_brand_entry,
132 &ia32_brand_info);
133
134static register_t *
135ia32_copyout_strings(struct image_params *imgp)
136{
137 int argc, envc;
138 u_int32_t *vectp;
139 char *stringp, *destp;
140 u_int32_t *stack_base;
141 struct ia32_ps_strings *arginfo;
142 int szsigcode;
143
144 /*
145 * Calculate string base and vector table pointers.
146 * Also deal with signal trampoline code for this exec type.
147 */
148 arginfo = (struct ia32_ps_strings *)IA32_PS_STRINGS;
149 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
148 destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
149 roundup((ARG_MAX - imgp->stringspace), sizeof(char *));
150 destp = (caddr_t)arginfo - szsigcode - IA32_USRSPACE -
151 roundup((ARG_MAX - imgp->stringspace), sizeof(char *));
150
151 /*
152 * install sigcode
153 */
154 if (szsigcode)
155 copyout(imgp->proc->p_sysent->sv_sigcode,
156 ((caddr_t)arginfo - szsigcode), szsigcode);
157
158 /*
159 * If we have a valid auxargs ptr, prepare some room
160 * on the stack.
161 */
162 if (imgp->auxargs) {
163 /*
164 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
165 * lower compatibility.
166 */
167 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
168 : (AT_COUNT * 2);
169 /*
170 * The '+ 2' is for the null pointers at the end of each of
171 * the arg and env vector sets,and imgp->auxarg_size is room
172 * for argument of Runtime loader.
173 */
174 vectp = (u_int32_t *) (destp - (imgp->argc + imgp->envc + 2 +
175 imgp->auxarg_size) * sizeof(u_int32_t));
176
177 } else
178 /*
179 * The '+ 2' is for the null pointers at the end of each of
180 * the arg and env vector sets
181 */
182 vectp = (u_int32_t *)
183 (destp - (imgp->argc + imgp->envc + 2) * sizeof(u_int32_t));
184
185 /*
186 * vectp also becomes our initial stack base
187 */
152
153 /*
154 * install sigcode
155 */
156 if (szsigcode)
157 copyout(imgp->proc->p_sysent->sv_sigcode,
158 ((caddr_t)arginfo - szsigcode), szsigcode);
159
160 /*
161 * If we have a valid auxargs ptr, prepare some room
162 * on the stack.
163 */
164 if (imgp->auxargs) {
165 /*
166 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
167 * lower compatibility.
168 */
169 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
170 : (AT_COUNT * 2);
171 /*
172 * The '+ 2' is for the null pointers at the end of each of
173 * the arg and env vector sets,and imgp->auxarg_size is room
174 * for argument of Runtime loader.
175 */
176 vectp = (u_int32_t *) (destp - (imgp->argc + imgp->envc + 2 +
177 imgp->auxarg_size) * sizeof(u_int32_t));
178
179 } else
180 /*
181 * The '+ 2' is for the null pointers at the end of each of
182 * the arg and env vector sets
183 */
184 vectp = (u_int32_t *)
185 (destp - (imgp->argc + imgp->envc + 2) * sizeof(u_int32_t));
186
187 /*
188 * vectp also becomes our initial stack base
189 */
190 vectp = (void*)((uintptr_t)vectp & ~15);
188 stack_base = vectp;
189
190 stringp = imgp->stringbase;
191 argc = imgp->argc;
192 envc = imgp->envc;
193
194 /*
195 * Copy out strings - arguments and environment.
196 */
197 copyout(stringp, destp, ARG_MAX - imgp->stringspace);
198
199 /*
200 * Fill in "ps_strings" struct for ps, w, etc.
201 */
202 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
203 suword32(&arginfo->ps_nargvstr, argc);
204
205 /*
206 * Fill in argument portion of vector table.
207 */
208 for (; argc > 0; --argc) {
209 suword32(vectp++, (u_int32_t)(intptr_t)destp);
210 while (*stringp++ != 0)
211 destp++;
212 destp++;
213 }
214
215 /* a null vector table pointer separates the argp's from the envp's */
216 suword32(vectp++, 0);
217
218 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
219 suword32(&arginfo->ps_nenvstr, envc);
220
221 /*
222 * Fill in environment portion of vector table.
223 */
224 for (; envc > 0; --envc) {
225 suword32(vectp++, (u_int32_t)(intptr_t)destp);
226 while (*stringp++ != 0)
227 destp++;
228 destp++;
229 }
230
231 /* end of vector table is a null pointer */
232 suword32(vectp, 0);
233
234 return ((register_t *)stack_base);
235}
236
237static void
238ia32_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
239{
191 stack_base = vectp;
192
193 stringp = imgp->stringbase;
194 argc = imgp->argc;
195 envc = imgp->envc;
196
197 /*
198 * Copy out strings - arguments and environment.
199 */
200 copyout(stringp, destp, ARG_MAX - imgp->stringspace);
201
202 /*
203 * Fill in "ps_strings" struct for ps, w, etc.
204 */
205 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
206 suword32(&arginfo->ps_nargvstr, argc);
207
208 /*
209 * Fill in argument portion of vector table.
210 */
211 for (; argc > 0; --argc) {
212 suword32(vectp++, (u_int32_t)(intptr_t)destp);
213 while (*stringp++ != 0)
214 destp++;
215 destp++;
216 }
217
218 /* a null vector table pointer separates the argp's from the envp's */
219 suword32(vectp++, 0);
220
221 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
222 suword32(&arginfo->ps_nenvstr, envc);
223
224 /*
225 * Fill in environment portion of vector table.
226 */
227 for (; envc > 0; --envc) {
228 suword32(vectp++, (u_int32_t)(intptr_t)destp);
229 while (*stringp++ != 0)
230 destp++;
231 destp++;
232 }
233
234 /* end of vector table is a null pointer */
235 suword32(vectp, 0);
236
237 return ((register_t *)stack_base);
238}
239
240static void
241ia32_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
242{
240 struct trapframe *frame = td->td_frame;
243 struct trapframe *tf = td->td_frame;
241 vm_offset_t gdt, ldt;
242 u_int64_t codesel, datasel, ldtsel;
243 u_int64_t codeseg, dataseg, gdtseg, ldtseg;
244 struct segment_descriptor desc;
245 struct vmspace *vmspace = td->td_proc->p_vmspace;
246
244 vm_offset_t gdt, ldt;
245 u_int64_t codesel, datasel, ldtsel;
246 u_int64_t codeseg, dataseg, gdtseg, ldtseg;
247 struct segment_descriptor desc;
248 struct vmspace *vmspace = td->td_proc->p_vmspace;
249
247 /*
248 * Make sure that we restore the entire trapframe after an
249 * execve.
250 */
251 frame->tf_flags &= ~FRAME_SYSCALL;
250 exec_setregs(td, entry, stack, ps_strings);
252
251
253 bzero(frame->tf_r, sizeof(frame->tf_r));
254 bzero(frame->tf_f, sizeof(frame->tf_f));
252 /* Non-syscall frames are cleared by exec_setregs() */
253 if (tf->tf_flags & FRAME_SYSCALL) {
254 bzero(&tf->tf_scratch, sizeof(tf->tf_scratch));
255 bzero(&tf->tf_scratch_fp, sizeof(tf->tf_scratch_fp));
256 } else
257 tf->tf_special.ndirty = 0;
255
258
256 frame->tf_cr_iip = entry;
257 frame->tf_cr_ipsr = (IA64_PSR_IC
258 | IA64_PSR_I
259 | IA64_PSR_IT
260 | IA64_PSR_DT
261 | IA64_PSR_RT
262 | IA64_PSR_DFH
263 | IA64_PSR_IS
264 | IA64_PSR_BN
265 | IA64_PSR_CPL_USER);
266 frame->tf_r[FRAME_R12] = stack;
259 tf->tf_special.psr |= IA64_PSR_IS;
260 tf->tf_special.sp = stack;
267
261
262 /* Point the RSE backstore to something harmless. */
263 tf->tf_special.bspstore = (IA32_PS_STRINGS - ia32_szsigcode -
264 IA32_USRSPACE + 15) & ~15;
265
268 codesel = LSEL(LUCODE_SEL, SEL_UPL);
269 datasel = LSEL(LUDATA_SEL, SEL_UPL);
270 ldtsel = GSEL(GLDT_SEL, SEL_UPL);
271
266 codesel = LSEL(LUCODE_SEL, SEL_UPL);
267 datasel = LSEL(LUDATA_SEL, SEL_UPL);
268 ldtsel = GSEL(GLDT_SEL, SEL_UPL);
269
272#if 1
273 frame->tf_r[FRAME_R16] = (datasel << 48) | (datasel << 32)
274 | (datasel << 16) | datasel;
275 frame->tf_r[FRAME_R17] = (ldtsel << 32) | (datasel << 16) | codesel;
276#else
277 frame->tf_r[FRAME_R16] = datasel;
278 frame->tf_r[FRAME_R17] = codesel;
279 frame->tf_r[FRAME_R18] = datasel;
280 frame->tf_r[FRAME_R19] = datasel;
281 frame->tf_r[FRAME_R20] = datasel;
282 frame->tf_r[FRAME_R21] = datasel;
283 frame->tf_r[FRAME_R22] = ldtsel;
284#endif
270 /* Setup ia32 segment registers. */
271 tf->tf_scratch.gr16 = (datasel << 48) | (datasel << 32) |
272 (datasel << 16) | datasel;
273 tf->tf_scratch.gr17 = (ldtsel << 32) | (datasel << 16) | codesel;
285
286 /*
287 * Build the GDT and LDT.
288 */
289 gdt = IA32_USRSTACK;
274
275 /*
276 * Build the GDT and LDT.
277 */
278 gdt = IA32_USRSTACK;
290 vm_map_find(&vmspace->vm_map, 0, 0,
291 &gdt, PAGE_SIZE, 0,
292 VM_PROT_ALL, VM_PROT_ALL, 0);
293 ldt = gdt + 4096;
279 vm_map_find(&vmspace->vm_map, 0, 0, &gdt, IA32_PAGE_SIZE << 1, 0,
280 VM_PROT_ALL, VM_PROT_ALL, 0);
281 ldt = gdt + IA32_PAGE_SIZE;
294
295 desc.sd_lolimit = 8*NLDT-1;
296 desc.sd_lobase = ldt & 0xffffff;
297 desc.sd_type = SDT_SYSLDT;
298 desc.sd_dpl = SEL_UPL;
299 desc.sd_p = 1;
300 desc.sd_hilimit = 0;
301 desc.sd_def32 = 0;
302 desc.sd_gran = 0;
303 desc.sd_hibase = ldt >> 24;
304 copyout(&desc, (caddr_t) gdt + 8*GLDT_SEL, sizeof(desc));
305
306 desc.sd_lolimit = ((IA32_USRSTACK >> 12) - 1) & 0xffff;
307 desc.sd_lobase = 0;
308 desc.sd_type = SDT_MEMERA;
309 desc.sd_dpl = SEL_UPL;
310 desc.sd_p = 1;
311 desc.sd_hilimit = ((IA32_USRSTACK >> 12) - 1) >> 16;
312 desc.sd_def32 = 1;
313 desc.sd_gran = 1;
314 desc.sd_hibase = 0;
315 copyout(&desc, (caddr_t) ldt + 8*LUCODE_SEL, sizeof(desc));
316 desc.sd_type = SDT_MEMRWA;
317 copyout(&desc, (caddr_t) ldt + 8*LUDATA_SEL, sizeof(desc));
318
319 codeseg = 0 /* base */
320 + (((IA32_USRSTACK >> 12) - 1) << 32) /* limit */
321 + ((long)SDT_MEMERA << 52)
322 + ((long)SEL_UPL << 57)
323 + (1L << 59) /* present */
324 + (1L << 62) /* 32 bits */
325 + (1L << 63); /* page granularity */
326 dataseg = 0 /* base */
327 + (((IA32_USRSTACK >> 12) - 1) << 32) /* limit */
328 + ((long)SDT_MEMRWA << 52)
329 + ((long)SEL_UPL << 57)
330 + (1L << 59) /* present */
331 + (1L << 62) /* 32 bits */
332 + (1L << 63); /* page granularity */
282
283 desc.sd_lolimit = 8*NLDT-1;
284 desc.sd_lobase = ldt & 0xffffff;
285 desc.sd_type = SDT_SYSLDT;
286 desc.sd_dpl = SEL_UPL;
287 desc.sd_p = 1;
288 desc.sd_hilimit = 0;
289 desc.sd_def32 = 0;
290 desc.sd_gran = 0;
291 desc.sd_hibase = ldt >> 24;
292 copyout(&desc, (caddr_t) gdt + 8*GLDT_SEL, sizeof(desc));
293
294 desc.sd_lolimit = ((IA32_USRSTACK >> 12) - 1) & 0xffff;
295 desc.sd_lobase = 0;
296 desc.sd_type = SDT_MEMERA;
297 desc.sd_dpl = SEL_UPL;
298 desc.sd_p = 1;
299 desc.sd_hilimit = ((IA32_USRSTACK >> 12) - 1) >> 16;
300 desc.sd_def32 = 1;
301 desc.sd_gran = 1;
302 desc.sd_hibase = 0;
303 copyout(&desc, (caddr_t) ldt + 8*LUCODE_SEL, sizeof(desc));
304 desc.sd_type = SDT_MEMRWA;
305 copyout(&desc, (caddr_t) ldt + 8*LUDATA_SEL, sizeof(desc));
306
307 codeseg = 0 /* base */
308 + (((IA32_USRSTACK >> 12) - 1) << 32) /* limit */
309 + ((long)SDT_MEMERA << 52)
310 + ((long)SEL_UPL << 57)
311 + (1L << 59) /* present */
312 + (1L << 62) /* 32 bits */
313 + (1L << 63); /* page granularity */
314 dataseg = 0 /* base */
315 + (((IA32_USRSTACK >> 12) - 1) << 32) /* limit */
316 + ((long)SDT_MEMRWA << 52)
317 + ((long)SEL_UPL << 57)
318 + (1L << 59) /* present */
319 + (1L << 62) /* 32 bits */
320 + (1L << 63); /* page granularity */
333 ia64_set_csd(codeseg);
334 ia64_set_ssd(dataseg);
335 frame->tf_r[FRAME_R24] = dataseg; /* ESD */
336 frame->tf_r[FRAME_R27] = dataseg; /* DSD */
337 frame->tf_r[FRAME_R28] = dataseg; /* FSD */
338 frame->tf_r[FRAME_R29] = dataseg; /* GSD */
339
321
322 tf->tf_scratch.csd = codeseg;
323 tf->tf_scratch.ssd = dataseg;
324 tf->tf_scratch.gr24 = dataseg; /* ESD */
325 tf->tf_scratch.gr27 = dataseg; /* DSD */
326 tf->tf_scratch.gr28 = dataseg; /* FSD */
327 tf->tf_scratch.gr29 = dataseg; /* GSD */
328
340 gdtseg = gdt /* base */
341 + ((8L*NGDT - 1) << 32) /* limit */
342 + ((long)SDT_SYSNULL << 52)
343 + ((long)SEL_UPL << 57)
344 + (1L << 59) /* present */
345 + (0L << 62) /* 16 bits */
346 + (0L << 63); /* byte granularity */
347 ldtseg = ldt /* base */
348 + ((8L*NLDT - 1) << 32) /* limit */
349 + ((long)SDT_SYSLDT << 52)
350 + ((long)SEL_UPL << 57)
351 + (1L << 59) /* present */
352 + (0L << 62) /* 16 bits */
353 + (0L << 63); /* byte granularity */
329 gdtseg = gdt /* base */
330 + ((8L*NGDT - 1) << 32) /* limit */
331 + ((long)SDT_SYSNULL << 52)
332 + ((long)SEL_UPL << 57)
333 + (1L << 59) /* present */
334 + (0L << 62) /* 16 bits */
335 + (0L << 63); /* byte granularity */
336 ldtseg = ldt /* base */
337 + ((8L*NLDT - 1) << 32) /* limit */
338 + ((long)SDT_SYSLDT << 52)
339 + ((long)SEL_UPL << 57)
340 + (1L << 59) /* present */
341 + (0L << 62) /* 16 bits */
342 + (0L << 63); /* byte granularity */
354 frame->tf_r[FRAME_R30] = ldtseg; /* LDTD */
355 frame->tf_r[FRAME_R31] = gdtseg; /* GDTD */
356
343
344 tf->tf_scratch.gr30 = ldtseg; /* LDTD */
345 tf->tf_scratch.gr31 = gdtseg; /* GDTD */
346
347 /* Set ia32 control registers on this processor. */
348 ia64_set_cflg(CR0_PE | CR0_PG | ((long)(CR4_XMM | CR4_FXSR) << 32));
357 ia64_set_eflag(PSL_USER);
358
359 /* PS_STRINGS value for BSD/OS binaries. It is 0 for non-BSD/OS. */
349 ia64_set_eflag(PSL_USER);
350
351 /* PS_STRINGS value for BSD/OS binaries. It is 0 for non-BSD/OS. */
360 frame->tf_r[FRAME_R11] = IA32_PS_STRINGS;
352 tf->tf_scratch.gr11 = IA32_PS_STRINGS;
361
362 /*
363 * XXX - Linux emulator
364 * Make sure sure edx is 0x0 on entry. Linux binaries depend
365 * on it.
366 */
367 td->td_retval[1] = 0;
368}
353
354 /*
355 * XXX - Linux emulator
356 * Make sure sure edx is 0x0 on entry. Linux binaries depend
357 * on it.
358 */
359 td->td_retval[1] = 0;
360}
361
362void
363ia32_restorectx(struct pcb *pcb)
364{
365
366 ia64_set_cflg(pcb->pcb_ia32_cflg);
367 ia64_set_eflag(pcb->pcb_ia32_eflag);
368 ia64_set_fcr(pcb->pcb_ia32_fcr);
369 ia64_set_fdr(pcb->pcb_ia32_fdr);
370 ia64_set_fir(pcb->pcb_ia32_fir);
371 ia64_set_fsr(pcb->pcb_ia32_fsr);
372}
373
374void
375ia32_savectx(struct pcb *pcb)
376{
377
378 pcb->pcb_ia32_cflg = ia64_get_cflg();
379 pcb->pcb_ia32_eflag = ia64_get_eflag();
380 pcb->pcb_ia32_fcr = ia64_get_fcr();
381 pcb->pcb_ia32_fdr = ia64_get_fdr();
382 pcb->pcb_ia32_fir = ia64_get_fir();
383 pcb->pcb_ia32_fsr = ia64_get_fsr();
384}