Changeset View
Changeset View
Standalone View
Standalone View
sys/arm/arm/vfp.c
| Show All 28 Lines | |||||
| */ | */ | ||||
| #include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
| __FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
| #ifdef VFP | #ifdef VFP | ||||
| #include <sys/param.h> | #include <sys/param.h> | ||||
| #include <sys/systm.h> | #include <sys/systm.h> | ||||
| #include <sys/limits.h> | |||||
| #include <sys/proc.h> | #include <sys/proc.h> | ||||
| #include <sys/imgact_elf.h> | #include <sys/imgact_elf.h> | ||||
| #include <sys/kernel.h> | #include <sys/kernel.h> | ||||
| #include <machine/armreg.h> | #include <machine/armreg.h> | ||||
| #include <machine/elf.h> | #include <machine/elf.h> | ||||
| #include <machine/frame.h> | #include <machine/frame.h> | ||||
| #include <machine/md_var.h> | #include <machine/md_var.h> | ||||
| ▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | vfp_bounce(u_int addr, u_int insn, struct trapframe *frame, int code) | ||||
| * If the last time this thread used the VFP it was on this core, and | * If the last time this thread used the VFP it was on this core, and | ||||
| * the last thread to use the VFP on this core was this thread, then the | * the last thread to use the VFP on this core was this thread, then the | ||||
| * VFP state is valid, otherwise restore this thread's state to the VFP. | * VFP state is valid, otherwise restore this thread's state to the VFP. | ||||
| */ | */ | ||||
| fmxr(fpexc, fpexc | VFPEXC_EN); | fmxr(fpexc, fpexc | VFPEXC_EN); | ||||
| curpcb = curthread->td_pcb; | curpcb = curthread->td_pcb; | ||||
| cpu = PCPU_GET(cpuid); | cpu = PCPU_GET(cpuid); | ||||
| if (curpcb->pcb_vfpcpu != cpu || curthread != PCPU_GET(fpcurthread)) { | if (curpcb->pcb_vfpcpu != cpu || curthread != PCPU_GET(fpcurthread)) { | ||||
| if (curpcb->pcb_vfpsaved == NULL) | |||||
| curpcb->pcb_vfpsaved = &curpcb->pcb_vfpstate; | |||||
| vfp_restore(curpcb->pcb_vfpsaved); | vfp_restore(curpcb->pcb_vfpsaved); | ||||
| curpcb->pcb_vfpcpu = cpu; | curpcb->pcb_vfpcpu = cpu; | ||||
| PCPU_SET(fpcurthread, curthread); | PCPU_SET(fpcurthread, curthread); | ||||
| } | } | ||||
| critical_exit(); | critical_exit(); | ||||
| KASSERT(curpcb->pcb_vfpsaved == &curpcb->pcb_vfpstate, | |||||
| ("Kernel VFP state in use when entering userspace")); | |||||
| return (0); | return (0); | ||||
| } | } | ||||
| /* | /* | ||||
| * Update the VFP state for a forked process or new thread. The PCB will | |||||
| * have been copied from the old thread. | |||||
| * The code is heavily based on arm64 logic. | |||||
| */ | |||||
| void | |||||
| vfp_new_thread(struct thread *newtd, struct thread *oldtd, bool fork) | |||||
| { | |||||
| struct pcb *newpcb; | |||||
| newpcb = newtd->td_pcb; | |||||
| /* Kernel threads start with clean VFP */ | |||||
| if ((oldtd->td_pflags & TDP_KTHREAD) != 0) { | |||||
| newpcb->pcb_fpflags &= | |||||
| ~(PCB_FP_STARTED | PCB_FP_KERN | PCB_FP_NOSAVE); | |||||
| } else { | |||||
| MPASS((newpcb->pcb_fpflags & (PCB_FP_KERN|PCB_FP_NOSAVE)) == 0); | |||||
| if (!fork) { | |||||
| newpcb->pcb_fpflags &= ~PCB_FP_STARTED; | |||||
| } | |||||
| } | |||||
| newpcb->pcb_vfpsaved = &newpcb->pcb_vfpstate; | |||||
| newpcb->pcb_vfpcpu = UINT_MAX; | |||||
| } | |||||
| /* | |||||
| * Restore the given state to the VFP hardware. | * Restore the given state to the VFP hardware. | ||||
| */ | */ | ||||
| static void | static void | ||||
| vfp_restore(struct vfp_state *vfpsave) | vfp_restore(struct vfp_state *vfpsave) | ||||
| { | { | ||||
| uint32_t fpexc; | uint32_t fpexc; | ||||
| /* On vfpv3 we may need to restore FPINST and FPINST2 */ | /* On vfpv3 we may need to restore FPINST and FPINST2 */ | ||||
| ▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines | |||||