From: Daniel R. <co...@us...> - 2006-10-19 17:48:40
|
Update of /cvsroot/trion/trion v0.2/hal In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11597 Modified Files: mmu.cpp mmu.hpp mutex.cpp mutex.hpp Log Message: no message Index: mmu.cpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/hal/mmu.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** mmu.cpp 24 Jun 2006 15:00:02 -0000 1.7 --- mmu.cpp 19 Oct 2006 17:48:34 -0000 1.8 *************** *** 40,59 **** #include <mmu.hpp> ! map_item::map_item(u32b init): entry(init), zero_tables(true) {} ! map_item::map_item(bf32<page_structure> init) : entry(init) {} ! ! map_item& map_item::Physical(u32b address) { ! entry->physical = address >> 12; ! return *this; } ! map_item& map_item::Write() { entry->read_write = true; return *this; } ! map_item& map_item::UserMode() { entry->user_mode = true; return *this; } ! map_item& map_item::Pages4MB() { entry->PAT2 = true; return *this; } ! map_item& map_item::Global() { entry->global = true; return *this; } ! map_item& map_item::Present() { entry->present = true; return *this; } ! map_item& map_item::PAT(u08b number) { entry->PAT0 = number &0x01; --- 40,62 ---- #include <mmu.hpp> ! map_item::map_item(u32b physical) : entry(0) { ! if(physical != 0) ! { ! entry->physical = physical >> 12; ! entry->present = entry->read_write = true; ! } } ! u32b map_item::Physical() { return entry->physical << 12; } ! u08b map_item::Caching () { return entry->PAT0 << 0 | entry->PAT1 << 1 | entry->PAT2 << 2; } ! bool map_item::Modify() { return entry->read_write; } ! bool map_item::Global() { return entry->global; } ! bool map_item::Kernel() { return entry->user_mode; } ! ! map_item& map_item::Physical(u32b address) { entry->physical = address >> 12; return *this; } ! ! map_item& map_item::Caching (u08b number) { entry->PAT0 = number &0x01; *************** *** 64,245 **** } ! map_item& map_item::operator()(u32b physical) ! { ! Physical(physical); ! return *this; ! } ! map_target::map_target(u16b table, u16b page, bool page_table) { table_number = table; page_number = page; - - is_table = page_table; } ! void map_target::InvalidatePage(u32b address) { ! asm("invlpg (%%eax)" : : "a"(address)); } ! map_target& map_target::operator[](u32b index) ! { ! page_number = index; ! is_table = false; ! return *this; ! } ! map_target& map_target::operator=(map_item item) { ! u32b* table_map = reinterpret_cast<u32b*>(0xFFFFF000); ! u32b* page_map = reinterpret_cast<u32b*>(0xFFC00000); ! ! if(is_table) { ! // Insert the new page-table entry ! bf32<page_structure> entry = item.entry; ! entry->present = true; ! table_map[table_number] = entry; - - // Clear the table if required - if(item.zero_tables) - { - u32b first = table_number*4096; - memset(&page_map[first], &page_map[first+1024], u32b(0)); - } } else { ! // Insert the new page entry ! bf32<page_structure> entry = item.entry; ! entry->present = true; ! page_map[table_number*1024 + page_number] = entry; - - // Remove the old mapping from the TLB - InvalidatePage((table_number*1024 + page_number)*4096); } - return *this; } ! map_target& map_target::operator=(map_target target) { ! u32b* table_map = reinterpret_cast<u32b*>(0xFFFFF000); ! u32b* page_map = reinterpret_cast<u32b*>(0xFFC00000); ! ! if(is_table) { ! map_item flags = bf32<page_structure>(table_map[target.table_number]); ! flags.zero_tables = false; ! operator=(flags); } else { ! map_item flags = bf32<page_structure>(page_map[target.table_number*1024 + target.page_number]); ! operator=(flags); } - return *this; } ! map_target& map_target::operator+=(map_item item) ! { ! // Set additional flags for an existing page/page_table ! u32b* table_map = reinterpret_cast<u32b*>(0xFFFFF000); ! u32b* page_map = reinterpret_cast<u32b*>(0xFFC00000); ! if(is_table) ! { ! u32b entry = table_map[table_number]; ! entry |= item.entry; ! table_map[table_number] = entry; ! } ! else { ! u32b entry = page_map[table_number*1024 + page_number]; ! entry |= item.entry; ! page_map[table_number*1024 + page_number] = entry; ! } ! return *this; ! } ! map_target& map_target::operator-=(map_item item) ! { ! // Clear certain flags of an existing page/page_table ! u32b* table_map = reinterpret_cast<u32b*>(0xFFFFF000); ! u32b* page_map = reinterpret_cast<u32b*>(0xFFC00000); ! if(is_table) ! { ! u32b entry = table_map[table_number]; ! entry &= ~item.entry; ! table_map[table_number] = entry; } else { ! u32b entry = page_map[table_number*1024 + page_number]; ! entry &= ~item.entry; ! page_map[table_number*1024 + page_number] = entry; ! } ! return *this; ! } ! ! memory_mapper::memory_mapper(u32b directory) ! { ! if(directory != 0) pagedirectory = directory; // Access an exsisting page-directory ! ! // TODO - Create a new directory if required ! // TODO - Add support for extended PAT entries ! // TODO - Ensure multiprocessor TLB synchronisation ! } ! ! map_item memory_mapper::user_mode(u32b physical) { return map_item(0).Physical(physical).UserMode().Write();} ! map_item memory_mapper::user_read(u32b physical) { return map_item(0).Physical(physical).UserMode(); } ! ! map_item memory_mapper::kernel_mode(u32b physical) { return map_item(0).Physical(physical).Global().Write(); } ! map_item memory_mapper::kernel_read(u32b physical) { return map_item(0).Physical(physical).Global(); } ! map_item memory_mapper::device_regs(u32b physical) { return map_item(0).Physical(physical).PAT(3).Write(); } ! ! u32b* memory_mapper::CreateDirtyMap(u32b* map, u32b virtual_base, u32b number_pages) ! { ! u32b* page_map = reinterpret_cast<u32b*>(0xFFC00000); ! u32b page_base = virtual_base >> 12; ! ! for(u32b i=page_base; i < (page_base + number_pages); i++) ! { ! bf32<page_structure> entry = page_map[i]; ! ! u32b index = i/32; // Index of the dword within the map ! u08b offset = i%32; // Bit offset in the dword ! ! map[index] |= entry->dirty << offset; } - return map; } ! u32b* memory_mapper::CreateAccessedMap(u32b* map, u32b virtual_base, u32b number_pages) ! { ! u32b* page_map = reinterpret_cast<u32b*>(0xFFC00000); ! u32b page_base = virtual_base >> 12; ! ! for(u32b i=page_base; i < (page_base + number_pages); i++) ! { ! bf32<page_structure> entry = page_map[i]; ! ! u32b index = i/32; // Index of the dword within the map ! u08b offset = i%32; // Bit offset in the dword ! map[index] |= entry->accessed << offset; ! } ! return map; ! } ! map_target memory_mapper::operator[](u32b index) ! { ! return map_target(index, 0, true); ! } ! map_target memory_mapper::operator()(u32b address) ! { ! return map_target(address >> 22, (address >> 12)%1024, false); ! } --- 67,145 ---- } ! map_item& map_item::Modify(bool set) { entry->read_write = set; return *this; } ! map_item& map_item::Global(bool set) { entry->global = set; return *this; } ! map_item& map_item::Kernel(bool set) { entry->user_mode = set; return *this; } ! map_target::map_target(u16b table, u16b page) : page_table(true) { table_number = table; page_number = page; } ! map_target::map_target(u32b virtual_address) : page_table(false) { ! table_number = virtual_address >> 22; ! page_number = (virtual_address >> 12) % 1024; } ! void map_target::InvalidatePage(u32b address) { asm("invlpg (%0)" : : "r"(address)); } ! void map_target::SetMapping(u32b entry) { ! if(page_table == true) { ! u32b* table_map = reinterpret_cast<u32b*>(0xFFFFF000); table_map[table_number] = entry; } else { ! u32b* page_map = reinterpret_cast<u32b*>(0xFFC00000); page_map[table_number*1024 + page_number] = entry; } } ! u32b map_target::GetMapping() { ! if(page_table == true) { ! u32b* table_map = reinterpret_cast<u32b*>(0xFFFFF000); ! return table_map[table_number]; } else { ! u32b* page_map = reinterpret_cast<u32b*>(0xFFC00000); ! return page_map[table_number*1024 + page_number]; } } ! map_item map_target::operator->() { return map_item(bf32<page_structure>(GetMapping())); } ! void map_target::operator=(map_item item) ! { ! if(page_table == true) { ! u32b* page_map = reinterpret_cast<u32b*>(0xFFC00000); ! SetMapping(item.entry); ! // Initialize the page-table with all zeroes ! u32b first = table_number*1024; ! u32b last = table_number*1024 + 1024; ! memset(&page_map[first], &page_map[last], u32b(0)); } else { ! SetMapping(item.entry); ! InvalidatePage((table_number*1024 + page_number)*4096); } } ! void map_target::operator+=(map_item item) { SetMapping(GetMapping() | item.entry); } ! void map_target::operator-=(map_item item) { SetMapping(GetMapping() & ~item.entry); } ! memory_mapper::memory_mapper(u32b directory) : pagedirectory(directory) {} ! map_target memory_mapper::operator[](u32b index) { return map_target(index, 0); } ! map_target memory_mapper::operator()(u32b address) { return map_target(address); } ! void memory_mapper::SetPageDirectory(u32b directory) { asm("mov %0, %%cr3" : : "r"(directory)); } Index: mmu.hpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/hal/mmu.hpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** mmu.hpp 24 Jun 2006 15:00:02 -0000 1.5 --- mmu.hpp 19 Oct 2006 17:48:34 -0000 1.6 *************** *** 48,56 **** bool read_write : 1; bool user_mode : 1; ! bool PAT0 : 1; ! bool PAT1 : 1; bool accessed : 1; bool dirty : 1; ! bool PAT2 : 1; // 4MB pages bit for page-tables bool global : 1; bool : 3; --- 48,56 ---- bool read_write : 1; bool user_mode : 1; ! u08b PAT0 : 1; ! u08b PAT1 : 1; bool accessed : 1; bool dirty : 1; ! u08b PAT2 : 1; bool global : 1; bool : 3; *************** *** 60,84 **** class map_item { - private: friend class map_target; - bf32<page_structure> entry; ! bool zero_tables; // Set by default, must get uncheck before copying tables public: ! explicit map_item(u32b init = 0); ! map_item(bf32<page_structure> init); - // Modifiers to set additional flags map_item& Physical(u32b address); ! map_item& Write(); ! map_item& UserMode(); ! map_item& Pages4MB(); ! map_item& PAT(u08b number); ! map_item& Global(); ! map_item& Present(); ! // More convenient way of assigning an address ! map_item& operator()(u32b physical); }; --- 60,84 ---- class map_item { friend class map_target; ! private: bf32<page_structure> entry; public: ! map_item(bf32<page_structure> init) : entry(init) {} ! map_item(u32b physical=0); ! ! u32b Physical(); ! u08b Caching (); map_item& Physical(u32b address); ! map_item& Caching (u08b pat_number); ! bool Modify(); ! bool Global(); ! bool Kernel(); ! ! map_item& Modify(bool set = true); ! map_item& Global(bool set = true); ! map_item& Kernel(bool set = true); }; *************** *** 87,132 **** private: u16b table_number, page_number; ! bool is_table; void InvalidatePage(u32b address); public: ! map_target(u16b table, u16b page, bool page_table); ! map_target& operator[](u32b index); ! map_target& operator=(map_item item); // Assigns map_items to paging structures ! map_target& operator=(map_target target); // Allows the copying of pages/page-tables ! map_target& operator+=(map_item item); // Add or remove certain flags of the page ! map_target& operator-=(map_item item); }; class memory_mapper { ! private: ! u32b pagedirectory; // Physical address of the page-directory public: ! memory_mapper(u32b directory = 0); ! ~memory_mapper(); ! ! // Standard flag combinations that are often needed ! static map_item user_mode(u32b physical); ! static map_item user_read(u32b physical); ! ! static map_item kernel_mode(u32b physical); ! static map_item kernel_read(u32b physical); ! ! static map_item device_regs(u32b physical); ! ! // Dirty and accessed bits may be required by some user-mode pager ! u32b* CreateDirtyMap(u32b* map, u32b virtual_base, u32b number_pages); ! u32b* CreateAccessedMap(u32b* map, u32b virtual_base, u32b number_pages); ! u32b GetPageDirectory() { return pagedirectory; } // Used in conjunction with task_context ! map_target operator[](u32b index); // 2D access -> page_table : page_index ! map_target operator()(u32b address); // pages only -> absolute address }; --- 87,120 ---- private: u16b table_number, page_number; ! bool page_table; void InvalidatePage(u32b address); + void SetMapping(u32b entry); + u32b GetMapping(); + public: ! map_target(u16b table, u16b page); ! map_target(u32b virtual_address); ! map_item operator->(); ! void operator+=(map_item item); ! void operator-=(map_item item); ! void operator =(map_item item); }; class memory_mapper { ! private: u32b pagedirectory; public: ! memory_mapper(u32b directory = 0); ! map_target operator()(u32b address); // Page reference by virtual address ! map_target operator[](u32b index); // Table access by indexing the directory ! void SetPageDirectory(u32b directory); }; Index: mutex.cpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/hal/mutex.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** mutex.cpp 24 Jun 2006 15:00:02 -0000 1.6 --- mutex.cpp 19 Oct 2006 17:48:34 -0000 1.7 *************** *** 42,46 **** mutex::mutex() { ! key = 0; } --- 42,46 ---- mutex::mutex() { ! key = 0; } *************** *** 62,67 **** } ! void mutex::ExitMutex() { asm("movl $0, %[key] \n" : : [key] "m" (key)); } --- 62,78 ---- } ! void mutex::LeaveMutex() { asm("movl $0, %[key] \n" : : [key] "m" (key)); } + + CriticalSection::CriticalSection(mutex* key) + { + mutex_key = key; + mutex_key->EnterMutex(); + } + + CriticalSection::~CriticalSection() + { + mutex_key->LeaveMutex(); + } Index: mutex.hpp =================================================================== RCS file: /cvsroot/trion/trion v0.2/hal/mutex.hpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** mutex.hpp 24 Jun 2006 15:00:03 -0000 1.6 --- mutex.hpp 19 Oct 2006 17:48:34 -0000 1.7 *************** *** 46,50 **** { private: ! volatile u32b key; public: --- 46,50 ---- { private: ! volatile u32b key; public: *************** *** 53,57 **** void EnterMutex(); ! void ExitMutex(); }; --- 53,67 ---- void EnterMutex(); ! void LeaveMutex(); ! }; ! ! class CriticalSection ! { ! private: ! mutex* mutex_key; ! ! public: ! CriticalSection(mutex* key); ! ~CriticalSection(); }; |