mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-03 12:27:21 +12:00
Sort of working OS allocator, except freeing is impossible
This commit is contained in:
parent
2128d5060b
commit
93f5ec7bb4
8 changed files with 186 additions and 40 deletions
|
@ -13,6 +13,7 @@ class CP15 final : public Dynarmic::A32::Coprocessor {
|
|||
using CallbackOrAccessTwoWords = Dynarmic::A32::Coprocessor::CallbackOrAccessTwoWords;
|
||||
|
||||
u32 threadStoragePointer; // Pointer to thread-local storage
|
||||
u32 dummy; // MCR writes here for registers whose values are ignored
|
||||
|
||||
std::optional<Callback> CompileInternalOperation(bool two, unsigned opc1,
|
||||
CoprocReg CRd, CoprocReg CRn,
|
||||
|
@ -22,7 +23,10 @@ class CP15 final : public Dynarmic::A32::Coprocessor {
|
|||
|
||||
CallbackOrAccessOneWord CompileSendOneWord(bool two, unsigned opc1, CoprocReg CRn,
|
||||
CoprocReg CRm, unsigned opc2) override {
|
||||
Helpers::panic("CP15: CompileSendOneWord\n");
|
||||
if (!two && opc1 == 0 && CRn == CoprocReg::C7 && CRm == CoprocReg::C10 && opc2 == 5) {
|
||||
return &dummy; // TODO: Find out what this is. Some sort of memory barrier reg.
|
||||
}
|
||||
Helpers::panic("CP15: CompileSendOneWord\nopc1: %d CRn: %d CRm: %d opc2: %d\n", opc1, (int)CRn, (int)CRm, opc2);
|
||||
}
|
||||
|
||||
CallbackOrAccessTwoWords CompileSendTwoWords(bool two, unsigned opc, CoprocReg CRm) override {
|
||||
|
@ -36,7 +40,7 @@ class CP15 final : public Dynarmic::A32::Coprocessor {
|
|||
return &threadStoragePointer;
|
||||
}
|
||||
|
||||
Helpers::panic("CP15: CompileGetOneWord");
|
||||
Helpers::panic("CP15: CompileGetOneWord\nopc1: %d CRn: %d CRm: %d opc2: %d\n", opc1, (int)CRn, (int)CRm, opc2);
|
||||
}
|
||||
|
||||
CallbackOrAccessTwoWords CompileGetTwoWords(bool two, unsigned opc, CoprocReg CRm) override {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
#include "cpu.hpp"
|
||||
#include "helpers.hpp"
|
||||
|
@ -8,6 +9,10 @@
|
|||
#include "SFML/Window.hpp"
|
||||
#include "SFML/Graphics.hpp"
|
||||
|
||||
enum class ROMType {
|
||||
None, ELF, Cart
|
||||
};
|
||||
|
||||
class Emulator {
|
||||
CPU cpu;
|
||||
Memory memory;
|
||||
|
@ -16,6 +21,10 @@ class Emulator {
|
|||
sf::RenderWindow window;
|
||||
static constexpr u32 width = 400;
|
||||
static constexpr u32 height = 240 * 2; // * 2 because 2 screens
|
||||
ROMType romType = ROMType::None;
|
||||
|
||||
// Keep the handle for the ROM here to reload when necessary and to prevent deleting it
|
||||
std::ifstream loadedROM;
|
||||
|
||||
public:
|
||||
Emulator() : window(sf::VideoMode(width, height), "Alber", sf::Style::Default, sf::ContextSettings(0, 0, 0, 4, 3)),
|
||||
|
@ -31,4 +40,5 @@ public:
|
|||
void runFrame();
|
||||
|
||||
bool loadELF(std::filesystem::path& path);
|
||||
bool loadELF(std::ifstream& file);
|
||||
};
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include <filesystem>
|
||||
#include <bitset>
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include "helpers.hpp"
|
||||
|
@ -16,8 +17,12 @@ namespace VirtualAddrs {
|
|||
StackBottom = 0x0FFFC000,
|
||||
StackSize = 0x4000,
|
||||
|
||||
NormalHeapStart = 0x08000000,
|
||||
LinearHeapStart = 0x14000000,
|
||||
|
||||
// Start of TLS for first thread. Next thread's storage will be at TLSBase + 0x1000, and so on
|
||||
TLSBase = 0xFF400000
|
||||
TLSBase = 0xFF400000,
|
||||
TLSSize = 0x1000
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -30,12 +35,23 @@ class Memory {
|
|||
static constexpr u32 pageSize = 1 << pageShift;
|
||||
static constexpr u32 pageMask = pageSize - 1;
|
||||
static constexpr u32 totalPageCount = 1 << (32 - pageShift);
|
||||
|
||||
static constexpr u32 FCRAM_SIZE = 128_MB;
|
||||
static constexpr u32 FCRAM_APPLICATION_SIZE = 64_MB;
|
||||
static constexpr u32 FCRAM_PAGE_COUNT = FCRAM_SIZE / pageSize;
|
||||
static constexpr u32 FCRAM_APPLICATION_PAGE_COUNT = FCRAM_APPLICATION_SIZE / pageSize;
|
||||
|
||||
std::bitset<FCRAM_PAGE_COUNT> usedFCRAMPages;
|
||||
std::optional<u32> findPaddr(u32 size);
|
||||
|
||||
public:
|
||||
u32 usedUserMemory = 0;
|
||||
|
||||
Memory();
|
||||
void reset();
|
||||
void* getReadPointer(u32 address);
|
||||
void* getWritePointer(u32 address);
|
||||
std::optional<u32> loadELF(std::filesystem::path& path);
|
||||
std::optional<u32> loadELF(std::ifstream& file);
|
||||
|
||||
u8 read8(u32 vaddr);
|
||||
u16 read16(u32 vaddr);
|
||||
|
@ -46,4 +62,16 @@ public:
|
|||
void write16(u32 vaddr, u16 value);
|
||||
void write32(u32 vaddr, u32 value);
|
||||
void write64(u32 vaddr, u64 value);
|
||||
|
||||
// Allocate "size" bytes of RAM starting from physical FCRAM address "paddr" (We pick it ourself if paddr == 0)
|
||||
// And map them to virtual address "vaddr" (We also pick it ourself if vaddr == 0).
|
||||
// If the "linear" flag is on, the paddr pages must be adjacent in FCRAM
|
||||
// r, w, x: Permissions for the allocated memory
|
||||
// Returns the vaddr the FCRAM was mapped to or nullopt if allocation failed
|
||||
std::optional<u32> allocateMemory(u32 vaddr, u32 paddr, u32 size, bool linear, bool r = true, bool w = true, bool x = true);
|
||||
|
||||
// Returns whether "addr" is aligned to a page (4096 byte) boundary
|
||||
static constexpr bool isAligned(u32 addr) {
|
||||
return (addr & pageMask) == 0;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue