xref: /minix3/minix/kernel/arch/i386/arch_do_vmctl.c (revision 9624407e7addfd8b88486acfe3a0e056e2b92ee3)
1433d6423SLionel Sambuc /* The kernel call implemented in this file:
2433d6423SLionel Sambuc  *   m_type:	SYS_VMCTL
3433d6423SLionel Sambuc  *
4433d6423SLionel Sambuc  * The parameters for this kernel call are:
5433d6423SLionel Sambuc  *   	SVMCTL_WHO	which process
6433d6423SLionel Sambuc  *    	SVMCTL_PARAM	set this setting (VMCTL_*)
7433d6423SLionel Sambuc  *    	SVMCTL_VALUE	to this value
8433d6423SLionel Sambuc  */
9433d6423SLionel Sambuc 
10433d6423SLionel Sambuc #include "kernel/system.h"
11433d6423SLionel Sambuc #include <assert.h>
12433d6423SLionel Sambuc 
13433d6423SLionel Sambuc #include "arch_proto.h"
14433d6423SLionel Sambuc 
15433d6423SLionel Sambuc extern phys_bytes video_mem_vaddr;
16433d6423SLionel Sambuc 
17433d6423SLionel Sambuc extern char *video_mem;
18433d6423SLionel Sambuc 
setcr3(struct proc * p,u32_t cr3,u32_t * v)19433d6423SLionel Sambuc static void setcr3(struct proc *p, u32_t cr3, u32_t *v)
20433d6423SLionel Sambuc {
21433d6423SLionel Sambuc 	/* Set process CR3. */
22433d6423SLionel Sambuc 	p->p_seg.p_cr3 = cr3;
23433d6423SLionel Sambuc 	assert(p->p_seg.p_cr3);
24433d6423SLionel Sambuc 	p->p_seg.p_cr3_v = v;
25433d6423SLionel Sambuc 	if(p == get_cpulocal_var(ptproc)) {
26433d6423SLionel Sambuc 		write_cr3(p->p_seg.p_cr3);
27433d6423SLionel Sambuc 	}
28433d6423SLionel Sambuc 	if(p->p_nr == VM_PROC_NR) {
29433d6423SLionel Sambuc 		if (arch_enable_paging(p) != OK)
30433d6423SLionel Sambuc 			panic("arch_enable_paging failed");
31433d6423SLionel Sambuc 	}
32433d6423SLionel Sambuc 	RTS_UNSET(p, RTS_VMINHIBIT);
33433d6423SLionel Sambuc }
34433d6423SLionel Sambuc 
35433d6423SLionel Sambuc /*===========================================================================*
36433d6423SLionel Sambuc  *				arch_do_vmctl				     *
37433d6423SLionel Sambuc  *===========================================================================*/
arch_do_vmctl(register message * m_ptr,struct proc * p)38*6077d1adSDr. Florian Grätz int arch_do_vmctl(
39*6077d1adSDr. Florian Grätz   register message *m_ptr,	/* pointer to request message */
40*6077d1adSDr. Florian Grätz   struct proc *p
41*6077d1adSDr. Florian Grätz )
42433d6423SLionel Sambuc {
43433d6423SLionel Sambuc   switch(m_ptr->SVMCTL_PARAM) {
44433d6423SLionel Sambuc 	case VMCTL_GET_PDBR:
45433d6423SLionel Sambuc 		/* Get process page directory base reg (CR3). */
46433d6423SLionel Sambuc 		m_ptr->SVMCTL_VALUE = p->p_seg.p_cr3;
47433d6423SLionel Sambuc 		return OK;
48433d6423SLionel Sambuc 	case VMCTL_SETADDRSPACE:
49433d6423SLionel Sambuc 		setcr3(p, m_ptr->SVMCTL_PTROOT, (u32_t *) m_ptr->SVMCTL_PTROOT_V);
50433d6423SLionel Sambuc 		return OK;
51433d6423SLionel Sambuc 	case VMCTL_FLUSHTLB:
52433d6423SLionel Sambuc 	{
53433d6423SLionel Sambuc 		reload_cr3();
54433d6423SLionel Sambuc 		return OK;
55433d6423SLionel Sambuc 	}
56433d6423SLionel Sambuc 	case VMCTL_I386_INVLPG:
57433d6423SLionel Sambuc 	{
58433d6423SLionel Sambuc 		i386_invlpg(m_ptr->SVMCTL_VALUE);
59433d6423SLionel Sambuc 		return OK;
60433d6423SLionel Sambuc 	}
61433d6423SLionel Sambuc   }
62433d6423SLionel Sambuc 
63433d6423SLionel Sambuc 
64433d6423SLionel Sambuc 
65433d6423SLionel Sambuc   printf("arch_do_vmctl: strange param %d\n", m_ptr->SVMCTL_PARAM);
66433d6423SLionel Sambuc   return EINVAL;
67433d6423SLionel Sambuc }
68