1 /* 2 * Copyright (c) 1991 Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * %sccs.include.redist.c% 9 * 10 * @(#)vm_param.h 7.6 (Berkeley) 10/11/92 11 * 12 * 13 * Copyright (c) 1987, 1990 Carnegie-Mellon University. 14 * All rights reserved. 15 * 16 * Authors: Avadis Tevanian, Jr., Michael Wayne Young 17 * 18 * Permission to use, copy, modify and distribute this software and 19 * its documentation is hereby granted, provided that both the copyright 20 * notice and this permission notice appear in all copies of the 21 * software, derivative works or modified versions, and any portions 22 * thereof, and that both notices appear in supporting documentation. 23 * 24 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 25 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 26 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 27 * 28 * Carnegie Mellon requests users of this software to return to 29 * 30 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 31 * School of Computer Science 32 * Carnegie Mellon University 33 * Pittsburgh PA 15213-3890 34 * 35 * any improvements or extensions that they make and grant Carnegie the 36 * rights to redistribute these changes. 37 */ 38 39 /* 40 * Machine independent virtual memory parameters. 41 */ 42 43 #ifndef _VM_PARAM_ 44 #define _VM_PARAM_ 45 46 #include <machine/vmparam.h> 47 48 /* 49 * This belongs in types.h, but breaks too many existing programs. 50 */ 51 typedef int boolean_t; 52 #define TRUE 1 53 #define FALSE 0 54 55 /* 56 * The machine independent pages are refered to as PAGES. A page 57 * is some number of hardware pages, depending on the target machine. 58 */ 59 #define DEFAULT_PAGE_SIZE 4096 60 61 /* 62 * All references to the size of a page should be done with PAGE_SIZE 63 * or PAGE_SHIFT. The fact they are variables is hidden here so that 64 * we can easily make them constant if we so desire. 65 */ 66 #define PAGE_SIZE cnt.v_page_size /* size of page */ 67 #define PAGE_MASK page_mask /* size of page - 1 */ 68 #define PAGE_SHIFT page_shift /* bits to shift for pages */ 69 #ifdef KERNEL 70 extern vm_size_t page_mask; 71 extern int page_shift; 72 #endif 73 74 75 /* 76 * Return values from the VM routines. 77 */ 78 #define KERN_SUCCESS 0 79 #define KERN_INVALID_ADDRESS 1 80 #define KERN_PROTECTION_FAILURE 2 81 #define KERN_NO_SPACE 3 82 #define KERN_INVALID_ARGUMENT 4 83 #define KERN_FAILURE 5 84 #define KERN_RESOURCE_SHORTAGE 6 85 #define KERN_NOT_RECEIVER 7 86 #define KERN_NO_ACCESS 8 87 88 #ifdef ASSEMBLER 89 #else ASSEMBLER 90 /* 91 * Convert addresses to pages and vice versa. 92 * No rounding is used. 93 */ 94 95 #ifdef KERNEL 96 #define atop(x) (((unsigned)(x)) >> PAGE_SHIFT) 97 #define ptoa(x) ((vm_offset_t)((x) << PAGE_SHIFT)) 98 #endif KERNEL 99 100 /* 101 * Round off or truncate to the nearest page. These will work 102 * for either addresses or counts. (i.e. 1 byte rounds to 1 page 103 * bytes. 104 */ 105 106 #ifdef KERNEL 107 #define round_page(x) \ 108 ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) & ~PAGE_MASK)) 109 #define trunc_page(x) \ 110 ((vm_offset_t)(((vm_offset_t)(x)) & ~PAGE_MASK)) 111 #define num_pages(x) \ 112 ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) >> PAGE_SHIFT)) 113 #else KERNEL 114 #define round_page(x) \ 115 ((((vm_offset_t)(x) + (vm_page_size - 1)) / vm_page_size) * vm_page_size) 116 #define trunc_page(x) \ 117 ((((vm_offset_t)(x)) / vm_page_size) * vm_page_size) 118 #endif KERNEL 119 120 #ifdef KERNEL 121 extern vm_size_t mem_size; /* size of physical memory (bytes) */ 122 extern vm_offset_t first_addr; /* first physical page */ 123 extern vm_offset_t last_addr; /* last physical page */ 124 #endif KERNEL 125 126 #endif ASSEMBLER 127 128 #endif _VM_PARAM_ 129