sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
ioplib.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9#
10# taken from MX4SIO driver for simplicity.
11# all credits go to maximus32
12*/
13
14#include "ioplib.h"
15#include <intrman.h>
16
17int ioplib_iterateByName(const char *name, ioplib_libiterate_cb_t cb, void *userdata)
18{
19 iop_library_t *libptr;
20 int i;
21 int count;
22
23 count = 0;
24 // Get first loaded library
25 libptr = GetLoadcoreInternalData()->let_next;
26 // Loop through all loaded libraries
27 while (libptr != NULL) {
28 // Compare library name only
29 for (i = 0; i < 8; i++) {
30 if (libptr->name[i] != name[i])
31 break;
32 }
33
34 // Call callback if match
35 if (i == 8) {
36 count += 1;
37 // Return early if requested
38 if (cb(libptr, userdata))
39 break;
40 }
41
42 // Next library
43 libptr = libptr->prev;
44 }
45
46 return count;
47}
48
49unsigned int ioplib_getTableSize(iop_library_t *lib)
50{
51 void **exp;
52 unsigned int size;
53
54 exp = NULL;
55 if (lib != NULL) {
56 exp = lib->exports;
57 }
58 size = 0;
59
60 if (exp != NULL)
61 while (*exp++ != NULL)
62 size++;
63
64 return size;
65}
66
67void *ioplib_hookSameExportEntries(iop_library_t *lib, unsigned int entry, void *func)
68{
69 int table_size;
70 int oldstate;
71 void *oldfunc;
72 unsigned int i;
73
74 table_size = ioplib_getTableSize(lib);
75 if (entry >= table_size)
76 return NULL;
77
78 CpuSuspendIntr(&oldstate);
79 oldfunc = lib->exports[entry];
80 for (i = 0; i < table_size; i += 1)
81 if (lib->exports[i] == oldfunc)
82 lib->exports[i] = func;
83 CpuResumeIntr(oldstate);
84
85 return oldfunc;
86}
87
88void ioplib_relinkExports(iop_library_t *lib)
89{
90 struct irx_import_table *table;
91 struct irx_import_stub *stub;
92
93 // go through each table that imports the library
94 for (table = lib->caller; table != NULL; table = table->next) {
95 // go through each import in the table
96 for (stub = (struct irx_import_stub *)table->stubs; stub->jump != 0; stub++) {
97 // patch the stub to jump to the address specified in the library export table for "fno"
98 stub->jump = 0x08000000 | (((u32)lib->exports[stub->fno] << 4) >> 6);
99 }
100 }
101}
int CpuResumeIntr(int state)
Definition intrman.c:217
int CpuSuspendIntr(int *state)
Definition intrman.c:195
Definition main.c:40
u32 count
start sector of fragmented bd/file