2012-03-21 16:19:26 +00:00
|
|
|
/*******************************************************************************
|
2011-08-05 12:25:00 +00:00
|
|
|
|
2012-03-21 16:19:26 +00:00
|
|
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
2011-08-05 12:25:00 +00:00
|
|
|
|
|
|
|
This file is part of Sortix.
|
|
|
|
|
|
|
|
Sortix is free software: you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
|
|
|
|
2012-03-21 16:19:26 +00:00
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-05 12:25:00 +00:00
|
|
|
|
|
|
|
memorymanagement.h
|
2011-10-02 13:58:08 +00:00
|
|
|
Functions that allow modification of virtual memory.
|
2011-08-05 12:25:00 +00:00
|
|
|
|
2012-03-21 16:19:26 +00:00
|
|
|
*******************************************************************************/
|
2011-08-05 12:25:00 +00:00
|
|
|
|
|
|
|
#ifndef SORTIX_MEMORYMANAGEMENT_H
|
|
|
|
#define SORTIX_MEMORYMANAGEMENT_H
|
|
|
|
|
2011-08-12 00:58:55 +00:00
|
|
|
// Forward declarations.
|
|
|
|
typedef struct multiboot_info multiboot_info_t;
|
|
|
|
|
2011-08-05 12:25:00 +00:00
|
|
|
namespace Sortix
|
|
|
|
{
|
|
|
|
namespace Page
|
|
|
|
{
|
2012-03-21 16:19:26 +00:00
|
|
|
bool Reserve(size_t* counter, size_t amount);
|
|
|
|
bool Reserve(size_t* counter, size_t least, size_t ideal);
|
|
|
|
addr_t GetReserved(size_t* counter);
|
2011-08-12 00:58:55 +00:00
|
|
|
addr_t Get();
|
|
|
|
void Put(addr_t page);
|
|
|
|
|
2012-03-21 16:19:26 +00:00
|
|
|
inline size_t Size() { return 4096UL; }
|
|
|
|
|
2011-08-12 00:58:55 +00:00
|
|
|
// Rounds a memory address down to nearest page.
|
|
|
|
inline addr_t AlignDown(addr_t page) { return page & ~(0xFFFUL); }
|
2011-08-07 21:40:20 +00:00
|
|
|
|
2011-08-12 00:58:55 +00:00
|
|
|
// Rounds a memory address up to nearest page.
|
|
|
|
inline addr_t AlignUp(addr_t page) { return AlignDown(page + 0xFFFUL); }
|
2012-03-26 14:46:26 +00:00
|
|
|
|
|
|
|
// Tests whether an address is page aligned.
|
|
|
|
inline bool IsAligned(addr_t page) { return AlignDown(page) == page; }
|
2011-08-05 12:25:00 +00:00
|
|
|
}
|
|
|
|
|
2011-10-02 13:58:08 +00:00
|
|
|
namespace Memory
|
2011-08-05 12:25:00 +00:00
|
|
|
{
|
2011-10-02 13:58:08 +00:00
|
|
|
void Init(multiboot_info_t* bootinfo);
|
|
|
|
void InvalidatePage(addr_t addr);
|
|
|
|
void Flush();
|
|
|
|
addr_t Fork();
|
2012-04-09 12:15:40 +00:00
|
|
|
addr_t GetAddressSpace();
|
2011-08-06 22:47:36 +00:00
|
|
|
addr_t SwitchAddressSpace(addr_t addrspace);
|
2011-11-27 11:02:34 +00:00
|
|
|
void DestroyAddressSpace();
|
2012-03-21 16:19:26 +00:00
|
|
|
bool Map(addr_t physical, addr_t mapto, int prot);
|
|
|
|
addr_t Unmap(addr_t mapto);
|
|
|
|
addr_t Physical(addr_t mapto);
|
|
|
|
int PageProtection(addr_t mapto);
|
|
|
|
bool LookUp(addr_t mapto, addr_t* physical, int* prot);
|
|
|
|
int ProvidedProtection(int prot);
|
|
|
|
void PageProtect(addr_t mapto, int protection);
|
|
|
|
void PageProtectAdd(addr_t mapto, int protection);
|
|
|
|
void PageProtectSub(addr_t mapto, int protection);
|
|
|
|
bool MapRange(addr_t where, size_t bytes, int protection);
|
|
|
|
bool UnmapRange(addr_t where, size_t bytes);
|
2011-11-26 19:14:57 +00:00
|
|
|
void Statistics(size_t* amountused, size_t* totalmem);
|
2011-12-22 13:13:18 +00:00
|
|
|
addr_t GetKernelStack();
|
|
|
|
size_t GetKernelStackSize();
|
|
|
|
addr_t GetInitRD();
|
|
|
|
size_t GetInitRDSize();
|
|
|
|
void RegisterInitRDSize(size_t size);
|
|
|
|
addr_t GetHeapLower();
|
|
|
|
addr_t GetHeapUpper();
|
2012-05-27 22:19:18 +00:00
|
|
|
addr_t GetVideoMemory();
|
|
|
|
size_t GetMaxVideoMemorySize();
|
2011-08-05 12:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|