mirror of
https://github.com/wiiu-env/WiiUPluginSystem.git
synced 2024-12-25 01:21:57 +01:00
[Example Plugin] Updated the example plugin
- It's now linking with libc/libutils/libdynamiclibs - moved the main.c into the a "src" folder [Loader]- Added DCFlushRange and DCInvalidateRange - Improved logging. Finally we can load the plugin from the sdcard and call it's function!
This commit is contained in:
parent
4ce98a64f1
commit
10c5eccd93
@ -18,18 +18,22 @@ endif
|
|||||||
|
|
||||||
WUPSDIR := $(DEVKITPRO)/wups
|
WUPSDIR := $(DEVKITPRO)/wups
|
||||||
GCC_VER := $(shell $(DEVKITPPC)/bin/powerpc-eabi-gcc -dumpversion)
|
GCC_VER := $(shell $(DEVKITPPC)/bin/powerpc-eabi-gcc -dumpversion)
|
||||||
|
PORTLIBS := $(DEVKITPRO)/portlibs/ppc
|
||||||
|
|
||||||
PATH := $(DEVKITPPC)/bin:$(PATH)
|
PATH := $(DEVKITPPC)/bin:$(PATH)
|
||||||
LIB_INC_DIRS := $(DEVKITPPC)/lib/gcc/powerpc-eabi/$(GCC_VER)/include \
|
LIB_INC_DIRS := $(DEVKITPPC)/lib/gcc/powerpc-eabi/$(GCC_VER)/include \
|
||||||
$(DEVKITPPC)/lib/gcc/powerpc-eabi/$(GCC_VER)/include-fixed \
|
|
||||||
$(DEVKITPPC)/lib/gcc/powerpc-eabi/$(GCC_VER)/include-fixed \
|
$(DEVKITPPC)/lib/gcc/powerpc-eabi/$(GCC_VER)/include-fixed \
|
||||||
$(DEVKITPPC)/powerpc-eabi/include \
|
$(DEVKITPPC)/powerpc-eabi/include \
|
||||||
|
$(PORTLIBS)/include \
|
||||||
|
$(PORTLIBS)/include/libutils \
|
||||||
$(WUPSDIR)/include
|
$(WUPSDIR)/include
|
||||||
|
|
||||||
include makefile.mk
|
include makefile.mk
|
||||||
|
|
||||||
LIB_DIRS += $(DEVKITPPC)/lib/gcc/powerpc-eabi/$(GCC_VER)
|
LIB_DIRS += $(DEVKITPPC)/lib/gcc/powerpc-eabi/$(GCC_VER) \
|
||||||
LIBS += gcc
|
$(DEVKITPPC)/powerpc-eabi/ \
|
||||||
|
$(PORTLIBS)/lib
|
||||||
|
LIBS += c dynamiclibs utils
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Parameters
|
# Parameters
|
||||||
|
|
||||||
@ -63,11 +67,11 @@ OBJDUMP := $(PREFIX)objdump
|
|||||||
# --gc-sections: remove unneeded symbols
|
# --gc-sections: remove unneeded symbols
|
||||||
# -T: use the linker script specified (to force certain wups sections together)
|
# -T: use the linker script specified (to force certain wups sections together)
|
||||||
# -Map: generate a map file
|
# -Map: generate a map file
|
||||||
LDFLAGS += --relocatable -s -u wups_load -u wups_meta \
|
LDFLAGS += --relocatable -s --gc-sections -u wups_load -u wups_meta \
|
||||||
-T $(WUPSDIR)/wups.ld \
|
-T $(WUPSDIR)/wups.ld \
|
||||||
$(patsubst %,-Map %,$(strip $(MAP)))
|
$(patsubst %,-Map %,$(strip $(MAP))) -wrap malloc -wrap free -wrap memalign -wrap calloc -wrap realloc -wrap malloc_usable_size -wrap _malloc_r -wrap _free_r -wrap _realloc_r -wrap _calloc_r -wrap _memalign_r -wrap _malloc_usable_size_r
|
||||||
LD1FLAGS += --relocatable -s \
|
LD1FLAGS += --relocatable -s \
|
||||||
-T $(WUPSDIR)/wups_elf.ld
|
-T $(WUPSDIR)/wups_elf.ld -wrap malloc -wrap free -wrap memalign -wrap calloc -wrap realloc -wrap malloc_usable_size -wrap _malloc_r -wrap _free_r -wrap _realloc_r -wrap _calloc_r -wrap _memalign_r -wrap _malloc_usable_size_r
|
||||||
|
|
||||||
# -O2: optimise lots
|
# -O2: optimise lots
|
||||||
# -Wall: generate lots of warnings
|
# -Wall: generate lots of warnings
|
||||||
@ -88,11 +92,11 @@ LD1FLAGS += --relocatable -s \
|
|||||||
# -memb: enable embedded application specific compilation
|
# -memb: enable embedded application specific compilation
|
||||||
# -ffunction-sections: split up functions so linker can garbage collect
|
# -ffunction-sections: split up functions so linker can garbage collect
|
||||||
# -fdata-sections: split up data so linker can garbage collect
|
# -fdata-sections: split up data so linker can garbage collect
|
||||||
CFLAGS += -O0 -Wall -x c -std=gnu99 \
|
CFLAGS += -shared -fPIC -O0 -Wall -x c -std=c11 -DGEKKO_U -D__wiiu__ -mrvl -mcpu=750 -meabi -mhard-float -fshort-wchar -fno-common -msdata=none -memb -ffunction-sections -fdata-sections
|
||||||
-nostdinc -ffreestanding \
|
|
||||||
-DGEKKO_U -D__wiiu__ \
|
CFLAGS += -D__LOGGING__
|
||||||
-mrvl -mcpu=750 -meabi -mhard-float -fshort-wchar -fno-common \
|
|
||||||
-msdata=none -memb -ffunction-sections -fdata-sections
|
|
||||||
|
|
||||||
ifdef DEBUG
|
ifdef DEBUG
|
||||||
else
|
else
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
#include <wups.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
WUPS_MODULE_NAME("test module");
|
|
||||||
WUPS_MODULE_VERSION("v1.0");
|
|
||||||
WUPS_MODULE_AUTHOR("Maschell");
|
|
||||||
WUPS_MODULE_LICENSE("BSD");
|
|
||||||
|
|
||||||
int func(void);
|
|
||||||
int func2(void);
|
|
||||||
|
|
||||||
static int value = 15;
|
|
||||||
|
|
||||||
static int my_func(void)
|
|
||||||
{
|
|
||||||
int res = 17;
|
|
||||||
return 4 * value * res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int my_func2(void)
|
|
||||||
{
|
|
||||||
int res = 15;
|
|
||||||
return 4 * value * res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
WUPS_MUST_REPLACE(func,WUPS_LOADER_LIBRARY_GX2, my_func);
|
|
||||||
WUPS_MUST_REPLACE(func2,WUPS_LOADER_LIBRARY_COREINIT, my_func2);
|
|
@ -2,9 +2,10 @@
|
|||||||
# Source files
|
# Source files
|
||||||
|
|
||||||
# The source files to compile.
|
# The source files to compile.
|
||||||
SRC := main.c
|
SRC := src/main.c
|
||||||
|
|
||||||
# Include directories
|
# Include directories
|
||||||
INC_DIRS :=
|
INC_DIRS := src
|
||||||
# Library directories
|
# Library directories
|
||||||
LIB_DIRS :=
|
LIB_DIRS :=
|
||||||
# The names of libraries to use.
|
# The names of libraries to use.
|
||||||
|
31
example_plugin/src/main.c
Normal file
31
example_plugin/src/main.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <wups.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "dynamic_libs/os_functions.h"
|
||||||
|
#include "dynamic_libs/socket_functions.h"
|
||||||
|
#include "utils/logger.h"
|
||||||
|
|
||||||
|
|
||||||
|
WUPS_MODULE_NAME("test module");
|
||||||
|
WUPS_MODULE_VERSION("v1.0");
|
||||||
|
WUPS_MODULE_AUTHOR("Maschell");
|
||||||
|
WUPS_MODULE_LICENSE("BSD");
|
||||||
|
|
||||||
|
int func(void);
|
||||||
|
|
||||||
|
|
||||||
|
static int my_func2(void)
|
||||||
|
{
|
||||||
|
InitOSFunctionPointers();
|
||||||
|
InitSocketFunctionPointers();
|
||||||
|
|
||||||
|
log_init();
|
||||||
|
|
||||||
|
//log_printf is not working.
|
||||||
|
log_print("Logging from custom function.\n");
|
||||||
|
|
||||||
|
return 43;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WUPS_MUST_REPLACE(func,WUPS_LOADER_LIBRARY_GX2, my_func2);
|
@ -74,12 +74,17 @@ void loadAndProcessElf(const char * elfPath){
|
|||||||
if(Module_CheckFile(elfPath)){
|
if(Module_CheckFile(elfPath)){
|
||||||
Module_Load(elfPath);
|
Module_Load(elfPath);
|
||||||
DEBUG_FUNCTION_LINE("Found %d modules!\n",module_list_count);
|
DEBUG_FUNCTION_LINE("Found %d modules!\n",module_list_count);
|
||||||
//printInfos();
|
printInfos();
|
||||||
unsigned char * space = (unsigned char*)0x00910000;
|
unsigned char * space = (unsigned char*)0x00910000;
|
||||||
Module_ListLink(&space);
|
Module_ListLink(&space);
|
||||||
|
|
||||||
|
printInfos();
|
||||||
|
|
||||||
|
DCFlushRange ((void*)0x00850000,0x00910000-0x00850000);
|
||||||
|
DCInvalidateRange((void*)0x00850000,0x00910000-0x00850000);
|
||||||
|
|
||||||
if(module_relocations_count == 0){
|
if(module_relocations_count == 0){
|
||||||
DEBUG_FUNCTION_LINE("We need no relocations, we can call the functions!!\n");
|
DEBUG_FUNCTION_LINE("We need no more relocations, we can call the functions!!\n");
|
||||||
DEBUG_FUNCTION_LINE("Calling %d functions!\n",module_entries_count);
|
DEBUG_FUNCTION_LINE("Calling %d functions!\n",module_entries_count);
|
||||||
for (unsigned int i = 0; i < module_entries_count; i++) {
|
for (unsigned int i = 0; i < module_entries_count; i++) {
|
||||||
DEBUG_FUNCTION_LINE("--- Function %d ---\n",i);
|
DEBUG_FUNCTION_LINE("--- Function %d ---\n",i);
|
||||||
@ -87,9 +92,11 @@ void loadAndProcessElf(const char * elfPath){
|
|||||||
module_entries[i].type == WUPS_LOADER_ENTRY_FUNCTION_MANDATORY){
|
module_entries[i].type == WUPS_LOADER_ENTRY_FUNCTION_MANDATORY){
|
||||||
DEBUG_FUNCTION_LINE("Let's call the function: %s \n",module_entries[i].data._function.name);
|
DEBUG_FUNCTION_LINE("Let's call the function: %s \n",module_entries[i].data._function.name);
|
||||||
int ret = ( (int (*)(void))((unsigned int*)module_entries[i].data._function.target) )();
|
int ret = ( (int (*)(void))((unsigned int*)module_entries[i].data._function.target) )();
|
||||||
DEBUG_FUNCTION_LINE("result: %d \n",ret);
|
DEBUG_FUNCTION_LINE("result: %08X \n",ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
DEBUG_FUNCTION_LINE("There are still symbols that need to be resolved. Can't call the functions\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user