panic() cleanup.
[minix.git] / servers / vm / i386 / vm.c
blobf23534e7a211df4a59ed5318c06cc45e46458802
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 <env.h>
23 #include "../proto.h"
24 #include "../vm.h"
25 #include "../util.h"
27 #include "memory.h"
29 /*===========================================================================*
30 * arch_map2vir *
31 *===========================================================================*/
32 PUBLIC vir_bytes arch_map2vir(struct vmproc *vmp, vir_bytes addr)
34 vir_bytes textstart = CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_phys);
35 vir_bytes datastart = CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys);
37 /* Could be a text address. */
38 vm_assert(datastart <= addr || textstart <= addr);
40 return addr - datastart;
43 /*===========================================================================*
44 * arch_map2str *
45 *===========================================================================*/
46 PUBLIC char *arch_map2str(struct vmproc *vmp, vir_bytes addr)
48 static char bufstr[100];
49 vir_bytes textstart = CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_phys);
50 vir_bytes textend = textstart + CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_len);
51 vir_bytes datastart = CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys);
53 if(addr < textstart) {
54 sprintf(bufstr, "<lin:0x%lx>", addr);
55 } else if(addr < datastart) {
56 sprintf(bufstr, "0x%lx (codeseg)", addr - textstart);
57 } else {
58 sprintf(bufstr, "0x%lx (dataseg)", addr - datastart);
61 return bufstr;
64 /*===========================================================================*
65 * arch_map2info *
66 *===========================================================================*/
67 PUBLIC vir_bytes arch_map2info(struct vmproc *vmp, vir_bytes addr, int *seg,
68 int *prot)
70 vir_bytes textstart = CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_phys);
71 vir_bytes textend = textstart +
72 CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_len);
73 vir_bytes datastart = CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys);
75 /* The protection to be returned here is that of the segment. */
76 if(addr < textstart) {
77 *seg = D;
78 *prot = PROT_READ | PROT_WRITE | PROT_EXEC;
79 return addr;
80 } else if(addr < datastart) {
81 *seg = T;
82 *prot = PROT_READ | PROT_EXEC;
83 return addr - textstart;
84 } else {
85 *seg = D;
86 if (textstart == textend) /* common I&D? */
87 *prot = PROT_READ | PROT_WRITE | PROT_EXEC;
88 else
89 *prot = PROT_READ | PROT_WRITE;
90 return addr - datastart;
94 /*===========================================================================*
95 * arch_addrok *
96 *===========================================================================*/
97 PUBLIC vir_bytes arch_addrok(struct vmproc *vmp, vir_bytes addr)
99 vir_bytes textstart = CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_phys);
100 vir_bytes textend = CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_phys +
101 vmp->vm_arch.vm_seg[T].mem_phys);
102 vir_bytes datastart = CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys);
104 if(addr >= textstart && addr < textstart+textend)
105 return 1;
107 if(addr >= datastart && addr < VM_DATATOP)
108 return 1;
110 return 0;
113 /*===========================================================================*
114 * arch_vir2map *
115 *===========================================================================*/
116 PUBLIC vir_bytes arch_vir2map(struct vmproc *vmp, vir_bytes addr)
118 vir_bytes bottom = CLICK2ABS(vmp->vm_arch.vm_seg[D].mem_phys);
120 return addr + bottom;
123 /*===========================================================================*
124 * arch_vir2map_text *
125 *===========================================================================*/
126 PUBLIC vir_bytes arch_vir2map_text(struct vmproc *vmp, vir_bytes addr)
128 vir_bytes bottom = CLICK2ABS(vmp->vm_arch.vm_seg[T].mem_phys);
130 return addr + bottom;