From 670ac5643a7cda55b7c5d68c99495ade0d14e6e4 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 4 Apr 2014 23:02:59 -0400 Subject: [PATCH] added hw module to interface h/w register reads/writes --- src/core/core.vcxproj | 2 + src/core/core.vcxproj.filters | 9 +++++ src/core/src/hw/hw.cpp | 70 ++++++++++++++++++++++++++++++++++ src/core/src/hw/hw.h | 35 +++++++++++++++++ src/core/src/mem_map_funcs.cpp | 5 +-- 5 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 src/core/src/hw/hw.cpp create mode 100644 src/core/src/hw/hw.h diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index bee9f3046..eb1272b23 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -152,6 +152,7 @@ + @@ -180,6 +181,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 45ddf8cf6..f3237ed05 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -46,6 +46,9 @@ arm\interpreter + + hw + @@ -69,6 +72,9 @@ {cca8b763-8a80-4478-9bcc-3c979293c357} + + {d1158fc4-3e0f-431f-9d3b-f30bbfeb4ad5} + @@ -136,6 +142,9 @@ arm\interpreter + + hw + diff --git a/src/core/src/hw/hw.cpp b/src/core/src/hw/hw.cpp new file mode 100644 index 000000000..7250bc237 --- /dev/null +++ b/src/core/src/hw/hw.cpp @@ -0,0 +1,70 @@ +/** + * Copyright (C) 2013 Citrus Emulator + * + * @file hw.cpp + * @author bunnei + * @date 2014-04-04 + * @brief Hardware interface + * + * @section LICENSE + * This program 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 2 of + * the License, or (at your option) any later version. + * + * This program 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 at + * http://www.gnu.org/copyleft/gpl.html + * + * Official project repository can be found at: + * http://code.google.com/p/gekko-gc-emu/ + */ + +#include "log.h" +#include "hw/hw.h" + +namespace HW { + +template +inline void Read(T &var, const u32 addr) { + // TODO: Figure out the fastest order of tests for both read and write (they are probably different). + // TODO: Make sure this represents the mirrors in a correct way. + + // Could just do a base-relative read, too.... TODO + + //if ((addr & 0x3E000000) == 0x08000000) { + // var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); + + //} else { + // _assert_msg_(HW, false, "unknown hardware read"); + //} +} + +template +inline void Write(u32 addr, const T data) { + //// ExeFS:/.code is loaded here: + //if ((addr & 0xFFF00000) == 0x00100000) { + // // TODO(ShizZy): This is dumb... handle correctly. From 3DBrew: + // // http://3dbrew.org/wiki/Memory_layout#ARM11_User-land_memory_regions + // // The ExeFS:/.code is loaded here, executables must be loaded to the 0x00100000 region when + // // the exheader "special memory" flag is clear. The 0x03F00000-byte size restriction only + // // applies when this flag is clear. Executables are usually loaded to 0x14000000 when the + // // exheader "special memory" flag is set, however this address can be arbitrary. + // *(T*)&g_fcram[addr & MEM_FCRAM_MASK] = data; + + //// Error out... + //} else { + // _assert_msg_(HW, false, "unknown hardware write"); + //} +} + + +void Init() { +} + +void Shutdown() { +} + +} \ No newline at end of file diff --git a/src/core/src/hw/hw.h b/src/core/src/hw/hw.h new file mode 100644 index 000000000..dacad4924 --- /dev/null +++ b/src/core/src/hw/hw.h @@ -0,0 +1,35 @@ +/** + * Copyright (C) 2013 Citrus Emulator + * + * @file hw.h + * @author bunnei + * @date 2014-04-04 + * @brief Hardware interface + * + * @section LICENSE + * This program 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 2 of + * the License, or (at your option) any later version. + * + * This program 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 at + * http://www.gnu.org/copyleft/gpl.html + * + * Official project repository can be found at: + * http://code.google.com/p/gekko-gc-emu/ + */ + +#include "common_types.h" + +namespace HW { + +template +inline void Read(T &var, const u32 addr); + +template +inline void Write(u32 addr, const T data); + +} // namespace diff --git a/src/core/src/mem_map_funcs.cpp b/src/core/src/mem_map_funcs.cpp index 446d3ac97..b000571e5 100644 --- a/src/core/src/mem_map_funcs.cpp +++ b/src/core/src/mem_map_funcs.cpp @@ -54,8 +54,7 @@ inline void _Read(T &var, const u32 addr) { var = *((const T*)&g_fcram[addr & MEM_FCRAM_MASK]); } else { - _assert_msg_(MEMMAP, false, "unknown hardware read"); - // WARN_LOG(MEMMAP, "_Read: Invalid addr %08x PC %08x LR %08x", addr, currentMIPS->pc, currentMIPS->r[MIPS_REG_RA]); + _assert_msg_(MEMMAP, false, "unknown memory read"); } } @@ -104,7 +103,7 @@ inline void _Write(u32 addr, const T data) { // Error out... } else { - _assert_msg_(MEMMAP, false, "unknown hardware write"); + _assert_msg_(MEMMAP, false, "unknown memory write"); } }