reg_t p_ldt_sel; /* selector in gdt with ldt base and limit */
reg_t p_cr3; /* page table root */
u32_t *p_cr3_v;
+ char *fpu_state;
struct segdesc_s p_ldt[LDT_SIZE]; /* CS, DS and remote */
} segframe_t;
-/* fpu_state_s is used in kernel proc table.
- * Any changes in this structure requires changes in sconst.h,
- * since this structure is used in proc structure. */
-struct fpu_state_s {
- union fpu_state_u *fpu_save_area_p; /* 16-aligned fpu_save_area */
- /* fpu_image includes 512 bytes of image itself and
- * additional 15 bytes required for manual 16-byte alignment. */
- char fpu_image[527];
-};
-
#define INMEMORY(p) (!p->p_seg.p_cr3 || get_cpulocal_var(ptproc) == p)
typedef u32_t atomic_t; /* access to an aligned 32bit value is atomic on i386 */
void save_local_fpu(struct proc *pr, int retain)
{
+ char *state = pr->p_seg.fpu_state;
+
/* Save process FPU context. If the 'retain' flag is set, keep the FPU
* state as is. If the flag is not set, the state is undefined upon
* return, and the caller is responsible for reloading a proper state.
if(!is_fpu())
return;
+ assert(state);
+
if(osfxsr_feature) {
- fxsave(pr->p_fpu_state.fpu_save_area_p);
+ fxsave(state);
} else {
- fnsave(pr->p_fpu_state.fpu_save_area_p);
+ fnsave(state);
if (retain)
- (void) frstor(pr->p_fpu_state.fpu_save_area_p);
+ (void) frstor(state);
}
}
}
}
+/* reserve a chunk of memory for fpu state; every one has to
+ * be FPUALIGN-aligned.
+ */
+static char fpu_state[NR_PROCS][FPU_XFP_SIZE] __aligned(FPUALIGN);
+
+void arch_proc_init(int nr, struct proc *pr)
+{
+ if(nr < 0) return;
+ char *v;
+
+ assert(nr < NR_PROCS);
+
+ v = fpu_state[nr];
+
+ /* verify alignment */
+ assert(!((vir_bytes)v % FPUALIGN));
+
+ pr->p_seg.fpu_state = v;
+}
+
int restore_fpu(struct proc *pr)
{
int failed;
+ char *state = pr->p_seg.fpu_state;
+
+ assert(state);
if(!proc_used_fpu(pr)) {
fninit();
pr->p_misc_flags |= MF_FPU_INITIALIZED;
} else {
if(osfxsr_feature) {
- failed = fxrstor(pr->p_fpu_state.fpu_save_area_p);
+ failed = fxrstor(state);
} else {
- failed = frstor(pr->p_fpu_state.fpu_save_area_p);
+ failed = frstor(state);
}
if (failed) return EINVAL;
member PSWREG p_reg.psw
member SPREG p_reg.sp
member SSREG p_reg.ss
-member FP_SAVE_AREA_P p_fpu_state
member P_LDT_SEL p_seg.p_ldt_sel
member P_CR3 p_seg.p_cr3
member P_CR3_V p_seg.p_cr3_v
rp->p_scheduler = NULL; /* no user space scheduler */
rp->p_priority = 0; /* no priority */
rp->p_quantum_size_ms = 0; /* no quantum size */
+
+ /* arch-specific initialization */
+ arch_proc_init(i, rp);
}
for (sp = BEG_PRIV_ADDR, i = 0; sp < END_PRIV_ADDR; ++sp, ++i) {
sp->s_proc_nr = NONE; /* initialize as free */
ip->p_rts_flags |= RTS_PROC_STOP;
set_idle_name(ip->p_name, i);
}
-
-#if (_MINIX_CHIP == _CHIP_INTEL)
- for (rp = BEG_PROC_ADDR; rp < END_PROC_ADDR; ++rp) {
- /*
- * FXSR requires 16-byte alignment of memory image, but
- * unfortunately a.out does not preserve the alignment while
- * linking. Thus we have to do manual alignment.
- */
- phys_bytes aligned_fp_area;
- aligned_fp_area =
- (phys_bytes) &rp->p_fpu_state.fpu_image;
- if(aligned_fp_area % FPUALIGN) {
- aligned_fp_area += FPUALIGN -
- (aligned_fp_area % FPUALIGN);
- }
- rp->p_fpu_state.fpu_save_area_p =
- (void *) aligned_fp_area;
- }
-#endif
}
static void switch_address_space_idle(void)
struct proc {
struct stackframe_s p_reg; /* process' registers saved in stack frame */
- struct fpu_state_s p_fpu_state; /* process' fpu_regs saved lazily */
struct segframe p_seg; /* segment descriptors */
proc_nr_t p_nr; /* number of this process (for fast access) */
struct priv *p_priv; /* system privileges structure */
void enqueue(struct proc *rp);
void dequeue(struct proc *rp);
void switch_to_user(void);
+void arch_proc_init(int nr, struct proc *rp);
struct proc * arch_finish_switch_to_user(void);
struct proc *endpoint_lookup(endpoint_t ep);
#if DEBUG_ENABLE_IPC_WARNINGS
/* Handle sys_fork(). PR_ENDPT has forked. The child is PR_SLOT. */
#if (_MINIX_CHIP == _CHIP_INTEL)
reg_t old_ldt_sel;
- void *old_fpu_save_area_p;
+ char *old_fpu_save_area_p;
#endif
register struct proc *rpc; /* child process pointer */
struct proc *rpp; /* parent process pointer */
gen = _ENDPOINT_G(rpc->p_endpoint);
#if (_MINIX_CHIP == _CHIP_INTEL)
old_ldt_sel = rpc->p_seg.p_ldt_sel; /* backup local descriptors */
- old_fpu_save_area_p = rpc->p_fpu_state.fpu_save_area_p;
+ old_fpu_save_area_p = rpc->p_seg.fpu_state;
#endif
*rpc = *rpp; /* copy 'proc' struct */
#if (_MINIX_CHIP == _CHIP_INTEL)
rpc->p_seg.p_ldt_sel = old_ldt_sel; /* restore descriptors */
- rpc->p_fpu_state.fpu_save_area_p = old_fpu_save_area_p;
+ rpc->p_seg.fpu_state = old_fpu_save_area_p;
if(proc_used_fpu(rpp))
- memcpy(rpc->p_fpu_state.fpu_save_area_p,
- rpp->p_fpu_state.fpu_save_area_p,
- FPU_XFP_SIZE);
+ memcpy(rpc->p_seg.fpu_state, rpp->p_seg.fpu_state, FPU_XFP_SIZE);
#endif
if(++gen >= _ENDPOINT_MAX_GENERATION) /* increase generation */
gen = 1; /* generation number wraparound */
/* make sure that the FPU context is saved into proc structure first */
save_fpu(rp);
mc.mc_fpu_flags = rp->p_misc_flags & MF_FPU_INITIALIZED;
- memcpy(&(mc.mc_fpu_state), rp->p_fpu_state.fpu_save_area_p,
- FPU_XFP_SIZE);
+ memcpy(&(mc.mc_fpu_state), rp->p_seg.fpu_state, FPU_XFP_SIZE);
}
#endif
/* Copy FPU state */
if (mc.mc_fpu_flags & MF_FPU_INITIALIZED) {
rp->p_misc_flags |= MF_FPU_INITIALIZED;
- memcpy(rp->p_fpu_state.fpu_save_area_p, &(mc.mc_fpu_state),
- FPU_XFP_SIZE);
+ memcpy(rp->p_seg.fpu_state, &(mc.mc_fpu_state), FPU_XFP_SIZE);
} else
rp->p_misc_flags &= ~MF_FPU_INITIALIZED;
/* force reloading FPU in either case */
#if (_MINIX_CHIP == _CHIP_INTEL)
if(sc.sc_flags & MF_FPU_INITIALIZED)
{
- memcpy(rp->p_fpu_state.fpu_save_area_p, &sc.sc_fpu_state,
- FPU_XFP_SIZE);
+ memcpy(rp->p_seg.fpu_state, &sc.sc_fpu_state, FPU_XFP_SIZE);
rp->p_misc_flags |= MF_FPU_INITIALIZED; /* Restore math usage flag. */
/* force reloading FPU */
release_fpu(rp);
if(proc_used_fpu(rp)) {
/* save the FPU context before saving it to the sig context */
save_fpu(rp);
- memcpy(&sc.sc_fpu_state, rp->p_fpu_state.fpu_save_area_p,
- FPU_XFP_SIZE);
+ memcpy(&sc.sc_fpu_state, rp->p_seg.fpu_state, FPU_XFP_SIZE);
}
#endif
static void adjust_proc_slot(struct proc *rp, struct proc *from_rp);
static void adjust_priv_slot(struct priv *privp, struct priv
*from_privp);
-static void swap_fpu_state(struct proc *a_rp, struct proc *b_orig_rp,
- struct proc *b_copy_rp);
static void swap_proc_slot_pointer(struct proc **rpp, struct proc
*src_rp, struct proc *dst_rp);
adjust_priv_slot(priv(src_rp), &orig_src_priv);
adjust_priv_slot(priv(dst_rp), &orig_dst_priv);
- /* Swap FPU state. Can only be done after adjusting the process slots. */
- swap_fpu_state(src_rp, dst_rp, &orig_dst_proc);
- swap_fpu_state(dst_rp, src_rp, &orig_src_proc);
-
/* Swap global process slot addresses. */
swap_proc_slot_pointer(get_cpulocal_var_ptr(ptproc), src_rp, dst_rp);
priv(rp)->s_proc_nr = from_rp->p_nr;
rp->p_caller_q = from_rp->p_caller_q;
-#if (_MINIX_CHIP == _CHIP_INTEL)
- /* Preserve FPU pointer. */
- rp->p_fpu_state.fpu_save_area_p = from_rp->p_fpu_state.fpu_save_area_p;
-#endif
-
/* preserve scheduling */
rp->p_scheduler = from_rp->p_scheduler;
#ifdef CONFIG_SMP
privp->s_alarm_timer = from_privp->s_alarm_timer;
}
-/*===========================================================================*
- * swap_fpu_state *
- *===========================================================================*/
-static void swap_fpu_state(struct proc *a_rp, struct proc *b_orig_rp,
- struct proc *b_copy_rp)
-{
- /* Copy the FPU state from process B's copied slot, using B's original FPU
- * save area alignment, into process A's slot.
- */
-#if (_MINIX_CHIP == _CHIP_INTEL)
- int align;
-
- align = (int) ((char *) b_orig_rp->p_fpu_state.fpu_save_area_p -
- (char *) &b_orig_rp->p_fpu_state.fpu_image);
-
- memcpy(a_rp->p_fpu_state.fpu_save_area_p,
- b_copy_rp->p_fpu_state.fpu_image + align, FPU_XFP_SIZE);
-#endif
-}
-
/*===========================================================================*
* swap_proc_slot_pointer *
*===========================================================================*/