Formatting and cleanup

This commit is contained in:
Maschell 2021-09-24 16:51:11 +02:00
parent 18a2889a36
commit d0e432fb69
7 changed files with 96 additions and 94 deletions

View File

@ -26,8 +26,8 @@ public:
typedef void (*Callback)(CThread *thread, void *arg);
//! constructor
CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
: pThread(NULL), pThreadStack(NULL), pCallback(callback), pCallbackArg(callbackArg) {
explicit CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = nullptr, void *callbackArg = nullptr)
: pThread(nullptr), pThreadStack(nullptr), pCallback(callback), pCallbackArg(callbackArg) {
//! save attribute assignment
iAttributes = iAttr;
//! allocate the thread
@ -50,24 +50,24 @@ public:
}
//! Get thread ID
virtual void *getThread() const {
[[nodiscard]] virtual void *getThread() const {
return pThread;
}
//! Thread entry function
virtual void executeThread(void) {
virtual void executeThread() {
if (pCallback)
pCallback(this, pCallbackArg);
}
//! Suspend thread
virtual void suspendThread(void) {
virtual void suspendThread() {
if (isThreadSuspended()) return;
if (pThread) OSSuspendThread(pThread);
}
//! Resume thread
virtual void resumeThread(void) {
virtual void resumeThread() {
if (!isThreadSuspended()) return;
if (pThread) OSResumeThread(pThread);
}
@ -78,36 +78,36 @@ public:
}
//! Check if thread is suspended
virtual bool isThreadSuspended(void) const {
[[nodiscard]] virtual bool isThreadSuspended() const {
if (pThread) return OSIsThreadSuspended(pThread);
return false;
}
//! Check if thread is terminated
virtual bool isThreadTerminated(void) const {
[[nodiscard]] virtual bool isThreadTerminated() const {
if (pThread) return OSIsThreadTerminated(pThread);
return false;
}
//! Check if thread is running
virtual bool isThreadRunning(void) const {
[[nodiscard]] virtual bool isThreadRunning() const {
return !isThreadSuspended() && !isThreadRunning();
}
//! Gets the thread affinity.
virtual uint16_t getThreadAffinity(void) const {
[[nodiscard]] virtual uint16_t getThreadAffinity() const {
if (pThread) return OSGetThreadAffinity(pThread);
return 0;
}
//! Shutdown thread
virtual void shutdownThread(void) {
virtual void shutdownThread() {
//! wait for thread to finish
if (pThread && !(iAttributes & eAttributeDetach)) {
while (isThreadSuspended()) {
resumeThread();
}
OSJoinThread(pThread, NULL);
OSJoinThread(pThread, nullptr);
}
//! free the thread stack buffer
if (pThreadStack) {
@ -116,8 +116,8 @@ public:
if (pThread) {
free(pThread);
}
pThread = NULL;
pThreadStack = NULL;
pThread = nullptr;
pThreadStack = nullptr;
}
//! Thread attributes

View File

@ -3,8 +3,8 @@
#include "memory_mapping.h"
DECL_FUNCTION(int32_t, KiEffectiveToPhysical, uint32_t addressSpace, uint32_t virtualAddress) {
int32_t result = real_KiEffectiveToPhysical(addressSpace, virtualAddress);
DECL_FUNCTION(uint32_t, KiEffectiveToPhysical, uint32_t addressSpace, uint32_t virtualAddress) {
uint32_t result = real_KiEffectiveToPhysical(addressSpace, virtualAddress);
if (result == 0) {
return MemoryMapping_EffectiveToPhysical(virtualAddress);
}
@ -12,23 +12,23 @@ DECL_FUNCTION(int32_t, KiEffectiveToPhysical, uint32_t addressSpace, uint32_t vi
}
DECL_FUNCTION(int32_t, sCheckDataRange, uint32_t address, uint32_t maxDataSize) {
if((address & 0xF0000000) == 0x80000000){
if ((address & 0xF0000000) == 0x80000000) {
return 1;
}
return real_sCheckDataRange(address, maxDataSize);
}
DECL_FUNCTION(int32_t, KiPhysicalToEffectiveCached, uint32_t addressSpace, uint32_t virtualAddress) {
int32_t result = real_KiPhysicalToEffectiveCached(addressSpace, virtualAddress);
DECL_FUNCTION(uint32_t, KiPhysicalToEffectiveCached, uint32_t addressSpace, uint32_t virtualAddress) {
uint32_t result = real_KiPhysicalToEffectiveCached(addressSpace, virtualAddress);
if (result == 0) {
return MemoryMapping_PhysicalToEffective(virtualAddress);
}
return result;
}
DECL_FUNCTION(int32_t, KiPhysicalToEffectiveUncached, uint32_t addressSpace, uint32_t virtualAddress) {
int32_t result = real_KiPhysicalToEffectiveUncached(addressSpace, virtualAddress);
DECL_FUNCTION(uint32_t, KiPhysicalToEffectiveUncached, uint32_t addressSpace, uint32_t virtualAddress) {
uint32_t result = real_KiPhysicalToEffectiveUncached(addressSpace, virtualAddress);
if (result == 0) {
return MemoryMapping_PhysicalToEffective(virtualAddress);

View File

@ -1,6 +1,7 @@
#pragma once
#include <function_patcher/function_patching.h>
#include <stdint.h>
#include <cstdint>
extern function_replacement_data_t function_replacements[] __attribute__((section(".data")));

View File

@ -18,7 +18,7 @@ extern "C" {
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0);
} while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \

View File

@ -1,6 +1,3 @@
#include <coreinit/debug.h>
#include <cstddef>
#include <malloc.h>
#include <wums.h>
#include <whb/log.h>
#include <whb/log_udp.h>
@ -37,7 +34,7 @@ WUMS_APPLICATION_STARTS() {
//MemoryMapping_CreateHeaps();
for (int32_t i = 0; /* waiting for a break */; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
void *address = (void *) (mem_mapping[i].effective_start_address);

View File

@ -9,24 +9,24 @@
#include "memory.h"
#include "logger.h"
#include "CThread.h"
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <coreinit/debug.h>
#include <cstdio>
// #define DEBUG_FUNCTION_LINE(x,...)
void runOnAllCores(CThread::Callback callback, void *callbackArg, int32_t iAttr = 0, int32_t iPriority = 16, int32_t iStackSize = 0x8000) {
int32_t aff[] = {CThread::eAttributeAffCore2, CThread::eAttributeAffCore1, CThread::eAttributeAffCore0};
for (uint32_t i = 0; i < (sizeof(aff) / sizeof(aff[0])); i++) {
CThread *thread = CThread::create(callback, callbackArg, iAttr | aff[i], iPriority, iStackSize);
for (int i: aff) {
CThread *thread = CThread::create(callback, callbackArg, iAttr | i, iPriority, iStackSize);
thread->resumeThread();
delete thread;
}
}
void writeKernelNOPs(CThread *thread, void *arg) {
uint16_t core = OSGetThreadAffinity(OSGetCurrentThread());
DEBUG_FUNCTION_LINE_VERBOSE("Writing kernel NOPs on core %d", core/2);
DEBUG_FUNCTION_LINE_VERBOSE("Writing kernel NOPs on core %d", OSGetThreadAffinity(OSGetCurrentThread()) / 2);
KernelNOPAtPhysicalAddress(0xFFF1D754);
KernelNOPAtPhysicalAddress(0xFFF1D64C);
@ -48,17 +48,15 @@ void writeKernelNOPs(CThread *thread, void *arg) {
}
void writeSegmentRegister(CThread *thread, void *arg) {
sr_table_t *table = (sr_table_t *) arg;
uint16_t core = OSGetThreadAffinity(OSGetCurrentThread());
DEBUG_FUNCTION_LINE_VERBOSE("Writing segment register to core %d", core/2);
auto *table = (sr_table_t *) arg;
DEBUG_FUNCTION_LINE_VERBOSE("Writing segment register to core %d", OSGetThreadAffinity(OSGetCurrentThread()) / 2);
DCFlushRange(table, sizeof(sr_table_t));
KernelWriteSRs(table);
}
void readAndPrintSegmentRegister(CThread *thread, void *arg) {
uint16_t core = OSGetThreadAffinity(OSGetCurrentThread());
DEBUG_FUNCTION_LINE_VERBOSE("Reading segment register and page table from core %d", core/2);
DEBUG_FUNCTION_LINE_VERBOSE("Reading segment register and page table from core %d", OSGetThreadAffinity(OSGetCurrentThread()) / 2);
sr_table_t srTable;
memset(&srTable, 0, sizeof(srTable));
@ -97,7 +95,7 @@ void MemoryMapping_searchEmptyMemoryRegions() {
DEBUG_FUNCTION_LINE("Searching for empty memory.");
for (int32_t i = 0;; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
uint32_t ea_start_address = mem_mapping[i].effective_start_address;
@ -114,7 +112,7 @@ void MemoryMapping_searchEmptyMemoryRegions() {
ea_size += pa_end_address - pa_start_address;
}
uint32_t *flush_start = (uint32_t *) ea_start_address;
auto *flush_start = (uint32_t *) ea_start_address;
uint32_t flush_size = ea_size;
DEBUG_FUNCTION_LINE("Flushing %08X (%d kB) at %08X.", flush_size, flush_size / 1024, flush_start);
@ -122,14 +120,14 @@ void MemoryMapping_searchEmptyMemoryRegions() {
DEBUG_FUNCTION_LINE("Searching in memory region %d. 0x%08X - 0x%08X. Size 0x%08X (%d KBytes).", i + 1, ea_start_address, ea_start_address + ea_size, ea_size, ea_size / 1024);
bool success = true;
uint32_t *memory_ptr = (uint32_t *) ea_start_address;
auto *memory_ptr = (uint32_t *) ea_start_address;
bool inFailRange = false;
uint32_t startFailing = 0;
uint32_t startGood = ea_start_address;
for (uint32_t j = 0; j < ea_size / 4; j++) {
if (memory_ptr[j] != 0) {
success = false;
if (!success && !inFailRange) {
if (!inFailRange) {
if ((((uint32_t) &memory_ptr[j]) - (uint32_t) startGood) / 1024 > 512) {
uint32_t start_addr = startGood & 0xFFFE0000;
if (start_addr != startGood) {
@ -137,7 +135,8 @@ void MemoryMapping_searchEmptyMemoryRegions() {
}
uint32_t end_addr = ((uint32_t) &memory_ptr[j]) - MEMORY_START_BASE;
end_addr = (end_addr & 0xFFFE0000);
DEBUG_FUNCTION_LINE("+ Free between 0x%08X and 0x%08X size: %u kB", start_addr - MEMORY_START_BASE, end_addr, (((uint32_t) end_addr) - ((uint32_t) startGood - MEMORY_START_BASE)) / 1024);
DEBUG_FUNCTION_LINE("+ Free between 0x%08X and 0x%08X size: %u kB", start_addr - MEMORY_START_BASE, end_addr,
(((uint32_t) end_addr) - ((uint32_t) startGood - MEMORY_START_BASE)) / 1024);
}
startFailing = (uint32_t) &memory_ptr[j];
inFailRange = true;
@ -174,7 +173,7 @@ void MemoryMapping_writeTestValuesToMemory() {
uint32_t testBuffer[chunk_size];
for (int32_t i = 0;; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
uint32_t cur_ea_start_address = mem_mapping[i].effective_start_address;
@ -204,7 +203,7 @@ void MemoryMapping_writeTestValuesToMemory() {
}
//DEBUG_FUNCTION_LINE("testBuffer[%d] = %d",i % chunk_size,i);
}
uint32_t *flush_start = (uint32_t *) cur_ea_start_address;
auto *flush_start = (uint32_t *) cur_ea_start_address;
uint32_t flush_size = pa_size;
cur_ea_start_address += pa_size;
@ -221,7 +220,7 @@ void MemoryMapping_readTestValuesFromMemory() {
DEBUG_FUNCTION_LINE("Testing reading the written values.");
for (int32_t i = 0;; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
uint32_t ea_start_address = mem_mapping[i].effective_start_address;
@ -238,7 +237,7 @@ void MemoryMapping_readTestValuesFromMemory() {
ea_size += pa_end_address - pa_start_address;
}
uint32_t *flush_start = (uint32_t *) ea_start_address;
auto *flush_start = (uint32_t *) ea_start_address;
uint32_t flush_size = ea_size;
DEBUG_FUNCTION_LINE("Flushing %08X (%d kB) at %08X to map memory.", flush_size, flush_size / 1024, flush_start);
@ -246,14 +245,14 @@ void MemoryMapping_readTestValuesFromMemory() {
DEBUG_FUNCTION_LINE("Testing memory region %d. 0x%08X - 0x%08X. Size 0x%08X (%d KBytes).", i + 1, ea_start_address, ea_start_address + ea_size, ea_size, ea_size / 1024);
bool success = true;
uint32_t *memory_ptr = (uint32_t *) ea_start_address;
auto *memory_ptr = (uint32_t *) ea_start_address;
bool inFailRange = false;
uint32_t startFailing = 0;
uint32_t startGood = ea_start_address;
for (uint32_t j = 0; j < ea_size / 4; j++) {
if (memory_ptr[j] != j) {
success = false;
if (!success && !inFailRange) {
if (!inFailRange) {
DEBUG_FUNCTION_LINE("+ Good between 0x%08X and 0x%08X size: %u kB", startGood, &memory_ptr[j], (((uint32_t) &memory_ptr[j]) - (uint32_t) startGood) / 1024);
startFailing = (uint32_t) &memory_ptr[j];
inFailRange = true;
@ -286,7 +285,7 @@ void MemoryMapping_readTestValuesFromMemory() {
void MemoryMapping_memoryMappingForRegions(const memory_mapping_t *memory_mapping, sr_table_t SRTable, uint32_t *translation_table) {
for (int32_t i = 0; /* waiting for a break */; i++) {
//DEBUG_FUNCTION_LINE("In loop %d",i);
if (memory_mapping[i].physical_addresses == NULL) {
if (memory_mapping[i].physical_addresses == nullptr) {
//DEBUG_FUNCTION_LINE("break %d",i);
break;
}
@ -305,7 +304,8 @@ void MemoryMapping_memoryMappingForRegions(const memory_mapping_t *memory_mappin
break;
}
uint32_t pa_size = pa_end_address - pa_start_address;
DEBUG_FUNCTION_LINE_VERBOSE("Adding page table entry %d for mapping area %d. %08X-%08X => %08X-%08X...", j + 1, i + 1, cur_ea_start_address, memory_mapping[i].effective_start_address + pa_size, pa_start_address, pa_end_address);
DEBUG_FUNCTION_LINE_VERBOSE("Adding page table entry %d for mapping area %d. %08X-%08X => %08X-%08X...", j + 1, i + 1, cur_ea_start_address,
memory_mapping[i].effective_start_address + pa_size, pa_start_address, pa_end_address);
if (!MemoryMapping_mapMemory(pa_start_address, pa_end_address, cur_ea_start_address, SRTable, translation_table)) {
//log_print("error =(");
DEBUG_FUNCTION_LINE("Failed to map memory.");
@ -322,9 +322,9 @@ void MemoryMapping_memoryMappingForRegions(const memory_mapping_t *memory_mappin
void MemoryMapping_setupMemoryMapping() {
// Override all writes to SR8 with nops.
// Override some memory region checks inside the kernel
runOnAllCores(writeKernelNOPs,NULL);
runOnAllCores(writeKernelNOPs, nullptr);
//runOnAllCores(readAndPrintSegmentRegister,NULL,0,16,0x80000);
//runOnAllCores(readAndPrintSegmentRegister,nullptr,0,16,0x80000);
sr_table_t srTableCpy;
uint32_t pageTableCpy[0x8000];
@ -356,7 +356,7 @@ void MemoryMapping_setupMemoryMapping() {
DEBUG_FUNCTION_LINE_VERBOSE("Writing segment registers...", segment_index, segment_content);
// Writing the segment registers to ALL cores.
//
//writeSegmentRegister(NULL, &srTableCpy);
//writeSegmentRegister(nullptr, &srTableCpy);
runOnAllCores(writeSegmentRegister, &srTableCpy);
@ -372,7 +372,7 @@ void MemoryMapping_setupMemoryMapping() {
//printPageTableTranslation(srTableCpy,pageTableCpy);
//runOnAllCores(readAndPrintSegmentRegister,NULL,0,16,0x80000);
//runOnAllCores(readAndPrintSegmentRegister,nullptr,0,16,0x80000);
//searchEmptyMemoryRegions();
@ -383,14 +383,16 @@ void MemoryMapping_setupMemoryMapping() {
}
void *MemoryMapping_alloc(uint32_t size, uint32_t align) {
void *res = NULL;
void *res = nullptr;
for (int32_t i = 0; /* waiting for a break */; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
MEMHeapHandle heapHandle = (MEMHeapHandle) mem_mapping[i].effective_start_address;
MEMExpHeap *heap = (MEMExpHeap *) heapHandle;
OSUninterruptibleSpinLock_Acquire(&heap->header.lock);
auto heapHandle = (MEMHeapHandle) mem_mapping[i].effective_start_address;
auto *heap = (MEMExpHeap *) heapHandle;
auto header = (MEMHeapHeader *) heap;
OSUninterruptibleSpinLock_Acquire(&header->lock);
res = MEMAllocFromExpHeapEx(heapHandle, size, align);
auto cur = heap->usedList.head;
while (cur != nullptr) {
@ -402,7 +404,7 @@ void *MemoryMapping_alloc(uint32_t size, uint32_t align) {
DCFlushRange(cur, sizeof(MEMExpHeapBlock));
cur = cur->next;
}
OSUninterruptibleSpinLock_Release(&heap->header.lock);
OSUninterruptibleSpinLock_Release(&header->lock);
if (res != nullptr) {
break;
}
@ -411,19 +413,19 @@ void *MemoryMapping_alloc(uint32_t size, uint32_t align) {
}
void *MemoryMapping_allocVideoMemory(uint32_t size, uint32_t align) {
void *res = NULL;
void *res = nullptr;
for (int32_t i = 0; /* waiting for a break */; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
uint32_t effectiveAddress = mem_mapping[i].effective_start_address;
// Skip non-video memory
if(effectiveAddress < MEMORY_START_VIDEO || effectiveAddress > MEMORY_END_VIDEO){
if (effectiveAddress < MEMORY_START_VIDEO || effectiveAddress > MEMORY_END_VIDEO) {
continue;
}
res = MEMAllocFromExpHeapEx((MEMHeapHandle) mem_mapping[i].effective_start_address, size, align);
if (res != NULL) {
if (res != nullptr) {
break;
}
}
@ -432,18 +434,20 @@ void *MemoryMapping_allocVideoMemory(uint32_t size, uint32_t align) {
void MemoryMapping_free(void *ptr) {
if (ptr == NULL) {
if (ptr == nullptr) {
return;
}
uint32_t ptr_val = (uint32_t) ptr;
auto ptr_val = (uint32_t) ptr;
for (int32_t i = 0; /* waiting for a break */; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
if (ptr_val > mem_mapping[i].effective_start_address && ptr_val < mem_mapping[i].effective_end_address) {
MEMHeapHandle heapHandle = (MEMHeapHandle) mem_mapping[i].effective_start_address;
MEMExpHeap *heap = (MEMExpHeap *) heapHandle;
OSUninterruptibleSpinLock_Acquire(&heap->header.lock);
auto heapHandle = (MEMHeapHandle) mem_mapping[i].effective_start_address;
auto *heap = (MEMExpHeap *) heapHandle;
auto *header = (MEMHeapHeader *) heapHandle;
OSUninterruptibleSpinLock_Acquire(&header->lock);
MEMFreeToExpHeap((MEMHeapHandle) mem_mapping[i].effective_start_address, ptr);
auto cur = heap->usedList.head;
while (cur != nullptr) {
@ -455,7 +459,7 @@ void MemoryMapping_free(void *ptr) {
DCFlushRange(cur, sizeof(MEMExpHeapBlock));
cur = cur->next;
}
OSUninterruptibleSpinLock_Release(&heap->header.lock);
OSUninterruptibleSpinLock_Release(&header->lock);
break;
}
}
@ -468,7 +472,7 @@ uint32_t MemoryMapping_MEMGetAllocatableSize() {
uint32_t MemoryMapping_MEMGetAllocatableSizeEx(uint32_t align) {
uint32_t res = 0;
for (int32_t i = 0; /* waiting for a break */; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
uint32_t curRes = MEMGetAllocatableSizeForExpHeapEx((MEMHeapHandle) mem_mapping[i].effective_start_address, align);
@ -483,7 +487,7 @@ uint32_t MemoryMapping_MEMGetAllocatableSizeEx(uint32_t align) {
uint32_t MemoryMapping_GetFreeSpace() {
uint32_t res = 0;
for (int32_t i = 0; /* waiting for a break */; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
uint32_t curRes = MEMGetTotalFreeSizeForExpHeap((MEMHeapHandle) mem_mapping[i].effective_start_address);
@ -495,7 +499,7 @@ uint32_t MemoryMapping_GetFreeSpace() {
void MemoryMapping_CreateHeaps() {
for (int32_t i = 0; /* waiting for a break */; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
void *address = (void *) (mem_mapping[i].effective_start_address);
@ -509,7 +513,7 @@ void MemoryMapping_CreateHeaps() {
void MemoryMapping_DestroyHeaps() {
for (int32_t i = 0; /* waiting for a break */; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
void *address = (void *) (mem_mapping[i].effective_start_address);
@ -579,7 +583,7 @@ uint32_t MemoryMapping_getAreaSizeFromPageTable(uint32_t start, uint32_t maxSize
bool MemoryMapping_getPageEntryForAddress(uint32_t SDR1, uint32_t addr, uint32_t vsid, uint32_t *translation_table, uint32_t *oPTEH, uint32_t *oPTEL, bool checkSecondHash) {
uint32_t pageMask = SDR1 & 0x1FF;
uint32_t pageIndex = (addr >> PAGE_INDEX_SHIFT) & PAGE_INDEX_MASK;
uint32_t primaryHash = (vsid & 0x7FFFF) ^pageIndex;
uint32_t primaryHash = (vsid & 0x7FFFF) ^ pageIndex;
if (MemoryMapping_getPageEntryForAddressEx(SDR1, addr, vsid, primaryHash, translation_table, oPTEH, oPTEL, 0)) {
return true;
@ -712,9 +716,9 @@ void MemoryMapping_printPageTableTranslation(sr_table_t srTable, uint32_t *trans
const char *access1[] = {"read/write", "read/write", "read/write", "read only"};
const char *access2[] = {"no access", "read only", "read/write", "read only"};
for (std::vector<pageInformation>::iterator it = pageInfos.begin(); it != pageInfos.end(); ++it) {
pageInformation cur = *it;
DEBUG_FUNCTION_LINE_VERBOSE("%08X %08X -> %08X %08X. user access %s. supervisor access %s. %s", cur.addr, cur.addr + cur.size, cur.phys, cur.phys + cur.size, cur.kp ? access2[cur.pp] : access1[cur.pp],
for (auto cur: pageInfos) {
DEBUG_FUNCTION_LINE_VERBOSE("%08X %08X -> %08X %08X. user access %s. supervisor access %s. %s", cur.addr, cur.addr + cur.size, cur.phys, cur.phys + cur.size,
cur.kp ? access2[cur.pp] : access1[cur.pp],
cur.ks ? access2[cur.pp] : access1[cur.pp], cur.nx ? "not executable" : "executable");
}
}
@ -766,7 +770,7 @@ bool MemoryMapping_mapMemory(uint32_t pa_start_address, uint32_t pa_end_address,
uint32_t primary_hash = (VSID & 0x7FFFF);
uint32_t hashvalue1 = primary_hash ^page_index;
uint32_t hashvalue1 = primary_hash ^ page_index;
// hashvalue 2 is the complement of the first hash.
uint32_t hashvalue2 = ~hashvalue1;
@ -792,7 +796,7 @@ bool MemoryMapping_mapMemory(uint32_t pa_start_address, uint32_t pa_end_address,
uint32_t pteh = translation_table[index];
// Check if it's already taken. The first bit indicates if the PTE-slot inside
// this group is already taken.
if ((pteh == 0)) {
if (pteh == 0) {
// If we found a free slot, set the PTEH and PTEL value.
//DEBUG_FUNCTION_LINE("Used slot %d. PTEGaddr1 %08X addr %08X",j+1,PTEGaddr1 - (HTABORG << 16),PTEGoffset);
translation_table[index] = PTEH;
@ -819,7 +823,7 @@ bool MemoryMapping_mapMemory(uint32_t pa_start_address, uint32_t pa_end_address,
int32_t index = (PTEGoffset / 4);
uint32_t pteh = translation_table[index];
//Check if it's already taken.
if ((pteh == 0)) {
if (pteh == 0) {
translation_table[index] = PTEH;
translation_table[index + 1] = PTEL;
setSuccessfully = true;
@ -846,10 +850,10 @@ uint32_t MemoryMapping_PhysicalToEffective(uint32_t phyiscalAddress) {
}
uint32_t result = 0;
const memory_values_t *curMemValues = NULL;
const memory_values_t *curMemValues = nullptr;
//iterate through all own mapped memory regions
for (int32_t i = 0; true; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
@ -879,11 +883,11 @@ uint32_t MemoryMapping_EffectiveToPhysical(uint32_t effectiveAddress) {
uint32_t result = 0;
// CAUTION: The data may be fragmented between multiple areas in PA.
const memory_values_t *curMemValues = NULL;
const memory_values_t *curMemValues = nullptr;
uint32_t curOffset = 0;
for (int32_t i = 0; true; i++) {
if (mem_mapping[i].physical_addresses == NULL) {
if (mem_mapping[i].physical_addresses == nullptr) {
break;
}
if (effectiveAddress >= mem_mapping[i].effective_start_address && effectiveAddress < mem_mapping[i].effective_end_address) {
@ -893,7 +897,7 @@ uint32_t MemoryMapping_EffectiveToPhysical(uint32_t effectiveAddress) {
}
}
if (curMemValues == NULL) {
if (curMemValues == nullptr) {
return result;
}

View File

@ -1,6 +1,6 @@
#pragma once
#include <stddef.h>
#include <cstddef>
#ifdef __cplusplus
extern "C" {
@ -84,7 +84,7 @@ const memory_values_t mem_vals_video[] = {
// void * heap = (void*) SharedReadHeapTrackingAddr - [delta due mapping e.g (0xF8000000 + 0x80000000)];
// int size = 0x20000; // value have to be a multiple of 0x20000;
// while(true){
// void * outPtr = NULL;
// void * outPtr = nullptr;
// if(TinyHeap_Alloc(heap,size, 0x20000,&outPtr) == 0){ // value have to be a multiple of 0x20000;
// DEBUG_FUNCTION_LINE("Allocated %d kb on heap %08X (PA %08X)\n",size/1024,(uint32_t)outPtr, OSEffectiveToPhysical(outPtr));
// TinyHeap_Free(heap, outPtr);
@ -115,7 +115,7 @@ const memory_mapping_t mem_mapping[] = {
{MEMORY_HEAP2, MEMORY_HEAP3, mem_vals_heap_3},
{MEMORY_HEAP3, MEMORY_HEAP4, mem_vals_heap_4},
{MEMORY_START_VIDEO, MEMORY_END_VIDEO, mem_vals_video},
{0, 0, NULL}
{0, 0, nullptr}
};