Merge pull request #3262 from unknownbrackets/sysmem

Fix "grain will be off" by making it not actually off
This commit is contained in:
Henrik Rydgård 2013-08-20 01:28:20 -07:00
commit c5de701ae3
2 changed files with 39 additions and 20 deletions

View file

@ -15,9 +15,10 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "Log.h"
#include "BlockAllocator.h"
#include "ChunkFile.h"
#include "Common/Log.h"
#include "Common/ChunkFile.h"
#include "Core/Util/BlockAllocator.h"
#include "Core/Reporting.h"
// Slow freaking thing but works (eventually) :)
@ -145,16 +146,24 @@ u32 BlockAllocator::AllocAt(u32 position, u32 size, const char *tag)
ERROR_LOG(HLE, "Clearly bogus size: %08x - failing allocation", size);
return -1;
}
// upalign size to grain
size = (size + grain_ - 1) & ~(grain_ - 1);
// check that position is aligned
// Downalign the position so we're allocating full blocks.
u32 alignedPosition = position;
u32 alignedSize = size;
if (position & (grain_ - 1)) {
ERROR_LOG(HLE, "Position %08x does not align to grain. Grain will be off.", position);
DEBUG_LOG(HLE, "Position %08x does not align to grain.", position);
alignedPosition &= ~(grain_ - 1);
// Since the position was decreased, size must increase.
alignedSize += alignedPosition - position;
}
Block *bp = GetBlockFromAddress(position);
// Upalign size to grain.
alignedSize = (alignedSize + grain_ - 1) & ~(grain_ - 1);
// Tell the caller the allocated size from their requested starting position.
size = alignedSize - (alignedPosition - position);
Block *bp = GetBlockFromAddress(alignedPosition);
if (bp != NULL)
{
Block &b = *bp;
@ -166,24 +175,24 @@ u32 BlockAllocator::AllocAt(u32 position, u32 size, const char *tag)
else
{
//good to go
if (b.start == position)
if (b.start == alignedPosition)
{
InsertFreeAfter(&b, b.start + size, b.size - size);
InsertFreeAfter(&b, b.start + alignedSize, b.size - alignedSize);
b.taken = true;
b.size = size;
b.size = alignedSize;
b.SetTag(tag);
CheckBlocks();
return position;
}
else
{
int size1 = position - b.start;
int size1 = alignedPosition - b.start;
InsertFreeBefore(&b, b.start, size1);
if (b.start + b.size > position + size)
InsertFreeAfter(&b, position + size, b.size - (size + size1));
if (b.start + b.size > alignedPosition + alignedSize)
InsertFreeAfter(&b, alignedPosition + alignedSize, b.size - (alignedSize + size1));
b.taken = true;
b.start = position;
b.size = size;
b.start = alignedPosition;
b.size = alignedSize;
b.SetTag(tag);
return position;
}
@ -197,7 +206,7 @@ u32 BlockAllocator::AllocAt(u32 position, u32 size, const char *tag)
//Out of memory :(
ListBlocks();
ERROR_LOG(HLE, "Block Allocator failed to allocate %i bytes of contiguous memory", size);
ERROR_LOG(HLE, "Block Allocator failed to allocate %i bytes of contiguous memory", alignedSize);
return -1;
}
@ -376,6 +385,8 @@ u32 BlockAllocator::GetLargestFreeBlockSize() const
maxFreeBlock = b.size;
}
}
if (maxFreeBlock & (grain_ - 1))
WARN_LOG_REPORT(HLE, "GetLargestFreeBlockSize: free size %08x does not align to grain %08x.", maxFreeBlock, grain_);
return maxFreeBlock;
}
@ -390,6 +401,8 @@ u32 BlockAllocator::GetTotalFreeBytes() const
sum += b.size;
}
}
if (sum & (grain_ - 1))
WARN_LOG_REPORT(HLE, "GetTotalFreeBytes: free size %08x does not align to grain %08x.", sum, grain_);
return sum;
}

View file

@ -290,6 +290,12 @@ void PathBrowser::Navigate(const std::string &path) {
}
}
static std::string GetMemCardDirectory() {
std::string memCardDirectory, ignore;
GetSysDirectories(memCardDirectory, ignore);
return memCardDirectory;
}
class GameBrowser : public UI::LinearLayout {
public:
GameBrowser(std::string path, bool allowBrowsing, bool *gridStyle_, std::string lastText, std::string lastLink, UI::LayoutParams *layoutParams = 0);
@ -333,7 +339,7 @@ UI::EventReturn GameBrowser::LastClick(UI::EventParams &e) {
}
UI::EventReturn GameBrowser::HomeClick(UI::EventParams &e) {
path_.SetPath(g_Config.memCardDirectory);
path_.SetPath(GetMemCardDirectory());
g_Config.currentDirectory = path_.GetPath();
Refresh();
return UI::EVENT_DONE;
@ -472,7 +478,7 @@ void MainScreen::CreateViews() {
GameBrowser *tabAllGames = new GameBrowser(g_Config.currentDirectory, true, &g_Config.bGridView2,
m->T("How to get games"), "http://www.ppsspp.org/faq.html",
new LinearLayoutParams(FILL_PARENT, FILL_PARENT));
GameBrowser *tabHomebrew = new GameBrowser(g_Config.memCardDirectory + "PSP/GAME/", false, &g_Config.bGridView3,
GameBrowser *tabHomebrew = new GameBrowser(GetMemCardDirectory() + "PSP/GAME/", false, &g_Config.bGridView3,
"", "",
new LinearLayoutParams(FILL_PARENT, FILL_PARENT));