mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2024-11-25 06:06:53 +01:00
Use libkernel for a KernelCopy instead register own kernel functions.
This commit is contained in:
parent
9ee8085a64
commit
13e5d854d1
3
Makefile
3
Makefile
@ -24,7 +24,6 @@ TARGET := PluginBackend
|
|||||||
BUILD := build
|
BUILD := build
|
||||||
SOURCES := source \
|
SOURCES := source \
|
||||||
source/elfio \
|
source/elfio \
|
||||||
source/kernel \
|
|
||||||
source/patcher \
|
source/patcher \
|
||||||
source/plugin \
|
source/plugin \
|
||||||
source/utils
|
source/utils
|
||||||
@ -44,7 +43,7 @@ CXXFLAGS := $(CFLAGS) -std=c++17
|
|||||||
ASFLAGS := -g $(ARCH)
|
ASFLAGS := -g $(ARCH)
|
||||||
LDFLAGS = -g $(ARCH) $(WUMSSPECS) -Wl,-Map,$(notdir $*.map)
|
LDFLAGS = -g $(ARCH) $(WUMSSPECS) -Wl,-Map,$(notdir $*.map)
|
||||||
|
|
||||||
LIBS := -lwums -lwut -lwups
|
LIBS := -lwums -lwut -lwups -lkernel
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# list of directories containing libraries, this must be the top level
|
# list of directories containing libraries, this must be the top level
|
||||||
|
@ -29,6 +29,7 @@ DEVKITPPC=/opt/devkitpro/devkitPPC
|
|||||||
```
|
```
|
||||||
|
|
||||||
Also make sure to install [wut](https://github.com/decaf-emu/wut), [WiiUPluginSystem](https://github.com/wiiu-env/WiiUPluginSystem) and the [WiiUModuleSystem](https://github.com/wiiu-env/WiiUModuleSystem).
|
Also make sure to install [wut](https://github.com/decaf-emu/wut), [WiiUPluginSystem](https://github.com/wiiu-env/WiiUPluginSystem) and the [WiiUModuleSystem](https://github.com/wiiu-env/WiiUModuleSystem).
|
||||||
|
It requires the [KernelModule](https://github.com/wiiu-env/KernelModule) to be running at the same time and it's linking aginst [libkernel](https://github.com/wiiu-env/libkernel).
|
||||||
|
|
||||||
# Credits
|
# Credits
|
||||||
- Maschell
|
- Maschell
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
|
|
||||||
.global SCKernelCopyData
|
|
||||||
SCKernelCopyData:
|
|
||||||
// Disable data address translation
|
|
||||||
mfmsr %r6
|
|
||||||
li %r7, 0x10
|
|
||||||
andc %r6, %r6, %r7
|
|
||||||
mtmsr %r6
|
|
||||||
|
|
||||||
// Copy data
|
|
||||||
addi %r3, %r3, -1
|
|
||||||
addi %r4, %r4, -1
|
|
||||||
mtctr %r5
|
|
||||||
SCKernelCopyData_loop:
|
|
||||||
lbzu %r5, 1(%r4)
|
|
||||||
stbu %r5, 1(%r3)
|
|
||||||
bdnz SCKernelCopyData_loop
|
|
||||||
|
|
||||||
// Enable data address translation
|
|
||||||
ori %r6, %r6, 0x10
|
|
||||||
mtmsr %r6
|
|
||||||
blr
|
|
||||||
|
|
||||||
.global KernelCopyData
|
|
||||||
KernelCopyData:
|
|
||||||
li %r0, 0x2500
|
|
||||||
sc
|
|
||||||
blr
|
|
||||||
|
|
||||||
.globl SC0x36_KernelReadSRs
|
|
||||||
SC0x36_KernelReadSRs:
|
|
||||||
li %r0, 0x3600
|
|
||||||
sc
|
|
||||||
blr
|
|
||||||
|
|
||||||
.globl SC0x0A_KernelWriteSRs
|
|
||||||
SC0x0A_KernelWriteSRs:
|
|
||||||
li %r0, 0x0A00
|
|
||||||
sc
|
|
||||||
blr
|
|
@ -1,36 +0,0 @@
|
|||||||
#ifndef __KERNEL_DEFS_H_
|
|
||||||
#define __KERNEL_DEFS_H_
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define KERN_SYSCALL_TBL1 0xFFE84C70 //Unknown
|
|
||||||
#define KERN_SYSCALL_TBL2 0xFFE85070 //Games
|
|
||||||
#define KERN_SYSCALL_TBL3 0xFFE85470 //Loader
|
|
||||||
#define KERN_SYSCALL_TBL4 0xFFEAAA60 //Home menu
|
|
||||||
#define KERN_SYSCALL_TBL5 0xFFEAAE60 //Browser
|
|
||||||
|
|
||||||
typedef struct _sr_table_t {
|
|
||||||
uint32_t value[16];
|
|
||||||
uint32_t sdr1;
|
|
||||||
} sr_table_t;
|
|
||||||
|
|
||||||
typedef struct _bat_t {
|
|
||||||
uint32_t h;
|
|
||||||
uint32_t l;
|
|
||||||
} bat_t;
|
|
||||||
|
|
||||||
typedef struct _bat_table_t {
|
|
||||||
bat_t bat[8];
|
|
||||||
} bat_table_t;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __KERNEL_DEFS_H_
|
|
@ -1,92 +0,0 @@
|
|||||||
#include "kernel_utils.h"
|
|
||||||
#include "kernel_defs.h"
|
|
||||||
#include <coreinit/cache.h>
|
|
||||||
#include <coreinit/memorymap.h>
|
|
||||||
|
|
||||||
|
|
||||||
extern void SCKernelCopyData(uint32_t dst, uint32_t src, uint32_t len);
|
|
||||||
|
|
||||||
void KernelWrite(uint32_t addr, const void *data, uint32_t length) {
|
|
||||||
uint32_t dst = (uint32_t) OSEffectiveToPhysical(addr);
|
|
||||||
uint32_t src = (uint32_t) OSEffectiveToPhysical((uint32_t) data);
|
|
||||||
KernelCopyData(dst, src, length);
|
|
||||||
DCFlushRange((void *) addr, length);
|
|
||||||
ICInvalidateRange((void *) addr, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
void KernelWriteU32(uint32_t addr, uint32_t value) {
|
|
||||||
uint32_t dst = (uint32_t) OSEffectiveToPhysical(addr);
|
|
||||||
uint32_t src = (uint32_t) OSEffectiveToPhysical((uint32_t) &value);
|
|
||||||
KernelCopyData(dst, src, 4);
|
|
||||||
DCFlushRange((void *) addr, 4);
|
|
||||||
ICInvalidateRange((void *) addr, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write a 32-bit word with kernel permissions */
|
|
||||||
void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value) {
|
|
||||||
asm volatile (
|
|
||||||
"li 3,1\n"
|
|
||||||
"li 4,0\n"
|
|
||||||
"mr 5,%1\n"
|
|
||||||
"li 6,0\n"
|
|
||||||
"li 7,0\n"
|
|
||||||
"lis 8,1\n"
|
|
||||||
"mr 9,%0\n"
|
|
||||||
"mr %1,1\n"
|
|
||||||
"li 0,0x3500\n"
|
|
||||||
"sc\n"
|
|
||||||
"nop\n"
|
|
||||||
"mr 1,%1\n"
|
|
||||||
:
|
|
||||||
: "r"(addr), "r"(value)
|
|
||||||
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
|
|
||||||
"11", "12"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read a 32-bit word with kernel permissions */
|
|
||||||
uint32_t __attribute__ ((noinline)) kern_read(const void *addr) {
|
|
||||||
uint32_t result;
|
|
||||||
asm volatile (
|
|
||||||
"li 3,1\n"
|
|
||||||
"li 4,0\n"
|
|
||||||
"li 5,0\n"
|
|
||||||
"li 6,0\n"
|
|
||||||
"li 7,0\n"
|
|
||||||
"lis 8,1\n"
|
|
||||||
"mr 9,%1\n"
|
|
||||||
"li 0,0x3400\n"
|
|
||||||
"mr %0,1\n"
|
|
||||||
"sc\n"
|
|
||||||
"nop\n"
|
|
||||||
"mr 1,%0\n"
|
|
||||||
"mr %0,3\n"
|
|
||||||
: "=r"(result)
|
|
||||||
: "b"(addr)
|
|
||||||
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
|
|
||||||
"11", "12"
|
|
||||||
);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PatchSyscall(int index, uint32_t addr) {
|
|
||||||
//DEBUG_FUNCTION_LINE("Patching Syscall 0x%02X\n",index);
|
|
||||||
kern_write((void *) (KERN_SYSCALL_TBL1 + index * 4), addr);
|
|
||||||
kern_write((void *) (KERN_SYSCALL_TBL2 + index * 4), addr);
|
|
||||||
kern_write((void *) (KERN_SYSCALL_TBL3 + index * 4), addr);
|
|
||||||
kern_write((void *) (KERN_SYSCALL_TBL4 + index * 4), addr);
|
|
||||||
kern_write((void *) (KERN_SYSCALL_TBL5 + index * 4), addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void kernelInitialize() {
|
|
||||||
static uint8_t ucSyscallsSetupRequired = 1;
|
|
||||||
if (!ucSyscallsSetupRequired)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ucSyscallsSetupRequired = 0;
|
|
||||||
|
|
||||||
PatchSyscall(0x25, (uint32_t) SCKernelCopyData);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
#ifndef __KERNEL_UTILS_H_
|
|
||||||
#define __KERNEL_UTILS_H_
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "kernel_defs.h"
|
|
||||||
|
|
||||||
extern void KernelCopyData(uint32_t dst, uint32_t src, uint32_t len);
|
|
||||||
|
|
||||||
void kern_write(void *addr, uint32_t value);
|
|
||||||
|
|
||||||
uint32_t kern_read(const void *addr);
|
|
||||||
|
|
||||||
void SC0x0A_KernelWriteSRs(sr_table_t *table);
|
|
||||||
|
|
||||||
void SC0x36_KernelReadSRs(sr_table_t *table);
|
|
||||||
|
|
||||||
void KernelReadPTE(uint32_t addr, int32_t length);
|
|
||||||
|
|
||||||
void KernelWritePTE(uint32_t addr, int32_t length);
|
|
||||||
|
|
||||||
void KernelWrite(uint32_t addr, const void *data, uint32_t length);
|
|
||||||
|
|
||||||
void KernelWriteU32(uint32_t addr, uint32_t value);
|
|
||||||
|
|
||||||
void kernelInitialize();
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __KERNEL_UTILS_H_
|
|
@ -27,10 +27,9 @@
|
|||||||
#include "function_patcher.h"
|
#include "function_patcher.h"
|
||||||
#include <utils/logger.h>
|
#include <utils/logger.h>
|
||||||
#include <utils/utils.h>
|
#include <utils/utils.h>
|
||||||
#include <kernel/kernel_defs.h>
|
|
||||||
#include <kernel/kernel_utils.h>
|
|
||||||
#include <coreinit/memorymap.h>
|
#include <coreinit/memorymap.h>
|
||||||
#include <coreinit/cache.h>
|
#include <coreinit/cache.h>
|
||||||
|
#include <kernel/kernel.h>
|
||||||
#include <whb/log.h>
|
#include <whb/log.h>
|
||||||
#include <coreinit/dynload.h>
|
#include <coreinit/dynload.h>
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include <coreinit/dynload.h>
|
#include <coreinit/dynload.h>
|
||||||
#include <coreinit/debug.h>
|
#include <coreinit/debug.h>
|
||||||
|
|
||||||
#include "kernel/kernel_utils.h"
|
#include <kernel/kernel.h>
|
||||||
#include "function_patcher.h"
|
#include "function_patcher.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user