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 unchanged lines hidden (view full) --- 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 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> --- 12 unchanged lines hidden (view full) --- 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 |
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> |
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 */ |
89 0 |
90}; |
91static int ia32_szsigcode = sizeof(ia32_sigcode); |
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, |
110 IA32_MINSIGSTKSZ, 111 IA32_PAGE_SIZE, |
112 0, 113 IA32_USRSTACK, 114 IA32_USRSTACK, 115 IA32_PS_STRINGS, 116 VM_PROT_ALL, 117 ia32_copyout_strings, 118 ia32_setregs 119}; --- 22 unchanged lines hidden (view full) --- 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); |
150 destp = (caddr_t)arginfo - szsigcode - IA32_USRSPACE - 151 roundup((ARG_MAX - imgp->stringspace), sizeof(char *)); |
152 153 /* 154 * install sigcode 155 */ 156 if (szsigcode) 157 copyout(imgp->proc->p_sysent->sv_sigcode, 158 ((caddr_t)arginfo - szsigcode), szsigcode); 159 --- 22 unchanged lines hidden (view full) --- 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); |
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. --- 36 unchanged lines hidden (view full) --- 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{ |
243 struct trapframe *tf = td->td_frame; |
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 |
250 exec_setregs(td, entry, stack, ps_strings); |
251 |
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; |
258 |
259 tf->tf_special.psr |= IA64_PSR_IS; 260 tf->tf_special.sp = stack; |
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 |
266 codesel = LSEL(LUCODE_SEL, SEL_UPL); 267 datasel = LSEL(LUDATA_SEL, SEL_UPL); 268 ldtsel = GSEL(GLDT_SEL, SEL_UPL); 269 |
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; |
274 275 /* 276 * Build the GDT and LDT. 277 */ 278 gdt = IA32_USRSTACK; |
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; |
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; --- 23 unchanged lines hidden (view full) --- 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 */ |
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 |
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 */ |
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)); |
349 ia64_set_eflag(PSL_USER); 350 351 /* PS_STRINGS value for BSD/OS binaries. It is 0 for non-BSD/OS. */ |
352 tf->tf_scratch.gr11 = IA32_PS_STRINGS; |
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} |