diff --git a/.gitignore b/.gitignore index 739adc7..cd858b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,50 +1,3 @@ -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# ========================= -# Operating System Files -# ========================= - -# OSX -# ========================= - -.DS_Store -.AppleDouble -.LSOverride - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -# Build artifacts -*.o +libdynamiclibs.cbp +libdynamiclibs.depend +release/* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8c92b4e --- /dev/null +++ b/Makefile @@ -0,0 +1,123 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITPPC)),) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC) +endif +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=devkitPRO") +endif + +include $(DEVKITPPC)/wii_rules + +export PORTLIBS := $(DEVKITPRO)/portlibs/ppc + +#--------------------------------------------------------------------------------- +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +# DATA is a list of directories containing binary files +# LIBDIR is where the built library will be placed +# all directories are relative to this makefile +#--------------------------------------------------------------------------------- +BUILD ?= release +SOURCES := source +INCLUDES := include +DATA := +LIB := lib + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +CFLAGS = -g -Os -Wall -D__wiiu__ $(MACHDEP) $(INCLUDE) +CXXFLAGS = $(CFLAGS) + +ASFLAGS := -g + +export WIIUBIN := $(LIB)/libdynamiclibs.a + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +#--------------------------------------------------------------------------------- +LIBS := + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export TOPDIR ?= $(CURDIR)/.. + + +export DEPSDIR := $(CURDIR)/$(BUILD) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) -I$(PORTLIBS)/include -I$(PORTLIBS)/include + + + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) $(PORTLIBS)/lib + +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr debug release $(LIB) include + +all: $(WIIUBIN) + +install: + @cp $(BUILD)/lib/libdynamiclibs.a $(PORTLIBS)/lib + @mkdir -p $(PORTLIBS)/include/dynamic_libs + @cp source/*.h $(PORTLIBS)/include/dynamic_libs + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(WIIUBIN) : $(OFILES) $(LIB) + @rm -f "$(WIIUBIN)" + @$(AR) rcs "$(WIIUBIN)" $(OFILES) + @echo built ... $(notdir $@) + +$(LIB): + mkdir $(LIB) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- + diff --git a/README.md b/README.md index be82302..692077d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,31 @@ -# dynamic_libs -Dynamic libs for WiiU homebrew +# Dynamic libs for WiiU homebrew. + +## Compiling + +Install this static library into your portlibs folder via: + +``` +make && make install +``` + +## Usage + +To be able to use this library, you need to include the header initialize the OS functions. + +``` +InitOSFunctionPointers(); +``` + +After that, you can initialize any lib and use their functions. Example: + +``` +InitVPadFunctionPointers(); +InitProcUIFunctionPointers(); +``` + +Check out the header for more information. + +# Credits + +- Based on the dynamic_libs from dimok. +- Various other \ No newline at end of file diff --git a/acp_functions.c b/source/acp_functions.c similarity index 100% rename from acp_functions.c rename to source/acp_functions.c diff --git a/acp_functions.h b/source/acp_functions.h similarity index 98% rename from acp_functions.h rename to source/acp_functions.h index 328b9c3..33fe979 100644 --- a/acp_functions.h +++ b/source/acp_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" extern u32 acp_handle; diff --git a/aoc_functions.c b/source/aoc_functions.c similarity index 100% rename from aoc_functions.c rename to source/aoc_functions.c diff --git a/aoc_functions.h b/source/aoc_functions.h similarity index 98% rename from aoc_functions.h rename to source/aoc_functions.h index f2e8205..9e2272d 100644 --- a/aoc_functions.h +++ b/source/aoc_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" extern u32 aoc_handle; diff --git a/ax_functions.c b/source/ax_functions.c similarity index 99% rename from ax_functions.c rename to source/ax_functions.c index 7d91ecc..37dc869 100644 --- a/ax_functions.c +++ b/source/ax_functions.c @@ -21,7 +21,6 @@ * 3. This notice may not be removed or altered from any source * distribution. ***************************************************************************/ -#include "common/common.h" #include "os_functions.h" #include "ax_functions.h" diff --git a/ax_functions.h b/source/ax_functions.h similarity index 99% rename from ax_functions.h rename to source/ax_functions.h index 467a8b0..10885ae 100644 --- a/ax_functions.h +++ b/source/ax_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" extern u32 sound_handle; extern u32 sound_handle_old; diff --git a/curl_functions.c b/source/curl_functions.c similarity index 100% rename from curl_functions.c rename to source/curl_functions.c diff --git a/curl_functions.h b/source/curl_functions.h similarity index 98% rename from curl_functions.h rename to source/curl_functions.h index e40740b..638e103 100644 --- a/curl_functions.h +++ b/source/curl_functions.h @@ -28,7 +28,8 @@ extern "C" { #endif -#include +#include "os_types.h" + #include "socket_functions.h" typedef int socklen_t; #include diff --git a/fs_defs.h b/source/fs_defs.h similarity index 99% rename from fs_defs.h rename to source/fs_defs.h index cc4cce0..a75e772 100644 --- a/fs_defs.h +++ b/source/fs_defs.h @@ -1,8 +1,6 @@ #ifndef FS_DEFS_H #define FS_DEFS_H -#include - #ifdef __cplusplus extern "C" { #endif diff --git a/fs_functions.c b/source/fs_functions.c similarity index 100% rename from fs_functions.c rename to source/fs_functions.c diff --git a/fs_functions.h b/source/fs_functions.h similarity index 99% rename from fs_functions.h rename to source/fs_functions.h index 4728359..bc79045 100644 --- a/fs_functions.h +++ b/source/fs_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" #include "fs_defs.h" void InitFSFunctionPointers(void); diff --git a/gx2_functions.c b/source/gx2_functions.c similarity index 100% rename from gx2_functions.c rename to source/gx2_functions.c diff --git a/gx2_functions.h b/source/gx2_functions.h similarity index 99% rename from gx2_functions.h rename to source/gx2_functions.h index 9133fcc..e104d15 100644 --- a/gx2_functions.h +++ b/source/gx2_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" #include "gx2_types.h" extern u32 gx2_handle; diff --git a/gx2_types.h b/source/gx2_types.h similarity index 99% rename from gx2_types.h rename to source/gx2_types.h index e292318..a01262d 100644 --- a/gx2_types.h +++ b/source/gx2_types.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" //!----------------------------------------------------------------------------------------------------------------------- //! Constants diff --git a/nfp_functions.c b/source/nfp_functions.c similarity index 100% rename from nfp_functions.c rename to source/nfp_functions.c diff --git a/nfp_functions.h b/source/nfp_functions.h similarity index 98% rename from nfp_functions.h rename to source/nfp_functions.h index 67a3f79..ddab2dd 100644 --- a/nfp_functions.h +++ b/source/nfp_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" extern u32 nfp_handle; diff --git a/nn_act_functions.c b/source/nn_act_functions.c similarity index 100% rename from nn_act_functions.c rename to source/nn_act_functions.c diff --git a/nn_act_functions.h b/source/nn_act_functions.h similarity index 98% rename from nn_act_functions.h rename to source/nn_act_functions.h index a3cc26c..08a35ac 100644 --- a/nn_act_functions.h +++ b/source/nn_act_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" extern u32 nn_act_handle; diff --git a/nn_nim_functions.c b/source/nn_nim_functions.c similarity index 100% rename from nn_nim_functions.c rename to source/nn_nim_functions.c diff --git a/nn_nim_functions.h b/source/nn_nim_functions.h similarity index 92% rename from nn_nim_functions.h rename to source/nn_nim_functions.h index ac94cce..2f3d19f 100644 --- a/nn_nim_functions.h +++ b/source/nn_nim_functions.h @@ -5,7 +5,7 @@ extern "C" { #endif -#include +#include "os_types.h" /* Handle for coreinit */ extern u32 nn_nim_handle; diff --git a/nn_save_functions.c b/source/nn_save_functions.c similarity index 100% rename from nn_save_functions.c rename to source/nn_save_functions.c diff --git a/nn_save_functions.h b/source/nn_save_functions.h similarity index 98% rename from nn_save_functions.h rename to source/nn_save_functions.h index 81c153e..dd0e1fa 100644 --- a/nn_save_functions.h +++ b/source/nn_save_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" extern u32 nn_save_handle; diff --git a/ntag_functions.c b/source/ntag_functions.c similarity index 100% rename from ntag_functions.c rename to source/ntag_functions.c diff --git a/ntag_functions.h b/source/ntag_functions.h similarity index 98% rename from ntag_functions.h rename to source/ntag_functions.h index 0f7e631..97869a9 100644 --- a/ntag_functions.h +++ b/source/ntag_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" extern u32 ntag_handle; diff --git a/source/os_defs.h b/source/os_defs.h new file mode 100644 index 0000000..48a4c8f --- /dev/null +++ b/source/os_defs.h @@ -0,0 +1,25 @@ +#ifndef __OS_DEFS_H_ +#define __OS_DEFS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _OsSpecifics +{ + unsigned int addr_OSDynLoad_Acquire; + unsigned int addr_OSDynLoad_FindExport; + unsigned int addr_OSTitle_main_entry; + + unsigned int addr_KernSyscallTbl1; + unsigned int addr_KernSyscallTbl2; + unsigned int addr_KernSyscallTbl3; + unsigned int addr_KernSyscallTbl4; + unsigned int addr_KernSyscallTbl5; +} OsSpecifics; + +#ifdef __cplusplus +} +#endif + +#endif // __OS_DEFS_H_ diff --git a/os_functions.c b/source/os_functions.c similarity index 99% rename from os_functions.c rename to source/os_functions.c index 9f74273..0409f86 100644 --- a/os_functions.c +++ b/source/os_functions.c @@ -21,7 +21,6 @@ * 3. This notice may not be removed or altered from any source * distribution. ***************************************************************************/ -#include "common/common.h" #include "os_functions.h" u32 coreinit_handle __attribute__((section(".data"))) = 0; diff --git a/os_functions.h b/source/os_functions.h similarity index 98% rename from os_functions.h rename to source/os_functions.h index e7b6d06..5bb1381 100644 --- a/os_functions.h +++ b/source/os_functions.h @@ -24,14 +24,22 @@ #ifndef __OS_FUNCTIONS_H_ #define __OS_FUNCTIONS_H_ -#include -#include "common/os_defs.h" #include "os_types.h" +#include "os_defs.h" #ifdef __cplusplus extern "C" { #endif +#ifndef MEM_BASE +#define MEM_BASE (0x00800000) +#endif + + +#define OS_FIRMWARE (*(volatile u32*)(MEM_BASE + 0x1400 + 0x04)) + +#define OS_SPECIFICS ((OsSpecifics*)(MEM_BASE + 0x1500)) + /* Disassembler */ typedef void (*DisasmReport)(char *outputBuffer, ...); diff --git a/os_types.h b/source/os_types.h similarity index 62% rename from os_types.h rename to source/os_types.h index b8b5bd5..21be4c0 100644 --- a/os_types.h +++ b/source/os_types.h @@ -5,8 +5,44 @@ extern "C" { #endif -#include +#include +#include +#include +#include +/*+----------------------------------------------------------------------------------------------+*/ +typedef uint8_t u8; ///< 8bit unsigned integer +typedef uint16_t u16; ///< 16bit unsigned integer +typedef uint32_t u32; ///< 32bit unsigned integer +typedef uint64_t u64; ///< 64bit unsigned integer +/*+----------------------------------------------------------------------------------------------+*/ +typedef int8_t s8; ///< 8bit signed integer +typedef int16_t s16; ///< 16bit signed integer +typedef int32_t s32; ///< 32bit signed integer +typedef int64_t s64; ///< 64bit signed integer +/*+----------------------------------------------------------------------------------------------+*/ +typedef volatile u8 vu8; ///< 8bit unsigned volatile integer +typedef volatile u16 vu16; ///< 16bit unsigned volatile integer +typedef volatile u32 vu32; ///< 32bit unsigned volatile integer +typedef volatile u64 vu64; ///< 64bit unsigned volatile integer +/*+----------------------------------------------------------------------------------------------+*/ +typedef volatile s8 vs8; ///< 8bit signed volatile integer +typedef volatile s16 vs16; ///< 16bit signed volatile integer +typedef volatile s32 vs32; ///< 32bit signed volatile integer +typedef volatile s64 vs64; ///< 64bit signed volatile integer +/*+----------------------------------------------------------------------------------------------+*/ +// fixed point math typedefs +typedef s16 sfp16; ///< signed 8:8 fixed point +typedef s32 sfp32; ///< signed 20:8 fixed point +typedef u16 ufp16; ///< unsigned 8:8 fixed point +typedef u32 ufp32; ///< unsigned 24:8 fixed point +/*+----------------------------------------------------------------------------------------------+*/ +typedef float f32; +typedef double f64; +/*+----------------------------------------------------------------------------------------------+*/ +typedef volatile float vf32; +typedef volatile double vf64; +/*+----------------------------------------------------------------------------------------------+*/ #define OS_MESSAGE_NOBLOCK 0 #define OS_MESSAGE_BLOCK 1 diff --git a/padscore_functions.c b/source/padscore_functions.c similarity index 100% rename from padscore_functions.c rename to source/padscore_functions.c diff --git a/padscore_functions.h b/source/padscore_functions.h similarity index 99% rename from padscore_functions.h rename to source/padscore_functions.h index 141c786..5185836 100644 --- a/padscore_functions.h +++ b/source/padscore_functions.h @@ -28,12 +28,12 @@ extern "C" { #endif -#include "dynamic_libs/vpad_functions.h" +#include "os_types.h" + +#include "vpad_functions.h" extern u32 padscore_handle; -#include - #define WPAD_EXT_CORE 0 #define WPAD_EXT_NUNCHUK 1 #define WPAD_EXT_CLASSIC 2 diff --git a/proc_ui_functions.c b/source/proc_ui_functions.c similarity index 100% rename from proc_ui_functions.c rename to source/proc_ui_functions.c diff --git a/proc_ui_functions.h b/source/proc_ui_functions.h similarity index 98% rename from proc_ui_functions.h rename to source/proc_ui_functions.h index 92bd792..7e1ead1 100644 --- a/proc_ui_functions.h +++ b/source/proc_ui_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" extern u32 proc_ui_handle; diff --git a/socket_functions.c b/source/socket_functions.c similarity index 100% rename from socket_functions.c rename to source/socket_functions.c diff --git a/socket_functions.h b/source/socket_functions.h similarity index 99% rename from socket_functions.h rename to source/socket_functions.h index 6cd8839..f67c41c 100644 --- a/socket_functions.h +++ b/source/socket_functions.h @@ -28,9 +28,9 @@ extern "C" { #endif -extern u32 nsysnet_handle; +#include "os_types.h" -#include +extern u32 nsysnet_handle; extern u32 hostIpAddress; diff --git a/sys_functions.c b/source/sys_functions.c similarity index 100% rename from sys_functions.c rename to source/sys_functions.c diff --git a/sys_functions.h b/source/sys_functions.h similarity index 98% rename from sys_functions.h rename to source/sys_functions.h index c68e506..f57a240 100644 --- a/sys_functions.h +++ b/source/sys_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" extern u32 sysapp_handle; diff --git a/syshid_functions.c b/source/syshid_functions.c similarity index 100% rename from syshid_functions.c rename to source/syshid_functions.c diff --git a/syshid_functions.h b/source/syshid_functions.h similarity index 99% rename from syshid_functions.h rename to source/syshid_functions.h index 9e29133..65f4884 100644 --- a/syshid_functions.h +++ b/source/syshid_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" extern u32 syshid_handle; diff --git a/vpad_functions.c b/source/vpad_functions.c similarity index 100% rename from vpad_functions.c rename to source/vpad_functions.c diff --git a/vpad_functions.h b/source/vpad_functions.h similarity index 99% rename from vpad_functions.h rename to source/vpad_functions.h index cc24392..6620295 100644 --- a/vpad_functions.h +++ b/source/vpad_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -#include +#include "os_types.h" extern u32 vpad_handle; extern u32 vpadbase_handle;