diff --git a/example_plugin/Makefile b/example_plugin/Makefile index 2ce2e3c..8ff7784 100644 --- a/example_plugin/Makefile +++ b/example_plugin/Makefile @@ -16,20 +16,24 @@ ifeq ($(strip $(DEVKITPPC)),) $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") endif -WUPSDIR := $(DEVKITPRO)/wups -GCC_VER := $(shell $(DEVKITPPC)/bin/powerpc-eabi-gcc -dumpversion) +WUPSDIR := $(DEVKITPRO)/wups +GCC_VER := $(shell $(DEVKITPPC)/bin/powerpc-eabi-gcc -dumpversion) +PORTLIBS := $(DEVKITPRO)/portlibs/ppc PATH := $(DEVKITPPC)/bin:$(PATH) 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)/powerpc-eabi/include \ + $(PORTLIBS)/include \ + $(PORTLIBS)/include/libutils \ $(WUPSDIR)/include include makefile.mk -LIB_DIRS += $(DEVKITPPC)/lib/gcc/powerpc-eabi/$(GCC_VER) -LIBS += gcc +LIB_DIRS += $(DEVKITPPC)/lib/gcc/powerpc-eabi/$(GCC_VER) \ + $(DEVKITPPC)/powerpc-eabi/ \ + $(PORTLIBS)/lib +LIBS += c dynamiclibs utils ############################################################################### # Parameters @@ -63,11 +67,11 @@ OBJDUMP := $(PREFIX)objdump # --gc-sections: remove unneeded symbols # -T: use the linker script specified (to force certain wups sections together) # -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 \ - $(patsubst %,-Map %,$(strip $(MAP))) -LD1FLAGS += --relocatable -s \ - -T $(WUPSDIR)/wups_elf.ld + $(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 \ + -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 # -Wall: generate lots of warnings @@ -88,12 +92,12 @@ LD1FLAGS += --relocatable -s \ # -memb: enable embedded application specific compilation # -ffunction-sections: split up functions so linker can garbage collect # -fdata-sections: split up data so linker can garbage collect -CFLAGS += -O0 -Wall -x c -std=gnu99 \ - -nostdinc -ffreestanding \ - -DGEKKO_U -D__wiiu__ \ - -mrvl -mcpu=750 -meabi -mhard-float -fshort-wchar -fno-common \ - -msdata=none -memb -ffunction-sections -fdata-sections +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 +CFLAGS += -D__LOGGING__ + + + ifdef DEBUG else CFLAGS += -DNDEBUG diff --git a/example_plugin/main.c b/example_plugin/main.c deleted file mode 100644 index 01ccf6b..0000000 --- a/example_plugin/main.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -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); diff --git a/example_plugin/makefile.mk b/example_plugin/makefile.mk index b7fa45f..3d1d209 100644 --- a/example_plugin/makefile.mk +++ b/example_plugin/makefile.mk @@ -2,9 +2,10 @@ # Source files # The source files to compile. -SRC := main.c +SRC := src/main.c + # Include directories -INC_DIRS := +INC_DIRS := src # Library directories LIB_DIRS := # The names of libraries to use. diff --git a/example_plugin/src/main.c b/example_plugin/src/main.c new file mode 100644 index 0000000..af45e84 --- /dev/null +++ b/example_plugin/src/main.c @@ -0,0 +1,31 @@ +#include +#include +#include +#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); diff --git a/loader/src/main.cpp b/loader/src/main.cpp index 958988b..0ea0b99 100644 --- a/loader/src/main.cpp +++ b/loader/src/main.cpp @@ -74,12 +74,17 @@ void loadAndProcessElf(const char * elfPath){ if(Module_CheckFile(elfPath)){ Module_Load(elfPath); DEBUG_FUNCTION_LINE("Found %d modules!\n",module_list_count); - //printInfos(); + printInfos(); unsigned char * space = (unsigned char*)0x00910000; Module_ListLink(&space); + printInfos(); + + DCFlushRange ((void*)0x00850000,0x00910000-0x00850000); + DCInvalidateRange((void*)0x00850000,0x00910000-0x00850000); + 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); for (unsigned int i = 0; i < module_entries_count; 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){ 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) )(); - 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"); } } diff --git a/wups.ld b/wups.ld index 7a60c45..c36c85f 100644 --- a/wups.ld +++ b/wups.ld @@ -14,6 +14,12 @@ SECTIONS { .rodata : { *(.rodata*) } + .got2 : { + *(.got2*) + } + .sbss : { + *(.sbss*) + } .bss : { *(.bss*) }