00001 /* 00002 * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009 00003 * The President and Fellows of Harvard College. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the University nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 */ 00029 00030 #ifndef _ADDRSPACE_H_ 00031 #define _ADDRSPACE_H_ 00032 00033 /* 00034 * Address space structure and operations. 00035 */ 00036 00037 00038 #include <vm.h> 00039 00040 struct vnode; 00041 00042 00043 /* 00044 * Address space - data structure associated with the virtual memory 00045 * space of a process. 00046 * 00047 * You write this. 00048 */ 00049 00050 struct addrspace { 00051 vaddr_t as_vbase1; 00052 paddr_t as_pbase1; 00053 size_t as_npages1; 00054 vaddr_t as_vbase2; 00055 paddr_t as_pbase2; 00056 size_t as_npages2; 00057 paddr_t as_stackpbase; 00058 }; 00059 00060 /* 00061 * Functions in addrspace.c: 00062 * 00063 * as_create - create a new empty address space. You need to make 00064 * sure this gets called in all the right places. You 00065 * may find you want to change the argument list. May 00066 * return NULL on out-of-memory error. 00067 * 00068 * as_copy - create a new address space that is an exact copy of 00069 * an old one. Probably calls as_create to get a new 00070 * empty address space and fill it in, but that's up to 00071 * you. 00072 * 00073 * as_activate - make curproc's address space the one currently 00074 * "seen" by the processor. 00075 * 00076 * as_deactivate - unload curproc's address space so it isn't 00077 * currently "seen" by the processor. 00078 * 00079 * as_destroy - dispose of an address space. You may need to change 00080 * the way this works if implementing user-level threads. 00081 * 00082 * as_define_region - set up a region of memory within the address 00083 * space. 00084 * 00085 * as_prepare_load - this is called before actually loading from an 00086 * executable into the address space. 00087 * 00088 * as_complete_load - this is called when loading from an executable 00089 * is complete. 00090 * 00091 * as_define_stack - set up the stack region in the address space. 00092 * (Normally called *after* as_complete_load().) Hands 00093 * back the initial stack pointer for the new process. 00094 */ 00095 00096 struct addrspace *as_create(void); 00097 int as_copy(struct addrspace *src, struct addrspace **ret); 00098 void as_activate(void); 00099 void as_deactivate(void); 00100 void as_destroy(struct addrspace *); 00101 00102 int as_define_region(struct addrspace *as, 00103 vaddr_t vaddr, size_t sz, 00104 int readable, 00105 int writeable, 00106 int executable); 00107 int as_prepare_load(struct addrspace *as); 00108 int as_complete_load(struct addrspace *as); 00109 int as_define_stack(struct addrspace *as, vaddr_t *initstackptr); 00110 00111 00112 /* 00113 * Functions in loadelf.c 00114 * load_elf - load an ELF user program executable into the current 00115 * address space. Returns the entry point (initial PC) 00116 * in the space pointed to by ENTRYPOINT. 00117 */ 00118 00119 int load_elf(struct vnode *v, vaddr_t *entrypoint); 00120 00121 00122 #endif /* _ADDRSPACE_H_ */