/*1* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 20092* The President and Fellows of Harvard College.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the University nor the names of its contributors13* may be used to endorse or promote products derived from this software14* without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#ifndef _ADDRSPACE_H_30#define _ADDRSPACE_H_3132/*33* Address space structure and operations.34*/353637#include <vm.h>38#include <vm/region.h>39#include "opt-dumbvm.h"4041struct vnode;424344/*45* Address space - data structure associated with the virtual memory46* space of a process.47*48* You write this.49*/5051struct addrspace {52#if OPT_DUMBVM53vaddr_t as_vbase1;54paddr_t as_pbase1;55size_t as_npages1;56vaddr_t as_vbase2;57paddr_t as_pbase2;58size_t as_npages2;59paddr_t as_stackpbase;60#else61struct vm_region_array *as_regions;62vaddr_t as_heap_start;63vaddr_t as_heap_end;64#endif65};6667/*68* Functions in addrspace.c:69*70* as_create - create a new empty address space. You need to make71* sure this gets called in all the right places. You72* may find you want to change the argument list. May73* return NULL on out-of-memory error.74*75* as_copy - create a new address space that is an exact copy of76* an old one. Probably calls as_create to get a new77* empty address space and fill it in, but that's up to78* you.79*80* as_activate - make the specified address space the one currently81* "seen" by the processor. Argument might be NULL,82* meaning "no particular address space".83*84* as_destroy - dispose of an address space. You may need to change85* the way this works if implementing user-level threads.86*87* as_define_region - set up a region of memory within the address88* space.89*90* as_prepare_load - this is called before actually loading from an91* executable into the address space.92*93* as_complete_load - this is called when loading from an executable94* is complete.95*96* as_define_stack - set up the stack region in the address space.97* (Normally called *after* as_complete_load().) Hands98* back the initial stack pointer for the new process.99*/100101struct addrspace *as_create(void);102int as_copy(struct addrspace *src, struct addrspace **ret);103void as_activate(struct addrspace *);104void as_destroy(struct addrspace *);105106int as_define_region(struct addrspace *as,107vaddr_t vaddr, size_t sz,108int readable,109int writeable,110int executable);111int as_prepare_load(struct addrspace *as);112int as_complete_load(struct addrspace *as);113int as_define_stack(struct addrspace *as, vaddr_t *initstackptr);114115int as_fault( struct addrspace *, int, vaddr_t );116117118/*119* Functions in loadelf.c120* load_elf - load an ELF user program executable into the current121* address space. Returns the entry point (initial PC)122* in the space pointed to by ENTRYPOINT.123*/124125int load_elf(struct vnode *v, vaddr_t *entrypoint);126127128#endif /* _ADDRSPACE_H_ */129130131