xref: /minix/minix/kernel/arch/i386/arch_do_vmctl.c (revision fb9c64b2)
1 /* The kernel call implemented in this file:
2  *   m_type:	SYS_VMCTL
3  *
4  * The parameters for this kernel call are:
5  *   	SVMCTL_WHO	which process
6  *    	SVMCTL_PARAM	set this setting (VMCTL_*)
7  *    	SVMCTL_VALUE	to this value
8  */
9 
10 #include "kernel/system.h"
11 #include <assert.h>
12 
13 #include "arch_proto.h"
14 
15 extern phys_bytes video_mem_vaddr;
16 
17 extern char *video_mem;
18 
19 static void setcr3(struct proc *p, u32_t cr3, u32_t *v)
20 {
21 	/* Set process CR3. */
22 	p->p_seg.p_cr3 = cr3;
23 	assert(p->p_seg.p_cr3);
24 	p->p_seg.p_cr3_v = v;
25 	if(p == get_cpulocal_var(ptproc)) {
26 		write_cr3(p->p_seg.p_cr3);
27 	}
28 	if(p->p_nr == VM_PROC_NR) {
29 		if (arch_enable_paging(p) != OK)
30 			panic("arch_enable_paging failed");
31 	}
32 	RTS_UNSET(p, RTS_VMINHIBIT);
33 }
34 
35 /*===========================================================================*
36  *				arch_do_vmctl				     *
37  *===========================================================================*/
38 int arch_do_vmctl(
39   register message *m_ptr,	/* pointer to request message */
40   struct proc *p
41 )
42 {
43   switch(m_ptr->SVMCTL_PARAM) {
44 	case VMCTL_GET_PDBR:
45 		/* Get process page directory base reg (CR3). */
46 		m_ptr->SVMCTL_VALUE = p->p_seg.p_cr3;
47 		return OK;
48 	case VMCTL_SETADDRSPACE:
49 		setcr3(p, m_ptr->SVMCTL_PTROOT, (u32_t *) m_ptr->SVMCTL_PTROOT_V);
50 		return OK;
51 	case VMCTL_FLUSHTLB:
52 	{
53 		reload_cr3();
54 		return OK;
55 	}
56 	case VMCTL_I386_INVLPG:
57 	{
58 		i386_invlpg(m_ptr->SVMCTL_VALUE);
59 		return OK;
60 	}
61   }
62 
63 
64 
65   printf("arch_do_vmctl: strange param %d\n", m_ptr->SVMCTL_PARAM);
66   return EINVAL;
67 }
68