PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
slib.c
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright (c) 2003 Marcus R. Brown <mrbrown@0xd6.org>
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
16#include <tamtypes.h>
17#include <kernel.h>
18#include <string.h>
19#include <sifrpc.h>
20
21#include "slib.h"
22#include "smod.h"
23
24#include "common.h"
25
26slib_exp_lib_list_t _slib_cur_exp_lib_list = {NULL, NULL};
27
28/* from common.c */
29extern struct smem_buf smem_buf;
30
32{
34 slib_exp_lib_t *core_exps;
35 slib_exp_lib_list_t *exp_lib_list = NULL;
36 u32 i, addr, core_end, NextMod;
38
39 /* Read the start of the global module table - this is where we will search. */
40 SyncDCache(&smem_buf, smem_buf.bytes+sizeof(smod_mod_info_t));
41 if(SifRpcGetOtherData(&RData, (void*)0x800, &smem_buf, sizeof(smod_mod_info_t), 0)>=0){
42 /* The first entry points to LOADCORE's module info. We then use the
43 module info to determine the end of LOADCORE's .text segment (just
44 past the export library we're trying to find. */
45 NextMod = *smem_buf.words;
46 SyncDCache(&smem_buf, smem_buf.bytes+sizeof(smod_mod_info_t));
47 if(SifRpcGetOtherData(&RData, (void*)NextMod, &smem_buf, sizeof(smod_mod_info_t), 0)>=0){
48 ModInfo = &smem_buf.mod_info;
49 core_end = ModInfo->text_start+ModInfo->text_size;
50
51 /* Back up so we position ourselves infront of where the export
52 library will be. */
53 SyncDCache(&smem_buf, smem_buf.bytes+512);
54 if(SifRpcGetOtherData(&RData, (void*)(core_end - 512), &smem_buf, 512, 0)>=0){
55 void *pGetLoadcoreInternalData;
56
57 /* Search for LOADCORE's export library. */
58 for (i = 0; i < 512; i += 4) {
59 /* SYSMEM's export library sits at 0x830, so it should appear in
60 LOADCORE's prev pointer. */
61 if (smem_buf.words[i / sizeof(u32)] == 0x830) {
62 if (!__memcmp(smem_buf.bytes + i + 12, "loadcore", 8))
63 break;
64 }
65 }
66 if (i >= 512)
67 return NULL;
68
69 /* Get to the start of the export table, and find the address of the
70 routine that will get us the export library list info. */
71 core_exps = (slib_exp_lib_t *)(smem_buf.bytes + i);
72 pGetLoadcoreInternalData = core_exps->exports[3];
73
74 SyncDCache(&smem_buf, smem_buf.bytes+8);
75 if(SifRpcGetOtherData(&RData, pGetLoadcoreInternalData, &smem_buf, 8, 0)>=0){
76 u32 *exp_func;
77 exp_func = smem_buf.words;
78
79 /* Parse the two instructions that hold the address of the table. */
80 if ((exp_func[0] & 0xffff0000) != 0x3c020000) /* lui v0, XXXX */
81 return NULL;
82 if ((exp_func[1] & 0xffff0000) != 0x24420000) /* addiu v0, v0, XXXX */
83 return NULL;
84
85 addr = (u32) ((exp_func[0] & 0xFFFF) << 16) + (s16) (exp_func[1] & 0xFFFF);
86
87 SyncDCache(&smem_buf, smem_buf.bytes+8);
88 if(SifRpcGetOtherData(&RData, (void*)addr, &smem_buf, 8, 0)>=0){
89 _slib_cur_exp_lib_list.tail = (slib_exp_lib_t *)(smem_buf.words[0]);
90 _slib_cur_exp_lib_list.head = (slib_exp_lib_t *)(smem_buf.words[1]);
91 exp_lib_list = &_slib_cur_exp_lib_list;
92 }
93 }
94 }
95 }
96 }
97
98 return exp_lib_list;
99}
100
101#define EXP_LIB_MAX SMEM_BUF_SIZE /* We can even handle CDVDMAN's bloat! */
102
103int slib_get_exp_lib(const char *name, slib_exp_lib_t *library)
104{
106 slib_exp_lib_list_t *exp_lib_list = &_slib_cur_exp_lib_list;
107 slib_exp_lib_t *exp_lib = &smem_buf.exp_lib;
108 void *cur_lib;
109 int len = strlen(name), count = 0;
110
111 if (!exp_lib_list->head && !(exp_lib_list = slib_exp_lib_list()))
112 return 0;
113
114 /* Read the tail export library to initiate the search. */
115 cur_lib = exp_lib_list->tail;
116
117 while (cur_lib) {
118 SyncDCache(&smem_buf, smem_buf.bytes+EXP_LIB_MAX);
119 if(SifRpcGetOtherData(&RData, cur_lib, exp_lib, EXP_LIB_MAX, 0)>=0){
120 if (!__memcmp(exp_lib->name, name, len)) {
121 while (exp_lib->exports[count] != 0)
122 count++;
123
124 if (library)
125 memcpy(library, exp_lib, sizeof(slib_exp_lib_t) + count * 4);
126
127 return count;
128 }
129
130 cur_lib = exp_lib->prev;
131 }
132 }
133
134 return 0;
135}
slib_exp_lib_list_t * slib_exp_lib_list(void)
Definition slib.c:31
int slib_get_exp_lib(const char *name, slib_exp_lib_t *library)
Definition slib.c:103
u32 count
start sector of fragmented bd/file