diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index 3b9b800..c61faf7 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -27,7 +27,7 @@ jobs: - name: Build libogc2 run: | - sed -i 's/-O2/-Os -flto/' Makefile + patch -Np1 -i ../ogc.patch make install working-directory: libogc2 diff --git a/ogc.patch b/ogc.patch new file mode 100644 index 0000000..03401a6 --- /dev/null +++ b/ogc.patch @@ -0,0 +1,113 @@ +From d727901a9f7100c31557512eb66aeda7932cba6e Mon Sep 17 00:00:00 2001 +From: novenary +Date: Mon, 23 Oct 2023 15:37:08 +0300 +Subject: [PATCH 1/3] Remove lwp + +--- + Makefile | 5 ++--- + libogc/system.c | 1 + + libogc/video.c | 4 ++-- + 3 files changed, 5 insertions(+), 5 deletions(-) + +diff --git a/Makefile b/Makefile +index 56ade00..2d8ee38 100644 +--- a/Makefile ++++ b/Makefile +@@ -132,9 +132,8 @@ LWIPOBJ := network.o netio.o gcif.o \ + + #--------------------------------------------------------------------------------- + OGCOBJ := \ +- console.o lwp_priority.o lwp_queue.o lwp_threadq.o lwp_threads.o lwp_sema.o \ +- lwp_messages.o lwp.o lwp_handler.o lwp_stack.o lwp_mutex.o \ +- lwp_watchdog.o lwp_wkspace.o lwp_objmgr.o lwp_heap.o sys_state.o \ ++ console.o \ ++ sys_state.o \ + exception_handler.o exception.o irq.o irq_handler.o semaphore.o \ + video_asm.o video.o pad.o dvd.o exi.o mutex.o arqueue.o arqmgr.o \ + cache_asm.o system.o system_asm.o cond.o \ +diff --git a/libogc/system.c b/libogc/system.c +index bf07905..2f2bbd5 100644 +--- a/libogc/system.c ++++ b/libogc/system.c +@@ -1116,6 +1116,7 @@ void SYS_Init(void) + __libc_init(1); + __lwp_thread_startmultitasking(); + _CPU_ISR_Restore(level); ++ main(); + } + + // This function gets called inside the main thread, prior to the application's main() function +diff --git a/libogc/video.c b/libogc/video.c +index 62782a5..b22510e 100644 +--- a/libogc/video.c ++++ b/libogc/video.c +@@ -2741,12 +2741,12 @@ void VIDEO_WaitVSync(void) + u32 level; + u32 retcnt; + +- _CPU_ISR_Disable(level); ++ //_CPU_ISR_Disable(level); + retcnt = retraceCount; + do { + LWP_ThreadSleep(video_queue); + } while(retraceCount==retcnt); +- _CPU_ISR_Restore(level); ++ //_CPU_ISR_Restore(level); + } + + void VIDEO_SetFramebuffer(void *fb) +-- +2.42.0 + + +From a19f2a1892f152c1377b5268549c4a20fb2309db Mon Sep 17 00:00:00 2001 +From: novenary +Date: Mon, 23 Oct 2023 15:37:36 +0300 +Subject: [PATCH 2/3] Optimize for size + +--- + Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile b/Makefile +index 2d8ee38..f52abcd 100644 +--- a/Makefile ++++ b/Makefile +@@ -97,7 +97,7 @@ endif + INCLUDES += -I$(PORTLIBS_PATH)/ppc/include + + +-CFLAGS := -DLIBOGC_INTERNAL -g -O2 -fno-strict-aliasing -Wall -Wno-address-of-packed-member $(MACHDEP) $(INCLUDES) ++CFLAGS := -DLIBOGC_INTERNAL -g -Os -fno-strict-aliasing -Wall -Wno-address-of-packed-member $(MACHDEP) $(INCLUDES) + ASFLAGS := $(MACHDEP) -mregnames -D_LANGUAGE_ASSEMBLY $(INCLUDES) + + #--------------------------------------------------------------------------------- +-- +2.42.0 + + +From 7343d5bbb00c10c3718ed172f86424cdbc1b1b7b Mon Sep 17 00:00:00 2001 +From: novenary +Date: Mon, 23 Oct 2023 15:37:54 +0300 +Subject: [PATCH 3/3] Don't call GX_AbortFrame() from exception handler + +Saves a kilobyte or so +--- + libogc/exception.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/libogc/exception.c b/libogc/exception.c +index 820b200..1800b98 100644 +--- a/libogc/exception.c ++++ b/libogc/exception.c +@@ -237,7 +237,6 @@ static void waitForReload(void) + //just implement core for unrecoverable exceptions. + void c_default_exceptionhandler(frame_context *pCtx) + { +- GX_AbortFrame(); + VIDEO_SetFramebuffer(exception_xfb); + __console_init(exception_xfb,20,20,640,574,1280); + CON_EnableGecko(1, true); +-- +2.42.0 + diff --git a/source/lwp_stub.c b/source/lwp_stub.c new file mode 100644 index 0000000..6767c09 --- /dev/null +++ b/source/lwp_stub.c @@ -0,0 +1,81 @@ +#include + +vu32 _thread_dispatch_disable_level; +vu32 _context_switch_want; +void **__lwp_thr_libc_reent = NULL; +void *_thr_executing = NULL; + +typedef struct _lwpnode { + struct _lwpnode *next; + struct _lwpnode *prev; +} lwp_node; + +typedef struct _lwpqueue { + lwp_node *first; + lwp_node *perm_null; + lwp_node *last; +} lwp_queue; +lwp_queue _wd_ticks_queue; + +void __lwp_threadqueue_enqueuepriority() {} +void __lwp_threadqueue_dequeuepriority() {} +void __lwp_heap_free() {} +void __lwp_objmgr_initinfo() {} +void __lwp_wd_insert() {} +void __lwp_threadqueue_extractpriority() {} +void __lwp_thread_close() {} +void __lwp_mutex_surrender() {} +void __lwp_threadqueue_enqueue() {} +void __lwp_heap_allocate() {} +void __lwp_thread_changepriority() {} +void __lwp_threadqueue_dequeuefifo() {} +void __lwp_thread_init() {} +void __lwp_threadqueue_enqueuefifo() {} +void __lwp_wd_tickle() {} +void __lwp_thread_setstate() {} +void __lwp_thread_clearstate() {} +void __lwp_mutex_seize_irq_blocking() {} +void __lwp_threadqueue_extractfifo() {} +void __lwp_wd_remove() {} +void __lwp_thread_ready() {} +void __lwp_heap_init() {} +void __lwp_wkspace_init() {} +void __lwp_thread_settransient() {} +void __lwp_mutex_initialize() {} +void __lwp_thread_loadenv() {} +void __lwp_objmgr_get() {} +void __lwp_threadqueue_init() {} +void __lwp_objmgr_allocate() {} +void __lwp_thread_setpriority() {} +void __lwp_thread_stopmultitasking() {} +void __lwp_objmgr_getisrdisable() {} +void __lwp_objmgr_free() {} +void __lwp_stack_allocate() {} +void __lwp_queue_get() {} +void __lwp_thread_start() {} +void __lwp_queue_append() {} +void __lwp_thread_delayended() {} +void __lwp_queue_initialize() {} +void __lwp_threadqueue_flush() {} +void __lwp_threadqueue_extractproxy() {} +void __lwp_thread_exit() {} +void __lwp_watchdog_init() {} +void __lwp_threadqueue_dequeue() {} +void __lwp_objmgr_getnoprotection() {} +void __lwp_threadqueue_extract() {} +void __lwp_stack_free() {} +void __lwp_priority_init() {} +void __lwp_isr_in_progress() {} +void __lwp_mutex_flush() {} + +void __thread_dispatch() {} +void __thread_dispatch_fp() {} +void __lwp_sysinit() {} +void __lwp_thread_setlibcreent() {} +void __lwp_thread_closeall() {} +void __lwp_thread_coreinit() {} +void __lwp_thread_startmultitasking() {} + +void LWP_ThreadBroadcast() {} +void LWP_InitQueue() {} +void LWP_ThreadSleep() {}