2011-08-05 08:25:00 -04:00
|
|
|
/******************************************************************************
|
|
|
|
|
|
|
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
memorymanagement.h
|
2011-10-02 09:58:08 -04:00
|
|
|
Functions that allow modification of virtual memory.
|
2011-08-05 08:25:00 -04:00
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef SORTIX_MEMORYMANAGEMENT_H
|
|
|
|
#define SORTIX_MEMORYMANAGEMENT_H
|
|
|
|
|
2011-08-11 20:58:55 -04:00
|
|
|
// Forward declarations.
|
|
|
|
typedef struct multiboot_info multiboot_info_t;
|
|
|
|
|
2011-08-05 08:25:00 -04:00
|
|
|
namespace Sortix
|
|
|
|
{
|
|
|
|
namespace Page
|
|
|
|
{
|
2011-08-11 20:58:55 -04:00
|
|
|
addr_t Get();
|
|
|
|
void Put(addr_t page);
|
|
|
|
|
|
|
|
// Rounds a memory address down to nearest page.
|
|
|
|
inline addr_t AlignDown(addr_t page) { return page & ~(0xFFFUL); }
|
2011-08-07 17:40:20 -04:00
|
|
|
|
2011-08-11 20:58:55 -04:00
|
|
|
// Rounds a memory address up to nearest page.
|
|
|
|
inline addr_t AlignUp(addr_t page) { return AlignDown(page + 0xFFFUL); }
|
2011-08-05 08:25:00 -04:00
|
|
|
}
|
|
|
|
|
2011-10-02 09:58:08 -04:00
|
|
|
namespace Memory
|
2011-08-05 08:25:00 -04:00
|
|
|
{
|
2011-10-02 09:58:08 -04:00
|
|
|
void Init(multiboot_info_t* bootinfo);
|
|
|
|
void InvalidatePage(addr_t addr);
|
|
|
|
void Flush();
|
|
|
|
addr_t Fork();
|
2011-08-06 18:47:36 -04:00
|
|
|
addr_t SwitchAddressSpace(addr_t addrspace);
|
2011-11-27 06:02:34 -05:00
|
|
|
void DestroyAddressSpace();
|
2011-08-11 20:58:55 -04:00
|
|
|
bool MapRangeKernel(addr_t where, size_t bytes);
|
|
|
|
void UnmapRangeKernel(addr_t where, size_t bytes);
|
|
|
|
bool MapRangeUser(addr_t where, size_t bytes);
|
|
|
|
void UnmapRangeUser(addr_t where, size_t bytes);
|
2011-10-02 09:58:08 -04:00
|
|
|
bool MapKernel(addr_t physical, addr_t mapto);
|
|
|
|
bool MapUser(addr_t physical, addr_t mapto);
|
|
|
|
addr_t UnmapKernel(addr_t mapto);
|
|
|
|
addr_t UnmapUser(addr_t mapto);
|
2011-11-26 14:14:57 -05:00
|
|
|
void Statistics(size_t* amountused, size_t* totalmem);
|
2011-10-02 09:58:08 -04:00
|
|
|
|
|
|
|
#if defined(PLATFORM_X86)
|
|
|
|
const addr_t HEAPLOWER = 0x80000000UL;
|
Fixed two very nasty bugs in the x86 memory management code.
1) The PML2 was not initialized to zeroes, thus leaving some bits behind that
caused the fork code to go crazy, forking the unforkable, and mapping addresses
that never, ever, should have been mapped, leaving behind a trail of page faults
and general protection faults on some computers, while other computers worked
because the uninitalized memory just wasn't uninitialized enough. Yep, this was
a schrödinbug!
2) Fixed a time bomb. The kernel heap was accidentally put such that whenever a
few megabytes were allocated, it would begin overwriting the physical page stack
causing unthinkable events to unfold and would probably be even more obscure to
debug than 1).
Oh, and some string errors fixed and removed RunApplication from kernel.cpp,
funny thing that even linked in the first place. Guess, the optimizer actually
did work for once. :)
2011-10-19 21:40:37 -04:00
|
|
|
const addr_t HEAPUPPER = 0xFF400000UL;
|
2011-09-08 15:09:14 -04:00
|
|
|
#elif defined(PLATFORM_X64)
|
2011-10-02 09:58:08 -04:00
|
|
|
const addr_t HEAPLOWER = 0xFFFF800000000000UL;
|
|
|
|
const addr_t HEAPUPPER = 0xFFFFFE8000000000UL;
|
2011-08-06 18:18:41 -04:00
|
|
|
#endif
|
2011-08-05 08:25:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|