git subrepo pull --force emummc

subrepo:
  subdir:   "emummc"
  merged:   "2fc47cbb8"
upstream:
  origin:   "https://github.com/lulle2007200/emuMMC.git"
  branch:   "develop"
  commit:   "2fc47cbb8"
git-subrepo:
  version:  "0.4.9"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "30db3b8"
This commit is contained in:
lulle2007200
2025-05-12 14:22:12 +02:00
parent 0188898af4
commit 92c599f0f0
342 changed files with 106677 additions and 974 deletions

View File

@@ -21,8 +21,24 @@
#include "fatal.h"
#include "types.h"
#include "../nx/counter.h"
#include "../nx/svc.h"
// #include "../nx/svc.h"
#include "../soc/t210.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <switch/kernel/svc.h>
_Alignas(4096) u8 working_buf[4096];
typedef struct _log_ctx
{
u32 magic;
u32 sz;
u32 start;
u32 end;
char buf[];
} log_ctx_t;
typedef struct _io_mapping_t
{
@@ -41,7 +57,7 @@ static inline uintptr_t _GetIoMapping(u64 io_addr, u64 io_size)
if (emuMMC_ctx.fs_ver >= FS_VER_10_0_0) {
u64 out_size;
if (svcQueryIoMapping(&vaddr, &out_size, aligned_addr, aligned_size) != 0) {
if (svcQueryMemoryMapping(&vaddr, &out_size, aligned_addr, aligned_size) != 0) {
fatal_abort(Fatal_IoMapping);
}
} else {
@@ -117,3 +133,119 @@ void exec_cfg(u32 *base, const cfg_op_t *ops, u32 num_ops)
for (u32 i = 0; i < num_ops; i++)
base[ops[i].off] = ops[i].val;
}
#define IRAM_LOG_CTX_ADDR 0x4003C000
#define IRAM_LOG_MAX_SZ 4096
void log_iram(const char* fmt, ...) {
static const u32 max_log_sz = sizeof(working_buf) - sizeof(log_ctx_t);
static bool init_done = false;
log_ctx_t *log_ctx = (log_ctx_t*)working_buf;
smcCopyFromIram(working_buf, IRAM_LOG_CTX_ADDR, sizeof(working_buf));
if(!init_done){
init_done = true;
log_ctx->buf[0] = '\0';
log_ctx->magic = 0xaabbccdd;
log_ctx->start = 0;
log_ctx->end = 0;
}
va_list args;
va_start(args, fmt);
int res = vsnprintf(log_ctx->buf + log_ctx->end, sizeof(working_buf) - sizeof(log_ctx_t) - log_ctx->end, fmt, args);
va_end(args);
if(res < 0 || log_ctx->start + res + 1 > max_log_sz) {
return;
}
log_ctx->end += res;
smcCopyToIram(IRAM_LOG_CTX_ADDR, working_buf, sizeof(working_buf));
// static const u32 max_log_sz = IRAM_LOG_MAX_SZ - sizeof(log_ctx_t);
// static u32 cur_log_offset = 0;
// static u32 start = 0;
// static bool init_done = false;
// if(!init_done){
// init_done = true;
// __attribute__((aligned(0x20))) log_ctx_t log_ctx;
// log_ctx.magic = 0xaabbccdd;
// log_ctx.sz = max_log_sz;
// log_ctx.start = 0;
// log_ctx.end = 0;
// smcCopyToIram(IRAM_LOG_CTX_ADDR, &log_ctx, sizeof(log_ctx_t));
// }
// if(working_buf[0] == '\x00') {
// return;
// }
// u32 len = strlen((char*)working_buf);
// u32 bytes_left = len + 1;
// if(cur_log_offset % 4) {
// char __attribute__((aligned(4))) prev[4] = {0};
// smcCopyFromIram(&prev, IRAM_LOG_CTX_ADDR + sizeof(log_ctx_t) + cur_log_offset, 4);
// uintptr_t target_addr = (uintptr_t)IRAM_LOG_CTX_ADDR + sizeof(log_ctx_t) + (cur_log_offset & ~3);
// u32 prev_len = cur_log_offset % 4;
// u32 prev_free = 4 - prev_len;
// u32 bytes_to_cpy = MIN(prev_free, bytes_left);
// memcpy(prev + prev_len, working_buf, bytes_to_cpy);
// bytes_left -= bytes_to_cpy;
// smcCopyToIram(target_addr, prev, 4);
// memmove(working_buf, working_buf + bytes_to_cpy, bytes_left);
// cur_log_offset += bytes_to_cpy;
// }
// if(cur_log_offset >= max_log_sz) {
// cur_log_offset = 0;
// start = cur_log_offset + 1;
// }
// char *cur = (char*)working_buf;
// while(bytes_left) {
// // cur_log_offset is now 4 byte aligned
// uintptr_t target_addr = (uintptr_t)IRAM_LOG_CTX_ADDR + sizeof(log_ctx_t) + cur_log_offset;
// u32 bytes_to_cpy = MIN(4096, bytes_left);
// bytes_to_cpy = MIN(bytes_to_cpy, 4096 - (target_addr % 4096));
// bytes_to_cpy = MIN(bytes_to_cpy, 4096 - (((uintptr_t)cur) % 4096));
// smcCopyToIram(target_addr, cur, bytes_to_cpy);
// bytes_left -= bytes_to_cpy;
// if(cur_log_offset >= max_log_sz) {
// cur_log_offset = 0;
// start = cur_log_offset + 1;
// }
// }
// __attribute__((aligned(0x20))) log_ctx_t log_ctx;
// log_ctx.magic = 0xaabbccdd;
// log_ctx.sz = max_log_sz;
// log_ctx.end = cur_log_offset;
// log_ctx.start = start;
// smcCopyToIram(IRAM_LOG_CTX_ADDR, &log_ctx, sizeof(log_ctx_t));
// if(cur_log_offset != 0) {
// cur_log_offset--;
// } else {
// cur_log_offset = max_log_sz - 1;
// }
}