2010-03-12 16:58:41 +01:00
|
|
|
/* The kernel calls that are implemented in this file:
|
|
|
|
* m_type: SYS_SETMCONTEXT
|
|
|
|
* m_type: SYS_GETMCONTEXT
|
|
|
|
*
|
2014-05-26 10:41:06 +02:00
|
|
|
* The parameters for SYS_SETMCONTEXT kernel call are:
|
|
|
|
* m_lsys_krn_sys_setmcontext.endpt # proc endpoint doing call
|
|
|
|
* m_lsys_krn_sys_setmcontext.ctx_ptr # pointer to mcontext structure
|
2010-03-12 16:58:41 +01:00
|
|
|
*
|
2014-05-26 10:41:06 +02:00
|
|
|
* The parameters for SYS_GETMCONTEXT kernel call are:
|
|
|
|
* m_lsys_krn_sys_getmcontext.endpt # proc endpoint doing call
|
|
|
|
* m_lsys_krn_sys_getmcontext.ctx_ptr # pointer to mcontext structure
|
2010-03-12 16:58:41 +01:00
|
|
|
*/
|
|
|
|
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/system.h"
|
2010-03-12 16:58:41 +01:00
|
|
|
#include <string.h>
|
2013-12-10 14:55:46 +01:00
|
|
|
#include <assert.h>
|
2010-03-12 16:58:41 +01:00
|
|
|
#include <machine/mcontext.h>
|
|
|
|
|
|
|
|
#if USE_MCONTEXT
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_getmcontext *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_getmcontext(struct proc * caller, message * m_ptr)
|
2010-03-12 16:58:41 +01:00
|
|
|
{
|
|
|
|
/* Retrieve machine context of a process */
|
|
|
|
|
|
|
|
register struct proc *rp;
|
|
|
|
int proc_nr, r;
|
|
|
|
mcontext_t mc;
|
|
|
|
|
2014-05-26 10:41:06 +02:00
|
|
|
if (!isokendpt(m_ptr->m_lsys_krn_sys_getmcontext.endpt, &proc_nr))
|
|
|
|
return(EINVAL);
|
2010-03-12 16:58:41 +01:00
|
|
|
if (iskerneln(proc_nr)) return(EPERM);
|
|
|
|
rp = proc_addr(proc_nr);
|
|
|
|
|
2012-08-06 12:55:50 +02:00
|
|
|
#if defined(__i386__)
|
2010-07-01 14:31:53 +02:00
|
|
|
if (!proc_used_fpu(rp))
|
2010-03-12 16:58:41 +01:00
|
|
|
return(OK); /* No state to copy */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Get the mcontext structure into our address space. */
|
2014-05-26 10:41:06 +02:00
|
|
|
if ((r = data_copy(m_ptr->m_lsys_krn_sys_getmcontext.endpt,
|
|
|
|
m_ptr->m_lsys_krn_sys_getmcontext.ctx_ptr, KERNEL,
|
2013-12-10 14:55:46 +01:00
|
|
|
(vir_bytes) &mc, (phys_bytes) sizeof(mcontext_t))) != OK)
|
2010-03-12 16:58:41 +01:00
|
|
|
return(r);
|
|
|
|
|
2013-12-10 14:55:46 +01:00
|
|
|
mc.mc_flags = 0;
|
2012-08-06 12:55:50 +02:00
|
|
|
#if defined(__i386__)
|
2010-03-12 16:58:41 +01:00
|
|
|
/* Copy FPU state */
|
2010-07-01 14:23:25 +02:00
|
|
|
if (proc_used_fpu(rp)) {
|
2010-06-07 09:43:17 +02:00
|
|
|
/* make sure that the FPU context is saved into proc structure first */
|
2010-09-15 16:11:25 +02:00
|
|
|
save_fpu(rp);
|
2013-12-10 14:55:46 +01:00
|
|
|
mc.mc_flags = (rp->p_misc_flags & MF_FPU_INITIALIZED) ? _MC_FPU_SAVED : 0;
|
|
|
|
assert(sizeof(mc.__fpregs.__fp_reg_set) == FPU_XFP_SIZE);
|
|
|
|
memcpy(&(mc.__fpregs.__fp_reg_set), rp->p_seg.fpu_state, FPU_XFP_SIZE);
|
2010-03-12 16:58:41 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy the mcontext structure to the user's address space. */
|
2014-05-26 10:41:06 +02:00
|
|
|
if ((r = data_copy(KERNEL, (vir_bytes) &mc,
|
|
|
|
m_ptr->m_lsys_krn_sys_getmcontext.endpt,
|
|
|
|
m_ptr->m_lsys_krn_sys_getmcontext.ctx_ptr,
|
2013-12-10 14:55:46 +01:00
|
|
|
(phys_bytes) sizeof(mcontext_t))) != OK)
|
2010-03-12 16:58:41 +01:00
|
|
|
return(r);
|
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_setmcontext *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_setmcontext(struct proc * caller, message * m_ptr)
|
2010-03-12 16:58:41 +01:00
|
|
|
{
|
|
|
|
/* Set machine context of a process */
|
|
|
|
|
|
|
|
register struct proc *rp;
|
|
|
|
int proc_nr, r;
|
|
|
|
mcontext_t mc;
|
|
|
|
|
2014-05-26 10:41:06 +02:00
|
|
|
if (!isokendpt(m_ptr->m_lsys_krn_sys_setmcontext.endpt, &proc_nr)) return(EINVAL);
|
2010-03-12 16:58:41 +01:00
|
|
|
rp = proc_addr(proc_nr);
|
|
|
|
|
|
|
|
/* Get the mcontext structure into our address space. */
|
2014-05-26 10:41:06 +02:00
|
|
|
if ((r = data_copy(m_ptr->m_lsys_krn_sys_setmcontext.endpt,
|
|
|
|
m_ptr->m_lsys_krn_sys_setmcontext.ctx_ptr, KERNEL,
|
2013-12-10 14:55:46 +01:00
|
|
|
(vir_bytes) &mc, (phys_bytes) sizeof(mcontext_t))) != OK)
|
2010-03-12 16:58:41 +01:00
|
|
|
return(r);
|
|
|
|
|
2012-08-06 12:55:50 +02:00
|
|
|
#if defined(__i386__)
|
2010-03-12 16:58:41 +01:00
|
|
|
/* Copy FPU state */
|
2013-12-10 14:55:46 +01:00
|
|
|
if (mc.mc_flags & _MC_FPU_SAVED) {
|
2010-03-12 16:58:41 +01:00
|
|
|
rp->p_misc_flags |= MF_FPU_INITIALIZED;
|
2013-12-10 14:55:46 +01:00
|
|
|
assert(sizeof(mc.__fpregs.__fp_reg_set) == FPU_XFP_SIZE);
|
|
|
|
memcpy(rp->p_seg.fpu_state, &(mc.__fpregs.__fp_reg_set), FPU_XFP_SIZE);
|
2010-03-12 16:58:41 +01:00
|
|
|
} else
|
|
|
|
rp->p_misc_flags &= ~MF_FPU_INITIALIZED;
|
2010-06-07 09:43:17 +02:00
|
|
|
/* force reloading FPU in either case */
|
2010-09-15 16:11:25 +02:00
|
|
|
release_fpu(rp);
|
2010-03-12 16:58:41 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|