vm: use assert() instead of vm_assert(); remove vm_assert().
[minix.git] / servers / vm / arch / i386 / vm.c
blob16079e6dad0625c05237e9c5eb4295ccb87e9490
2 #define _SYSTEM 1
4 #include <minix/callnr.h>
5 #include <minix/com.h>
6 #include <minix/config.h>
7 #include <minix/const.h>
8 #include <minix/ds.h>
9 #include <minix/endpoint.h>
10 #include <minix/keymap.h>
11 #include <minix/minlib.h>
12 #include <minix/type.h>
13 #include <minix/ipc.h>
14 #include <minix/sysutil.h>
15 #include <minix/syslib.h>
16 #include <minix/bitmap.h>
18 #include <sys/mman.h>
20 #include <errno.h>
21 #include <assert.h>
22 #include <env.h>
24 #include "proto.h"
25 #include "vm.h"
26 #include "util.h"
28 #include "memory.h"
30 /*===========================================================================*
31 * arch_map2vir *
32 *===========================================================================*/
33 PUBLIC vir_bytes arch_map2vir(struct vmproc *vmp, vir_bytes addr)
35 vir_bytes textstart = CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_phys);
36 vir_bytes datastart = CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys);
38 /* Could be a text address. */
39 assert(datastart <= addr || textstart <= addr);
41 return addr - datastart;
44 /*===========================================================================*
45 * arch_map2str *
46 *===========================================================================*/
47 PUBLIC char *arch_map2str(struct vmproc *vmp, vir_bytes addr)
49 static char bufstr[100];
50 vir_bytes textstart = CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_phys);
51 vir_bytes textend = textstart + CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_len);
52 vir_bytes datastart = CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys);
54 if(addr < textstart) {
55 sprintf(bufstr, "<lin:0x%lx>", addr);
56 } else if(addr < datastart) {
57 sprintf(bufstr, "0x%lx (codeseg)", addr - textstart);
58 } else {
59 sprintf(bufstr, "0x%lx (dataseg)", addr - datastart);
62 return bufstr;
65 /*===========================================================================*
66 * arch_map2info *
67 *===========================================================================*/
68 PUBLIC vir_bytes arch_map2info(struct vmproc *vmp, vir_bytes addr, int *seg,
69 int *prot)
71 vir_bytes textstart = CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_phys);
72 vir_bytes textend = textstart +
73 CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_len);
74 vir_bytes datastart = CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys);
76 /* The protection to be returned here is that of the segment. */
77 if(addr < textstart) {
78 *seg = D;
79 *prot = PROT_READ | PROT_WRITE | PROT_EXEC;
80 return addr;
81 } else if(addr < datastart) {
82 *seg = T;
83 *prot = PROT_READ | PROT_EXEC;
84 return addr - textstart;
85 } else {
86 *seg = D;
87 if (textstart == textend) /* common I&D? */
88 *prot = PROT_READ | PROT_WRITE | PROT_EXEC;
89 else
90 *prot = PROT_READ | PROT_WRITE;
91 return addr - datastart;
95 /*===========================================================================*
96 * arch_addrok *
97 *===========================================================================*/
98 PUBLIC vir_bytes arch_addrok(struct vmproc *vmp, vir_bytes addr)
100 vir_bytes textstart = CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_phys);
101 vir_bytes textend = CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_phys +
102 vmp->vm_arch.vm_seg[T].mem_phys);
103 vir_bytes datastart = CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys);
105 if(addr >= textstart && addr < textstart+textend)
106 return 1;
108 if(addr >= datastart && addr < VM_DATATOP)
109 return 1;
111 return 0;
114 /*===========================================================================*
115 * arch_vir2map *
116 *===========================================================================*/
117 PUBLIC vir_bytes arch_vir2map(struct vmproc *vmp, vir_bytes addr)
119 vir_bytes bottom = CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys);
121 return addr + bottom;
124 /*===========================================================================*
125 * arch_vir2map_text *
126 *===========================================================================*/
127 PUBLIC vir_bytes arch_vir2map_text(struct vmproc *vmp, vir_bytes addr)
129 vir_bytes bottom = CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_phys);
131 return addr + bottom;