00001
00002
00003 #ifndef mem_layout_h
00004 #define mem_layout_h
00005
00006 #include "types.h"
00007
00008 #include "types.h"
00009
00010
00011
00012
00013
00014
00015 class Mem_layout
00016 {
00017 public:
00019 static const char load asm ("_load");
00020 static const char start asm ("_start");
00021 static const char end asm ("_end");
00022 static const char ecode asm ("_ecode");
00023 static const char etext asm ("_etext");
00024 static const char edata asm ("_edata");
00025 static const char initcall_start asm ("_initcall_start");
00026 static const char initcall_end asm ("_initcall_end");
00027
00028 static Mword in_tcbs (Address a);
00029 static Mword in_kernel (Address a);
00030 private:
00031
00032 public:
00033 enum
00034 {
00035 V2_utcb_addr = 0xbff00000,
00036 Kip_auto_map = 0xbfff2000,
00037 User_max = 0xc0000000,
00038 Vmem_start = User_max,
00039 Tcbs = 0xc0000000,
00040 Tcbs_end = 0xe0000000,
00041 Slabs_start = 0xe0000000,
00042 Slabs_end = 0xea000000,
00043 Space_index = 0xea000000,
00044 Chief_index = 0xea400000,
00045 Kip_index = 0xea800000,
00046 Service_page = 0xeac00000,
00047 Local_apic_page = Service_page + 0x0000,
00048 Jdb_adapter_page = Service_page + 0x1000,
00049 Tbuf_status_page = Service_page + 0x2000,
00050 Smas_trampoline = Service_page + 0x3000,
00051 Jdb_bench_page = Service_page + 0x4000,
00052 Utcb_ptr_page = Service_page + 0xfd000,
00053 Idt = Service_page + 0xfe000,
00054 Syscalls = Service_page + 0xff000,
00055 Tbuf_buffer_area = Service_page + 0x200000,
00056 Ldt_addr = 0xeb000000,
00057 Ldt_size = 0xeb400000,
00058
00059 Smas_version = 0xec000000,
00060 Smas_area = 0xec400000,
00061 Smas_io_bmap_bak = 0xec800000,
00062 Smas_io_cnt_bak = 0xec880000,
00063 Jdb_debug_start = 0xecc00000,
00064 Jdb_debug_end = 0xee000000,
00065 Ipc_window0 = 0xee000000,
00066 Ipc_window1 = 0xee800000,
00067
00068 Kstatic = 0xef800000,
00069 Io_bitmap = 0xefc00000,
00070 Io_counter = 0xefc80000,
00071 Vmem_end = 0xf0000000,
00072 Kernel_image = Vmem_end,
00073 Boot_state_start = Kernel_image,
00074 Boot_state_end = Kernel_image + 0x400000,
00075 Smas_start = 0xf0400000,
00076 Smas_end = 0xfc400000,
00077 Physmem = 0xfc400000,
00078 };
00079
00080 template < typename T > static T* boot_data (T const *addr);
00081
00082 private:
00083 static Address physmem_offs asm ("PHYSMEM_OFFS");
00084
00085 public:
00086 static inline Mword in_kernel_code(Address a);
00087
00088 static inline void kphys_base(Address base);
00089
00090 static inline Address pmem_to_phys(Address addr);
00091
00092 static inline Address pmem_to_phys(const void *ptr);
00093
00094 static inline Address phys_to_pmem(Address addr);
00095
00096 static inline Mword in_boot_state(Address addr);
00097
00098 static inline Mword in_pmem(Address addr);
00099 };
00100
00101
00102
00103
00104
00105
00106 #include <cassert>
00107
00108
00109
00110
00111
00112
00113
00114
00115 inline Mword
00116 Mem_layout::in_kernel_code(Address a)
00117 {
00118 return a >= (Address)&start && a < (Address)&ecode;
00119 }
00120
00121
00122
00123 inline void
00124 Mem_layout::kphys_base(Address base)
00125 {
00126 physmem_offs = (Address)Physmem - base;
00127 }
00128
00129
00130
00131 inline Address
00132 Mem_layout::pmem_to_phys(Address addr)
00133 {
00134 assert (in_pmem(addr));
00135 return addr - physmem_offs;
00136 }
00137
00138
00139
00140 inline Address
00141 Mem_layout::pmem_to_phys(const void *ptr)
00142 {
00143 Address addr = reinterpret_cast<Address>(ptr);
00144
00145 assert (in_pmem(addr));
00146 return addr - physmem_offs;
00147 }
00148
00149
00150
00151 inline Address
00152 Mem_layout::phys_to_pmem(Address addr)
00153 {
00154 return addr + physmem_offs;
00155 }
00156
00157
00158
00159 inline Mword
00160 Mem_layout::in_boot_state(Address addr)
00161 {
00162 return addr >= Boot_state_start && addr < Boot_state_end;
00163 }
00164
00165
00166
00167 inline Mword
00168 Mem_layout::in_pmem(Address addr)
00169 {
00170 return addr >= Physmem;
00171 }
00172
00173
00174
00175 inline Mword
00176 Mem_layout::in_tcbs(Address a)
00177 {
00178 return a >= Tcbs && a < Tcbs_end;
00179 }
00180
00181
00182
00183 inline Mword
00184 Mem_layout::in_kernel(Address a)
00185 {
00186 return a >= User_max;
00187 }
00188
00189
00190
00191 template < typename T > inline T*
00192 Mem_layout::boot_data(T const *addr)
00193 {
00194
00195 assert ((Address)addr < 4<<20);
00196 return (T*) ((Address)addr + Boot_state_start);
00197 }
00198
00199 #endif // mem_layout_h