diff --git a/Dockerfile b/Dockerfile index 09613bd..750b4da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM wiiuenv/devkitppc:20210414 +FROM wiiuenv/devkitppc:20210917 WORKDIR build COPY . . diff --git a/Makefile b/Makefile index 55a2099..11a0baa 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ TOPDIR ?= $(CURDIR) include $(TOPDIR)/share/wums_rules export WUMS_MAJOR := 0 -export WUMS_MINOR := 1 -export WUMS_PATCH := 3 +export WUMS_MINOR := 2 +export WUMS_PATCH := 0 VERSION := $(WUMS_MAJOR).$(WUMS_MINOR).$(WUMS_PATCH) diff --git a/include/wums.h b/include/wums.h index 7a26dc5..a66b630 100644 --- a/include/wums.h +++ b/include/wums.h @@ -1,8 +1,6 @@ -#ifndef WUMS_H_ -#define WUMS_H_ +#pragma once +#include "wums/meta.h" #include "wums/common.h" #include "wums/exports.h" -#include "wums/hooks.h" - -#endif /* WUMS_H_ */ \ No newline at end of file +#include "wums/hooks.h" \ No newline at end of file diff --git a/include/wums/common.h b/include/wums/common.h index 806f54b..8119f06 100644 --- a/include/wums/common.h +++ b/include/wums/common.h @@ -2,7 +2,7 @@ * by Alex Chadwick * * Copyright (C) 2014, Alex Chadwick - * Modified by Maschell, 2018-2020 + * Modified by Maschell, 2018-2021 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,18 +23,9 @@ * SOFTWARE. */ -#ifndef WUMS_COMMON_DEF_H_ -#define WUMS_COMMON_DEF_H_ +#pragma once -#include #include -#include -#include -#include -#include -#include -#include -#include "defines/module_defines.h" #ifdef __cplusplus extern "C" { @@ -46,17 +37,6 @@ extern "C" { extern const char wums_meta_ ## id [] WUMS_SECTION("meta"); \ const char wums_meta_ ## id [] = #id "=" value -#define WUMS_MODULE_EXPORT_NAME(x) WUMS_META(export_name, x); WUMS_META(wum, "0.1"); WUMS_META(buildtimestamp, __DATE__ " " __TIME__) -#define WUMS_MODULE_AUTHOR(x) WUMS_META(author, x) -#define WUMS_MODULE_VERSION(x) WUMS_META(version, x) -#define WUMS_MODULE_LICENSE(x) WUMS_META(license, x) -#define WUMS_MODULE_DESCRIPTION(x) WUMS_META(description, x) -#define WUMS_MODULE_SKIP_ENTRYPOINT() WUMS_META(skipEntrypoint, "true") -#define WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK() WUMS_META(initBeforeRelocationDoneHook, "true") -#define WUMS_MODULE_SKIP_WUT_INIT() WUMS_META(skipwutInit, "true") - #ifdef __cplusplus } #endif - -#endif /* WUMS_COMMON_DEF_H_ */ diff --git a/include/wums/defines/dynamic_linking_defines.h b/include/wums/defines/dynamic_linking_defines.h index 716936a..6711ea2 100644 --- a/include/wums/defines/dynamic_linking_defines.h +++ b/include/wums/defines/dynamic_linking_defines.h @@ -17,6 +17,7 @@ #pragma once +#include #include #include @@ -39,13 +40,13 @@ typedef struct _dyn_linking_function_t { typedef struct _dyn_linking_import_t { char importName[DYN_LINK_IMPORT_NAME_LENGTH + 1]; - bool isData = false; + bool isData; } dyn_linking_import_t; typedef struct _dyn_linking_relocation_entry_t { - dyn_linking_function_t *functionEntry = NULL; - dyn_linking_import_t *importEntry = NULL; - void *destination = NULL; + dyn_linking_function_t *functionEntry; + dyn_linking_import_t *importEntry; + void *destination; char type; size_t offset; int32_t addend; diff --git a/include/wums/defines/export_defines.h b/include/wums/defines/export_defines.h index bc66fdf..d061412 100644 --- a/include/wums/defines/export_defines.h +++ b/include/wums/defines/export_defines.h @@ -6,5 +6,5 @@ typedef struct export_data_t { uint32_t type; char name[EXPORT_MAXIMUM_NAME_LENGTH]; - uint32_t address = 0; + uint32_t address; } export_data_t; \ No newline at end of file diff --git a/include/wums/defines/module_defines.h b/include/wums/defines/module_defines.h index 6127d27..7994ace 100644 --- a/include/wums/defines/module_defines.h +++ b/include/wums/defines/module_defines.h @@ -32,15 +32,15 @@ extern "C" { #define DYN_LINK_RELOCATION_LIST_LENGTH 500 #define EXPORT_ENTRY_LIST_LENGTH 100 -#define HOOK_ENTRY_LIST_LENGTH 10 +#define HOOK_ENTRY_LIST_LENGTH 20 typedef struct hook_data_t { uint32_t type; - uint32_t target = 0; + uint32_t target; } hook_data_t; -struct module_information_single_t { - char path[MAXIMUM_MODULE_PATH_NAME_LENGTH] = ""; // Path where the module is stored +typedef struct module_information_single_t { + char path[MAXIMUM_MODULE_PATH_NAME_LENGTH]; // Path where the module is stored dyn_linking_relocation_entry_t linking_entries[DYN_LINK_RELOCATION_LIST_LENGTH]; char module_export_name[MAXIMUM_EXPORT_MODULE_NAME_LENGTH]; export_data_t export_entries[EXPORT_ENTRY_LIST_LENGTH]; @@ -55,19 +55,18 @@ struct module_information_single_t { uint32_t endAddress; uint8_t skipEntrypoint; uint8_t initBeforeRelocationDoneHook; - uint8_t skipWUTInit; -}; +} module_information_single_t; #define MAXIMUM_MODULES 8 -#define MODULE_INFORMATION_VERSION 0x00000003 +#define MODULE_INFORMATION_VERSION 0x00000004 -struct module_information_t { - uint32_t version = MODULE_INFORMATION_VERSION; - int32_t number_used_modules = 0; // Number of used function. Maximum is MAXIMUM_MODULES +typedef struct module_information_t { + uint32_t version; + int32_t number_used_modules; // Number of used function. Maximum is MAXIMUM_MODULES dyn_linking_relocation_data_t linking_data; relocation_trampolin_entry_t trampolines[DYN_LINK_TRAMPOLIN_LIST_LENGTH]; module_information_single_t module_data[MAXIMUM_MODULES]; -}; +} module_information_t; #ifdef __cplusplus } diff --git a/include/wums/defines/relocation_defines.h b/include/wums/defines/relocation_defines.h index 5efdf79..35b8d0e 100644 --- a/include/wums/defines/relocation_defines.h +++ b/include/wums/defines/relocation_defines.h @@ -16,5 +16,5 @@ typedef enum RelocationType{ typedef struct relocation_trampolin_entry_t { uint32_t id; uint32_t trampolin[4]; - RelocationTrampolinStatus status = RELOC_TRAMP_FREE; + RelocationTrampolinStatus status; } relocation_trampolin_entry_t; diff --git a/include/wums/exports.h b/include/wums/exports.h index 0e8f180..9393a90 100644 --- a/include/wums/exports.h +++ b/include/wums/exports.h @@ -2,7 +2,7 @@ * by Alex Chadwick * * Copyright (C) 2014, Alex Chadwick - * Modified by Maschell, 2018-2020 + * Modified by Maschell, 2018-2021 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,8 +23,7 @@ * SOFTWARE. */ -#ifndef WUMS_FUNCTION_EXPORT_DEF_H_ -#define WUMS_FUNCTION_EXPORT_DEF_H_ +#pragma once #include "common.h" @@ -55,9 +54,6 @@ typedef struct wums_entry_t { .address = (const void*) value \ } - #ifdef __cplusplus } -#endif - -#endif /* WUMS_FUNCTION_EXPORT_DEF_H_ */ +#endif \ No newline at end of file diff --git a/include/wums/hooks.h b/include/wums/hooks.h index fedd2e1..0fc3c0f 100644 --- a/include/wums/hooks.h +++ b/include/wums/hooks.h @@ -2,7 +2,7 @@ * by Alex Chadwick * * Copyright (C) 2014, Alex Chadwick - * Modified by Maschell, 2018-2020 + * Modified by Maschell, 2018-2021 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -40,11 +40,20 @@ extern "C" { } typedef enum wums_hook_type_t { + WUMS_HOOK_INIT_WUT_MALLOC, + WUMS_HOOK_FINI_WUT_MALLOC, + WUMS_HOOK_INIT_WUT_NEWLIB, + WUMS_HOOK_FINI_WUT_NEWLIB, + WUMS_HOOK_INIT_WUT_STDCPP, + WUMS_HOOK_FINI_WUT_STDCPP, + WUMS_HOOK_INIT_WUT_DEVOPTAB, + WUMS_HOOK_FINI_WUT_DEVOPTAB, + WUMS_HOOK_INIT_WUT_SOCKETS, + WUMS_HOOK_FINI_WUT_SOCKETS, + WUMS_HOOK_INIT, WUMS_HOOK_APPLICATION_STARTS, WUMS_HOOK_APPLICATION_ENDS, - WUMS_HOOK_INIT_WUT, - WUMS_HOOK_FINI_WUT, WUMS_HOOK_RELOCATIONS_DONE, WUMS_HOOK_APPLICATION_REQUESTS_EXIT, } wums_hook_type_t; @@ -63,8 +72,6 @@ typedef struct wums_relocs_done_args_t { } wums_relocs_done_args_t; #define WUMS_INITIALIZE(myargs) \ - WUMS_INIT_WUT(); \ - WUMS_FINI_WUT(); \ void __wums__init(wums_app_init_args_t);\ WUMS_HOOK_EX(WUMS_HOOK_INIT, __wums__init); \ void __wums__init(wums_app_init_args_t myargs) @@ -88,43 +95,67 @@ typedef struct wums_relocs_done_args_t { void __wums_relocations_done(wums_relocs_done_args_t);\ WUMS_HOOK_EX(WUMS_HOOK_RELOCATIONS_DONE, __wums_relocations_done); \ void __wums_relocations_done(wums_relocs_done_args_t myargs) - -#ifdef __cplusplus -#define WUMS_INIT_WUT() \ - void __wums_init_wut(void);\ - extern "C" void __init_wut(void);\ - void __wums_init_wut(){ \ - __init_wut(); \ - } \ - WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT, __wums_init_wut) -#else -#define WUMS_INIT_WUT() \ - void __wums_init_wut(void);\ - extern void __init_wut(void);\ - void __wums_init_wut(){ \ - __init_wut(); \ - } \ - WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT, __wums_init_wut) -#endif #ifdef __cplusplus -#define WUMS_FINI_WUT() \ - void __wums_fini_wut(void);\ - extern "C" void __fini_wut(void);\ - void __wums_fini_wut(){ \ - __fini_wut(); \ - } \ - WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT, __wums_fini_wut) +#define __EXTERN_C_MACRO extern "C" #else -#define WUMS_FINI_WUT() \ - void __wums_fini_wut(void);\ - extern void __fini_wut(void);\ - void __wums_fini_wut(){ \ - __fini_wut(); \ - } \ - WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT, __wums_fini_wut) +#define __EXTERN_C_MACRO #endif +#define WUMS_USE_WUT_MALLOC() \ + __EXTERN_C_MACRO void __init_wut_malloc(); \ + void on_init_wut_malloc(){ \ + __init_wut_malloc(); \ + }\ + WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_MALLOC,on_init_wut_malloc); \ + __EXTERN_C_MACRO void __fini_wut_malloc(); \ + void on_fini_wut_malloc(){ \ + __fini_wut_malloc(); \ + } \ + WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_MALLOC,on_fini_wut_malloc); \ + +#define WUMS_USE_WUT_DEVOPTAB() \ + __EXTERN_C_MACRO void __init_wut_devoptab(); \ + void on_init_wut_devoptab(){ \ + __init_wut_devoptab(); \ + }\ + WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_DEVOPTAB,on_init_wut_devoptab); \ + __EXTERN_C_MACRO void __fini_wut_devoptab(); \ + void on_fini_wut_devoptab(){ \ + __fini_wut_devoptab(); \ + }\ + WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_DEVOPTAB,on_fini_wut_devoptab); + +#define WUMS_USE_WUT_NEWLIB() \ + __EXTERN_C_MACRO void __init_wut_newlib(); \ + void on_init_wut_newlib(){ \ + __init_wut_newlib(); \ + }\ + WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_NEWLIB,on_init_wut_newlib); \ + __EXTERN_C_MACRO void __fini_wut_newlib(); \ + void on_fini_wut_newlib(){ \ + __fini_wut_newlib(); \ + }\ + WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_NEWLIB,on_fini_wut_newlib); + +#define WUMS_USE_WUT_STDCPP() \ + __EXTERN_C_MACRO void __init_wut_stdcpp(); \ + void on_init_wut_stdcpp(){ \ + __init_wut_stdcpp(); \ + }\ + WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_STDCPP,on_init_wut_stdcpp); \ + __EXTERN_C_MACRO void __fini_wut_stdcpp(); \ + void on_fini_wut_stdcpp(){ \ + __fini_wut_stdcpp(); \ + }\ + WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_STDCPP,on_fini_wut_stdcpp); + +#define WUMS_USE_WUT_SOCKETS() \ + __EXTERN_C_MACRO void __init_wut_socket(); \ + WUMS_HOOK_EX(WUMS_HOOK_INIT_WUT_SOCKETS,__init_wut_socket); \ + __EXTERN_C_MACRO void __fini_wut_socket(); \ + WUMS_HOOK_EX(WUMS_HOOK_FINI_WUT_SOCKETS,__fini_wut_socket); + #ifdef __cplusplus } -#endif +#endif \ No newline at end of file diff --git a/include/wums/meta.h b/include/wums/meta.h new file mode 100644 index 0000000..f303da3 --- /dev/null +++ b/include/wums/meta.h @@ -0,0 +1,45 @@ +/* based on blsug.h + * by Alex Chadwick + * + * Copyright (C) 2014, Alex Chadwick + * Modified by Maschell, 2018-2021 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "common.h" +#include "hooks.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define WUMS_MODULE_EXPORT_NAME(x) WUMS_META(export_name, x); WUMS_META(wum, "0.2"); WUMS_USE_WUT_MALLOC() WUMS_USE_WUT_SOCKETS() WUMS_USE_WUT_NEWLIB() WUMS_USE_WUT_STDCPP() WUMS_META(buildtimestamp, __DATE__ " " __TIME__); +#define WUMS_MODULE_AUTHOR(x) WUMS_META(author, x) +#define WUMS_MODULE_VERSION(x) WUMS_META(version, x) +#define WUMS_MODULE_LICENSE(x) WUMS_META(license, x) +#define WUMS_MODULE_DESCRIPTION(x) WUMS_META(description, x) +#define WUMS_MODULE_SKIP_ENTRYPOINT() WUMS_META(skipEntrypoint, "true") +#define WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK() WUMS_META(initBeforeRelocationDoneHook, "true") + +#ifdef __cplusplus +} +#endif diff --git a/libraries/libwums/crt.c b/libraries/libwums/crt.c index 2a90495..19d4f1e 100644 --- a/libraries/libwums/crt.c +++ b/libraries/libwums/crt.c @@ -1,3 +1,27 @@ -int main(int argc, char** argv){ +int main(int argc, char **argv) { return 0; +} + +extern __attribute__((weak)) void __wut_socket_init_devoptab(); +extern __attribute__((weak)) void __wut_socket_fini_devoptab(); + +static int __wut_socket_devoptab_added = 0; + +extern void socket_lib_init(); + +void __attribute__((weak)) __init_wut_socket() { + if(!&__wut_socket_init_devoptab) return; + if (!__wut_socket_devoptab_added) { + socket_lib_init(); + __wut_socket_init_devoptab(); + __wut_socket_devoptab_added = 1; + } +} + +void __attribute__((weak)) __fini_wut_socket() { + if(!&__wut_socket_init_devoptab || !&__wut_socket_fini_devoptab) return; + if (__wut_socket_devoptab_added) { + __wut_socket_fini_devoptab(); + __wut_socket_devoptab_added = 0; + } } \ No newline at end of file diff --git a/libraries/libwums/crt0.s b/libraries/libwums/crt0.s index 99d8023..d806792 100644 --- a/libraries/libwums/crt0.s +++ b/libraries/libwums/crt0.s @@ -1,24 +1,7 @@ .extern main -.extern exit -.extern __init_wut -.extern __fini_wut + +.section .crt0, "ax", @progbits .global __wums_start __wums_start: - stwu 1, -0x28(1) - mflr 0 - stw 0, 0x2C(1) - stw 31, 0x24(1) - or 31, 1, 1 - stw 3, 0x18(31) - stw 4, 0x1C(31) - bl __init_wut - lwz 4, 0x1C(31) - lwz 3, 0x18(31) - bl main - addi 11, 31, 0x28 - lwz 0, 0x4(11) - mtlr 0 - lwz 31, -0x4(11) - or 1, 11, 11 - blr \ No newline at end of file + b main \ No newline at end of file