as.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2004 Jakub Jermar
00003  * All rights reserved.
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  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef __AS_H__
00036 #define __AS_H__
00037 
00039 #define AS_AREA_READ            1
00040 #define AS_AREA_WRITE           2
00041 #define AS_AREA_EXEC            4
00042 #define AS_AREA_CACHEABLE       8
00043 
00044 #ifdef KERNEL
00045 
00046 #include <arch/mm/page.h>
00047 #include <arch/mm/as.h>
00048 #include <arch/mm/asid.h>
00049 #include <arch/types.h>
00050 #include <typedefs.h>
00051 #include <synch/spinlock.h>
00052 #include <synch/mutex.h>
00053 #include <adt/list.h>
00054 #include <adt/btree.h>
00055 #include <elf.h>
00056 
00058 #define KERNEL_ADDRESS_SPACE_SHADOWED   KERNEL_ADDRESS_SPACE_SHADOWED_ARCH
00059 
00060 #define KERNEL_ADDRESS_SPACE_START      KERNEL_ADDRESS_SPACE_START_ARCH
00061 #define KERNEL_ADDRESS_SPACE_END        KERNEL_ADDRESS_SPACE_END_ARCH
00062 #define USER_ADDRESS_SPACE_START        USER_ADDRESS_SPACE_START_ARCH
00063 #define USER_ADDRESS_SPACE_END          USER_ADDRESS_SPACE_END_ARCH
00064 
00065 #define IS_KA(addr)     ((addr)>=KERNEL_ADDRESS_SPACE_START && (addr)<=KERNEL_ADDRESS_SPACE_END)
00066 
00067 #define USTACK_ADDRESS  USTACK_ADDRESS_ARCH
00068 
00069 #define FLAG_AS_KERNEL      (1 << 0)    
00078 struct as {
00079 
00080         link_t inactive_as_with_asid_link;
00081 
00082         mutex_t lock;
00083 
00085         count_t refcount;
00086 
00088         count_t cpu_refcount;
00089 
00091         btree_t as_area_btree;
00092 
00094         pte_t *page_table;
00095 
00097         asid_t asid;
00098 };
00099 
00100 struct as_operations {
00101         pte_t *(* page_table_create)(int flags);
00102         void (* page_table_destroy)(pte_t *page_table);
00103         void (* page_table_lock)(as_t *as, bool lock);
00104         void (* page_table_unlock)(as_t *as, bool unlock);
00105 };
00106 typedef struct as_operations as_operations_t;
00107 
00109 #define AS_AREA_ATTR_NONE       0
00110 #define AS_AREA_ATTR_PARTIAL    1       
00112 #define AS_PF_FAULT             0       
00113 #define AS_PF_OK                1       
00114 #define AS_PF_DEFER             2       
00118 typedef struct {
00119         mutex_t lock;           
00120         count_t refcount;       
00121         btree_t pagemap;        
00122 } share_info_t;
00123 
00125 typedef struct {
00126         int (* page_fault)(as_area_t *area, __address addr, pf_access_t access);
00127         void (* frame_free)(as_area_t *area, __address page, __address frame);
00128         void (* share)(as_area_t *area);
00129 } mem_backend_t;
00130 
00132 typedef union {
00133         struct {        
00134                 elf_header_t *elf;
00135                 elf_segment_header_t *segment;
00136         };
00137         struct {        
00138                 __address base;
00139                 count_t frames;
00140         };
00141 } mem_backend_data_t;
00142 
00148 struct as_area {
00149         mutex_t lock;
00150         as_t *as;               
00151         int flags;              
00152         int attributes;         
00153         count_t pages;          
00154         __address base;         
00155         btree_t used_space;     
00156         share_info_t *sh_info;  
00158         mem_backend_t *backend; 
00161         mem_backend_data_t backend_data;
00162 };
00163 
00164 extern as_t *AS_KERNEL;
00165 extern as_operations_t *as_operations;
00166 
00167 extern spinlock_t inactive_as_with_asid_lock;
00168 extern link_t inactive_as_with_asid_head;
00169 
00170 extern void as_init(void);
00171 
00172 extern as_t *as_create(int flags);
00173 extern void as_destroy(as_t *as);
00174 extern void as_switch(as_t *old, as_t *new);
00175 extern int as_page_fault(__address page, pf_access_t access, istate_t *istate);
00176 
00177 extern as_area_t *as_area_create(as_t *as, int flags, size_t size, __address base, int attrs,
00178         mem_backend_t *backend, mem_backend_data_t *backend_data);
00179 extern int as_area_destroy(as_t *as, __address address);        
00180 extern int as_area_resize(as_t *as, __address address, size_t size, int flags);
00181 int as_area_share(as_t *src_as, __address src_base, size_t acc_size,
00182                   as_t *dst_as, __address dst_base, int dst_flags_mask);
00183 
00184 extern int as_area_get_flags(as_area_t *area);
00185 extern bool as_area_check_access(as_area_t *area, pf_access_t access);
00186 extern size_t as_get_size(__address base);
00187 extern int used_space_insert(as_area_t *a, __address page, count_t count);
00188 extern int used_space_remove(as_area_t *a, __address page, count_t count);
00189 
00190 /* Interface to be implemented by architectures. */
00191 #ifndef as_install_arch
00192 extern void as_install_arch(as_t *as);
00193 #endif /* !def as_install_arch */
00194 
00195 /* Backend declarations. */
00196 extern mem_backend_t anon_backend;
00197 extern mem_backend_t elf_backend;
00198 extern mem_backend_t phys_backend;
00199 
00200 /* Address space area related syscalls. */
00201 extern __native sys_as_area_create(__address address, size_t size, int flags);
00202 extern __native sys_as_area_resize(__address address, size_t size, int flags);
00203 extern __native sys_as_area_destroy(__address address);
00204 
00205 #endif /* KERNEL */
00206 
00207 #endif
00208 

Generated on Sun Jun 18 17:28:03 2006 for HelenOS Kernel (ppc64) by  doxygen 1.4.6