00001 00007 /* 00008 * Copyright (C) 2004 Bregmasoft 00009 * 00010 * This program is free software; you can redistribute it and/or modify it under 00011 * the terms of the GNU General Public License as published by the Free Software 00012 * Foundation; either version 2 of the License, or (at your option) any later 00013 * version. 00014 * 00015 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 00016 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 00017 * PARTICULAR PURPOSE. See the GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License along with 00020 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 * Place, Suite 330, Boston, MA 02111-1307 USA 00022 */ 00023 #ifndef ZYGOMA_MEMORY_H_ 00024 #define ZYGOMA_MEMORY_H_ 00025 00026 #include <arch/memory.h> 00027 #include <arch.h> 00028 #include <iterator> 00029 00030 namespace Zygoma 00031 { 00045 typedef Arch::PhysicalAddress PhysicalAddress; 00046 00055 using Arch::PAGE_FRAME_SIZE; 00056 00057 00066 template<int stride> 00067 class MemoryStrider 00068 : public std::iterator<std::forward_iterator_tag, const PhysicalAddress> 00069 { 00070 public: 00075 MemoryStrider(PhysicalAddress start = 0) 00076 : m_curAddress(start) 00077 { } 00078 00084 reference 00085 operator*() const 00086 { return m_curAddress; } 00087 00095 MemoryStrider& 00096 operator++() 00097 { 00098 m_curAddress += stride; 00099 return *this; 00100 } 00101 00109 MemoryStrider& 00110 operator++(int) 00111 { 00112 PhysicalAddress oldAddress = *this; 00113 m_curAddress += stride; 00114 return oldAddress; 00115 } 00116 00117 private: 00118 PhysicalAddress m_curAddress; 00119 }; 00120 00121 00135 template<int stride> 00136 inline bool 00137 operator==(const MemoryStrider<stride>& lhs, 00138 const MemoryStrider<stride>& rhs) 00139 { return *lhs == *rhs; } 00140 00150 template<int stride> 00151 inline bool 00152 operator!=(const MemoryStrider<stride>& lhs, 00153 const MemoryStrider<stride>& rhs) 00154 { return *lhs != *rhs; } 00155 00156 00165 template<int stride> 00166 class MemoryRange 00167 { 00168 public: 00169 typedef MemoryStrider<stride> iterator; 00170 00171 public: 00178 MemoryRange(PhysicalAddress start, PhysicalAddress size) 00179 : m_start(start) 00180 , m_size(size) 00181 { } 00182 00186 iterator 00187 begin() const 00188 { return m_start; } 00189 00196 iterator 00197 end() const 00198 { return m_start + m_size; } 00199 00200 private: 00201 PhysicalAddress m_start; 00202 PhysicalAddress m_size; 00203 }; 00204 } // namespace Zygoma 00205 00206 #endif // ZYGOMA_MEMORY_H_