|
From: Daniel R. <co...@us...> - 2006-10-19 17:50:51
|
Update of /cvsroot/trion/trion v0.2/object In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv12544 Modified Files: list.cpp list.hpp std_types.hpp tree.cpp tree.hpp Added Files: allocator.cpp allocator.hpp physical_memory.cpp physical_memory.hpp virtual_memory.cpp virtual_memory.hpp Removed Files: pager.cpp pager.hpp phys_allocator.cpp phys_allocator.hpp Log Message: no message --- pager.hpp DELETED --- --- NEW FILE: virtual_memory.hpp --- // ----------------------------------------------------------------------- // virtual_memory.hpp - 4kb virtual memory allocator // // Author(s) : // Date : MM/DD/2006 // Version : 0.2.0 // Home Page : http://trion.sourceforge.net // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- // Copyright (C) 2006, Trion Development Group Members // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // 3. Neither the name of the Trion Development Group nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ----------------------------------------------------------------------- #ifndef __OBJECTS__VIRTUAL_ALLOCATOR__ #define __OBJECTS__VIRTUAL_ALLOCATOR__ #include <std_types.hpp> struct memory_node { u32b address, length; memory_node* next, *prev; }; class iterator { private: memory_node* node; public: iterator(memory_node* initial_node); bool operator==(iterator compare); bool operator!=(iterator compare); iterator& operator++(); iterator operator++(int); iterator& operator--(); iterator operator--(int); memory_node* operator->(); memory_node* operator*(); }; class memory_pool { private: memory_node* node_list; public: memory_pool(u32b initial_area, u16b number_pages = 1); memory_node* AllocateNode(); memory_node* DelocateNode(memory_node* node); }; class memory_list { private: memory_node* node_list; memory_pool pool; public: memory_list(u32b virtual_base); iterator CreateNode(u32b base, u32b size = 0); iterator DeleteNode(iterator it); iterator Search(u32b minimum_size); }; class virtual_memory { private: memory_list list; public: virtual_memory(u32b initial_area); u32b AllocatePage(u16b number_pages = 1); void DelocatePage(u32b base_address, u16b number_pages = 1); }; virtual_memory& InitializeVirtAllocator(u32b initial_area); virtual_memory& virt_allocator(); #endif --- NEW FILE: virtual_memory.cpp --- // ----------------------------------------------------------------------- // virtual_memory.cpp - 4kb virtual memory allocator // // Author(s) : // Date : MM/DD/2006 // Version : 0.2.0 // Home Page : http://trion.sourceforge.net // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- // Copyright (C) 2006, Trion Development Group Members // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // 3. Neither the name of the Trion Development Group nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ----------------------------------------------------------------------- #include <virtual_memory.hpp> #include <physical_memory.hpp> #include <std_types.hpp> #include <cpu_node.hpp> #include <console.hpp> #include <mmu.hpp> iterator::iterator(memory_node* initial_node) : node(initial_node) {} bool iterator::operator==(iterator compare) { return (this->node == compare.node) ? true : false; } bool iterator::operator!=(iterator compare) { return (this->node != compare.node) ? true : false; } iterator& iterator::operator++() { node = node->next; return *this; } iterator iterator::operator++(int) { return iterator(node->next); } iterator& iterator::operator--() { node = node->prev; return *this; } iterator iterator::operator--(int) { return iterator(node->prev); } memory_node* iterator::operator->() { return node; } memory_node* iterator::operator*() { return node; } memory_pool::memory_pool(u32b initial_area, u16b number_pages) { // Use the first n pages to create a pool of empty nodes for(u16b i=0; i < number_pages; i++) { u32b phys_address = phys_allocator().AllocatePage(); u32b virt_address = initial_area + 4096*i; Node(Memory)(virt_address) = map_item(phys_address); } // Append all empty nodes to our internal node list node_list = reinterpret_cast<memory_node*>(initial_area); node_list->prev = node_list->next = 0; for(u16b i=1; i < (number_pages*4096)/(sizeof(memory_node)); i++) { memory_node* node = reinterpret_cast<memory_node*>(initial_area); node[i].next = node_list; node[i].prev = 0; node_list = node_list->prev = node+i; } } memory_node* memory_pool::AllocateNode() { Assert(node_list!= 0, "Virtual memory manager ran out of list nodes"); memory_node* node = node_list; node_list = node->next; if(node_list != 0) node_list->prev = 0; return node; } memory_node* memory_pool::DelocateNode(memory_node* node) { node->next = node_list; node->prev = 0; return node_list = node_list->prev = node; } memory_list::memory_list(u32b virtual_base) : pool(virtual_base), node_list(0) { // Initialize the list by inserting a node for the 512 MiB of kernel-space memory_node* node = node_list = pool.AllocateNode(); node->prev = node->next = 0; node->address = virtual_base + 4096; node->length = 0x1FFFF000; } iterator memory_list::CreateNode(u32b base, u32b size) { // Insert a node into the sorted list (without further checks) iterator current(node_list); while(base > current->address) current++; memory_node* node = pool.AllocateNode(); iterator next_node = current; iterator prev_node = current--; if(prev_node != 0 && next_node != 0) { prev_node->next = node; next_node->prev = node; node->prev = *prev_node; node->next = *next_node; } else { next_node->prev = node; node->next = *next_node; node->prev = 0; node_list = node; } return iterator(node); } iterator memory_list::DeleteNode(iterator it) { iterator next_node = it++; iterator prev_node = it--; if(prev_node != 0 && next_node != 0) { prev_node->next = it->next; next_node->prev = it->prev; } else { node_list = *next_node; next_node->prev = 0; } pool.DelocateNode(*it); return next_node; } iterator memory_list::Search(u32b minimum_size) { iterator current(node_list); while(current != 0 && minimum_size > current->length) current++; return current; } virtual_memory::virtual_memory(u32b initial_area) : list(initial_area) {} u32b virtual_memory::AllocatePage(u16b number_pages) { u32b minimum_size = 4096*number_pages; iterator node = list.Search(minimum_size); Assert(node != 0, "Virtual memory manager couldn't allocate page"); u32b address = node->address; node->address += minimum_size; node->length -= minimum_size; if(node->length == 0) list.DeleteNode(node); return address; } void virtual_memory::DelocatePage(u32b base_address, u16b number_pages) { iterator current = list.CreateNode(base_address, 4096*number_pages); iterator next = current++; iterator prev = current--; if(prev != 0 && current->address == prev->address + prev->length) { current->address = prev->address; current->length += prev->length; list.DeleteNode(prev); } if(next != 0 && current->address + current->length == next->address) { current->length += next->length; list.DeleteNode(next); } } u08b virtual_memory_reserved[sizeof(virtual_memory)]; virtual_memory& InitializeVirtAllocator(u32b initial_area) { new (virtual_memory_reserved) virtual_memory(initial_area); return reinterpret_cast<virtual_memory&>(virtual_memory_reserved); } virtual_memory& virt_allocator() { return reinterpret_cast<virtual_memory&>(virtual_memory_reserved); } --- NEW FILE: physical_memory.cpp --- // ----------------------------------------------------------------------- // physical_memory.cpp - 4kb physical memory allocator // // Author(s) : // Date : MM/DD/2006 // Version : 0.2.0 // Home Page : http://trion.sourceforge.net // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- // Copyright (C) 2006, Trion Development Group Members // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // 3. Neither the name of the Trion Development Group nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ----------------------------------------------------------------------- #include <physical_memory.hpp> #include <console.hpp> physical_memory::physical_memory(u32b heap_begin) { // Initialize the stack with sequential addresses for(u08b i=0; i<16; i++) stack[i] = heap_begin + 4096*i; stack_pointer = 0, stack_underflow = 16; // first and last+1 element } u32b physical_memory::AllocatePage() { Assert(stack_pointer != stack_underflow, "Physical allocator ran out of memory"); return stack[stack_pointer++]; } void physical_memory::DelocatePage(u32b base_address) { stack[--stack_pointer] = base_address; } u08b physical_memory_reserved[sizeof(physical_memory)]; physical_memory& phys_allocator() { return reinterpret_cast<physical_memory&>(physical_memory_reserved); } physical_memory& InitializePhysAllocator(u32b initial_area) { new (physical_memory_reserved) physical_memory(initial_area); return reinterpret_cast<physical_memory&>(physical_memory_reserved); } --- NEW FILE: physical_memory.hpp --- // ----------------------------------------------------------------------- // physical_memory.hpp - 4kb physical memory allocator // // Author(s) : // Date : MM/DD/2006 // Version : 0.2.0 // Home Page : http://trion.sourceforge.net // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- // Copyright (C) 2006, Trion Development Group Members // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // 3. Neither the name of the Trion Development Group nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ----------------------------------------------------------------------- #ifndef __OBJECTS__PHYSICAL_ALLOCATOR__ #define __OBJECTS__PHYSICAL_ALLOCATOR__ #include <std_types.hpp> class physical_memory { private: u16b stack_pointer, stack_underflow; u32b stack[16]; public: physical_memory(u32b initial_area); u32b AllocatePage(); void DelocatePage(u32b base_address); }; physical_memory& InitializePhysAllocator(u32b initial_area); physical_memory& phys_allocator(); #endif Index: tree.cpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/object/tree.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** tree.cpp 7 Jan 2006 16:39:38 -0000 1.1.1.1 --- tree.cpp 19 Oct 2006 17:50:47 -0000 1.2 *************** *** 9,13 **** // ----------------------------------------------------------------------- ! // Copyright (C) 2003, Trion Development Group Members // All rights reserved. // --- 9,13 ---- // ----------------------------------------------------------------------- ! // Copyright (C) 2006, Trion Development Group Members // All rights reserved. // Index: list.cpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/object/list.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** list.cpp 7 Jan 2006 16:39:36 -0000 1.1.1.1 --- list.cpp 19 Oct 2006 17:50:47 -0000 1.2 *************** *** 9,13 **** // ----------------------------------------------------------------------- ! // Copyright (C) 2003, Trion Development Group Members // All rights reserved. // --- 9,13 ---- // ----------------------------------------------------------------------- ! // Copyright (C) 2006, Trion Development Group Members // All rights reserved. // Index: std_types.hpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/object/std_types.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** std_types.hpp 24 Jun 2006 15:01:46 -0000 1.3 --- std_types.hpp 19 Oct 2006 17:50:47 -0000 1.4 *************** *** 78,81 **** --- 78,96 ---- }; + /** Allow a 64bit wide bitfield to be accessed like an ordinary long integer */ + template<class T> struct bf64 + { + private: + union { u64b integer; T bitfield; }; + + public: + bf64(u64b value) : integer(value) {}; // Allows initialization with an integer + + operator u64b() { return integer; } // Default conversation to an integer + operator T&() { return bitfield; } // Conversation to the bitfield type + + T* operator->() { return &bitfield; } // Access to the members of the bitfield + }; + /** Some very basic operations to initialize and copy memory ranges */ template<class T> void memset(T* begin, T* end, const T& value) Index: list.hpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/object/list.hpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** list.hpp 7 Jan 2006 16:39:37 -0000 1.1.1.1 --- list.hpp 19 Oct 2006 17:50:47 -0000 1.2 *************** *** 9,13 **** // ----------------------------------------------------------------------- ! // Copyright (C) 2003, Trion Development Group Members // All rights reserved. // --- 9,13 ---- // ----------------------------------------------------------------------- ! // Copyright (C) 2006, Trion Development Group Members // All rights reserved. // *************** *** 38,74 **** // ----------------------------------------------------------------------- ! #ifndef __OBJECT_CLASSES__LIST__ ! #define __OBJECT_CLASSES__LIST__ ! #include <pager.hpp> ! template<typename TYPE> struct Listnode { ! Listnode* prev, *next; ! ! TYPE data; }; ! template<typename TYPE> class list { private: ! void* object; ! void* first_used, *last_used; ! int number_used; ! iterator GetPrevNode(iterator it); ! iterator GetNextNode(iterator it); public: ! list(int max_nodes, void* object = 0); ~list(); ! bool InsertNode(iterator it); ! bool RemoveNode(iterator it); ! TYPE* GetNode(iterator it); ! iterator Find(bool (*function_pointer) (TYPE*)); }; --- 38,107 ---- // ----------------------------------------------------------------------- ! #ifndef __OBJECTS__LIST__ ! #define __OBJECTS__LIST__ ! #include <std_types.hpp> ! template<class TYPE> struct list_node { ! list_node* next, *prev; ! TYPE node_data; }; ! template<class TYPE> class iterator { + typedef list_node<TYPE> node; + private: ! node* element_pointer; ! public: ! iterator(node* element); ! iterator(); ! bool operator==(iterator it); ! bool operator!=(iterator it); ! ! TYPE& operator* (); ! TYPE* operator->(); ! ! iterator& operator++(); ! iterator operator++(int t); ! ! iterator& operator--(); ! iterator operator--(int t); ! }; ! ! template<class TYPE, class ALLOC = allocator<TYPE> > ! class list ! { ! typedef list_node<TYPE> node; ! ! private: ! node* first_element, *last_element; ! u32b number_elements; public: ! list(); ~list(); ! iterator begin(); ! iterator end(); ! TYPE& front(); ! TYPE& back(); ! void push_front(TYPE& node); ! void push_back (TYPE& node); ! ! void pop_front(); ! void pop_back(); ! ! iterator insert(iterator position, TYPE& value); ! ! iterator erase(iterator position); ! iterator erase(iterator first, iterator last); ! ! u32b size(); }; Index: tree.hpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/object/tree.hpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** tree.hpp 7 Jan 2006 16:39:38 -0000 1.1.1.1 --- tree.hpp 19 Oct 2006 17:50:47 -0000 1.2 *************** *** 9,13 **** // ----------------------------------------------------------------------- ! // Copyright (C) 2003, Trion Development Group Members // All rights reserved. // --- 9,13 ---- // ----------------------------------------------------------------------- ! // Copyright (C) 2006, Trion Development Group Members // All rights reserved. // *************** *** 38,43 **** // ----------------------------------------------------------------------- ! #ifndef __OBJECT_CLASSES__TREE__ ! #define __OBJECT_CLASSES__TREE__ #include <pager.hpp> --- 38,43 ---- // ----------------------------------------------------------------------- ! #ifndef __OBJECTS__TREE__ ! #define __OBJECTS__TREE__ #include <pager.hpp> --- phys_allocator.cpp DELETED --- --- phys_allocator.hpp DELETED --- --- NEW FILE: allocator.cpp --- // ----------------------------------------------------------------------- // allocator.hpp - 4kb allocator for kernel objects // // Author(s) : // Date : MM/DD/2006 // Version : 0.2.0 // Home Page : http://trion.sourceforge.net // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- // Copyright (C) 2006, Trion Development Group Members // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // 3. Neither the name of the Trion Development Group nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ----------------------------------------------------------------------- #include <allocator.hpp> --- NEW FILE: allocator.hpp --- // ----------------------------------------------------------------------- // allocator.hpp - 4kb allocator for kernel objects // // Author(s) : // Date : MM/DD/2006 // Version : 0.2.0 // Home Page : http://trion.sourceforge.net // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- // Copyright (C) 2006, Trion Development Group Members // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // 3. Neither the name of the Trion Development Group nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ----------------------------------------------------------------------- #ifndef __OBJECTS__ALLOCATOR__ #define __OBJECTS__ALLOCATOR__ #include <physical_memory.hpp> #include <virtual_memory.hpp> #include <std_types.hpp> struct object_header { u32b available_slots; u32b block_address[0x3fe]; object_header* next; }; template<class TYPE> struct allocator_node { allocator_node* next, *prev; TYPE node_data; }; template<class TYPE> class allocator { typedef allocator_node<TYPE> node; private: static object_header* header; static node* available_nodes; static u32b number_available; bool AppendHeaderBlock(); bool RemoveHeaderBlock(); bool AppendNodeBlock(); bool RemoveNodeBlock(); public: allocator(); ~allocator(); TYPE* Allocate(u32b number = 1); void Delocate(TYPE* object, u32b number = 1); }; #endif --- pager.cpp DELETED --- |