1 /* The kernel calls that are implemented in this file:
2 * m_type: SYS_SETMCONTEXT
3 * m_type: SYS_GETMCONTEXT
5 * The parameters for these kernel calls are:
6 * m1_i1: PR_ENDPT # proc endpoint doing call
7 * m1_p1: PR_MEM_PTR # pointer to mcontext structure
11 #include "kernel/system.h"
13 #include <machine/mcontext.h>
16 /*===========================================================================*
18 *===========================================================================*/
19 int do_getmcontext(struct proc
* caller
, message
* m_ptr
)
21 /* Retrieve machine context of a process */
23 register struct proc
*rp
;
27 if (! isokendpt(m_ptr
->PR_ENDPT
, &proc_nr
)) return(EINVAL
);
28 if (iskerneln(proc_nr
)) return(EPERM
);
29 rp
= proc_addr(proc_nr
);
32 if (!proc_used_fpu(rp
))
33 return(OK
); /* No state to copy */
36 /* Get the mcontext structure into our address space. */
37 if ((r
= data_copy(m_ptr
->PR_ENDPT
, (vir_bytes
) m_ptr
->PR_CTX_PTR
, KERNEL
,
38 (vir_bytes
) &mc
, (phys_bytes
) sizeof(struct __mcontext
))) != OK
)
44 if (proc_used_fpu(rp
)) {
45 /* make sure that the FPU context is saved into proc structure first */
47 mc
.mc_fpu_flags
= rp
->p_misc_flags
& MF_FPU_INITIALIZED
;
48 memcpy(&(mc
.mc_fpu_state
), rp
->p_seg
.fpu_state
, FPU_XFP_SIZE
);
53 /* Copy the mcontext structure to the user's address space. */
54 if ((r
= data_copy(KERNEL
, (vir_bytes
) &mc
, m_ptr
->PR_ENDPT
,
55 (vir_bytes
) m_ptr
->PR_CTX_PTR
,
56 (phys_bytes
) sizeof(struct __mcontext
))) != OK
)
63 /*===========================================================================*
65 *===========================================================================*/
66 int do_setmcontext(struct proc
* caller
, message
* m_ptr
)
68 /* Set machine context of a process */
70 register struct proc
*rp
;
74 if (!isokendpt(m_ptr
->PR_ENDPT
, &proc_nr
)) return(EINVAL
);
75 rp
= proc_addr(proc_nr
);
77 /* Get the mcontext structure into our address space. */
78 if ((r
= data_copy(m_ptr
->PR_ENDPT
, (vir_bytes
) m_ptr
->PR_CTX_PTR
, KERNEL
,
79 (vir_bytes
) &mc
, (phys_bytes
) sizeof(struct __mcontext
))) != OK
)
84 if (mc
.mc_fpu_flags
& MF_FPU_INITIALIZED
) {
85 rp
->p_misc_flags
|= MF_FPU_INITIALIZED
;
86 memcpy(rp
->p_seg
.fpu_state
, &(mc
.mc_fpu_state
), FPU_XFP_SIZE
);
88 rp
->p_misc_flags
&= ~MF_FPU_INITIALIZED
;
89 /* force reloading FPU in either case */