ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
slib.c File Reference
#include <tamtypes.h>
#include <kernel.h>
#include <string.h>
#include <sifrpc.h>
#include "slib.h"
#include "smod.h"
#include "common.h"
+ Include dependency graph for slib.c:

Go to the source code of this file.

Macros

#define EXP_LIB_MAX   SMEM_BUF_SIZE /* We can even handle CDVDMAN's bloat! */
 

Functions

slib_exp_lib_list_tslib_exp_lib_list (void)
 
int slib_get_exp_lib (const char *name, slib_exp_lib_t *library)
 

Variables

slib_exp_lib_list_t _slib_cur_exp_lib_list = {NULL, NULL}
 
struct smem_buf smem_buf
 

Detailed Description

Sub CPU library interface.

Definition in file slib.c.

Macro Definition Documentation

◆ EXP_LIB_MAX

#define EXP_LIB_MAX   SMEM_BUF_SIZE /* We can even handle CDVDMAN's bloat! */

Definition at line 99 of file slib.c.

Function Documentation

◆ slib_exp_lib_list()

slib_exp_lib_list_t* slib_exp_lib_list ( )

Find the head and tail of the export library list.

Returns
NULL if the list couldn't be found, and the address of the head and tail pointers if it was located.

This routine will need to be called everytime the IOP is reset.

Definition at line 31 of file slib.c.

32 {
33  SifRpcReceiveData_t RData;
34  slib_exp_lib_t *core_exps;
35  slib_exp_lib_list_t *exp_lib_list = NULL;
36  u32 i, addr, core_end, NextMod, *exp_func;
37  void *pGetLoadcoreInternalData;
38  smod_mod_info_t *ModInfo;
39 
40  /* Read the start of the global module table - this is where we will search. */
42  if(SifRpcGetOtherData(&RData, (void*)0x800, &smem_buf, sizeof(smod_mod_info_t), 0)>=0){
43  /* The first entry points to LOADCORE's module info. We then use the
44  module info to determine the end of LOADCORE's .text segment (just
45  past the export library we're trying to find. */
46  NextMod = *smem_buf.words;
48  if(SifRpcGetOtherData(&RData, (void*)NextMod, &smem_buf, sizeof(smod_mod_info_t), 0)>=0){
49  ModInfo = &smem_buf.mod_info;
50  core_end = ModInfo->text_start+ModInfo->text_size;
51 
52  /* Back up so we position ourselves infront of where the export
53  library will be. */
55  if(SifRpcGetOtherData(&RData, (void*)(core_end - 512), &smem_buf, 512, 0)>=0){
56  /* Search for LOADCORE's export library. */
57  for (i = 0; i < 512; i += 4) {
58  /* SYSMEM's export library sits at 0x830, so it should appear in
59  LOADCORE's prev pointer. */
60  if (smem_buf.words[i / sizeof(u32)] == 0x830) {
61  if (!__memcmp(smem_buf.bytes + i + 12, "loadcore", 8))
62  break;
63  }
64  }
65  if (i >= 512)
66  return NULL;
67 
68  /* Get to the start of the export table, and find the address of the
69  routine that will get us the export library list info. */
70  core_exps = (slib_exp_lib_t *)(smem_buf.bytes + i);
71  pGetLoadcoreInternalData = core_exps->exports[3];
72 
74  if(SifRpcGetOtherData(&RData, pGetLoadcoreInternalData, &smem_buf, 8, 0)>=0){
75  exp_func = smem_buf.words;
76 
77  /* Parse the two instructions that hold the address of the table. */
78  if ((exp_func[0] & 0xffff0000) != 0x3c020000) /* lui v0, XXXX */
79  return NULL;
80  if ((exp_func[1] & 0xffff0000) != 0x24420000) /* addiu v0, v0, XXXX */
81  return NULL;
82 
83  addr = ((exp_func[0] & 0xffff) << 16) | (exp_func[1] & 0xffff);
84 
86  if(SifRpcGetOtherData(&RData, (void*)addr, &smem_buf, 8, 0)>=0){
89  exp_lib_list = &_slib_cur_exp_lib_list;
90  }
91  }
92  }
93  }
94  }
95 
96  return exp_lib_list;
97 }
int __memcmp(const void *s1, const void *s2, unsigned int length)
Definition: common.c:27
void SyncDCache(void *start, void *end)
int SifRpcGetOtherData(SifRpcReceiveData_t *rd, void *src, void *dest, int size, int mode)
slib_exp_lib_list_t _slib_cur_exp_lib_list
Definition: slib.c:26
struct _slib_exp_lib * head
Definition: slib.h:47
struct _slib_exp_lib * tail
Definition: slib.h:46
void * exports[0]
Definition: slib.h:38
Definition: common.h:3
u8 bytes[SMEM_BUF_SIZE/sizeof(u8)]
Definition: common.h:5
u32 words[SMEM_BUF_SIZE/sizeof(u32)]
Definition: common.h:6
smod_mod_info_t mod_info
Definition: common.h:7
u32 text_start
Definition: smod.h:36
u32 text_size
Definition: smod.h:37
#define NULL
Definition: tamtypes.h:91
unsigned int u32
Definition: tamtypes.h:30

References __memcmp(), _slib_cur_exp_lib_list, smem_buf::bytes, slib_exp_lib_t::exports, slib_exp_lib_list_t::head, smem_buf::mod_info, NULL, SifRpcGetOtherData(), SyncDCache(), slib_exp_lib_list_t::tail, smod_mod_info_t::text_size, smod_mod_info_t::text_start, and smem_buf::words.

Referenced by slib_get_exp_lib().

◆ slib_get_exp_lib()

int slib_get_exp_lib ( const char *  name,
slib_exp_lib_t library 
)

Retrieve an export library by name.

Definition at line 101 of file slib.c.

102 {
103  SifRpcReceiveData_t RData;
105  slib_exp_lib_t *exp_lib = &smem_buf.exp_lib;
106  void *cur_lib;
107  int len = strlen(name), count = 0;
108 
109  if (!exp_lib_list->head && !(exp_lib_list = slib_exp_lib_list()))
110  return 0;
111 
112  /* Read the tail export library to initiate the search. */
113  cur_lib = exp_lib_list->tail;
114 
115  while (cur_lib) {
117  if(SifRpcGetOtherData(&RData, cur_lib, exp_lib, EXP_LIB_MAX, 0)>=0){
118  if (!__memcmp(exp_lib->name, name, len)) {
119  while (exp_lib->exports[count] != 0)
120  count++;
121 
122  if (library)
123  memcpy(library, exp_lib, sizeof(slib_exp_lib_t) + count * 4);
124 
125  return count;
126  }
127 
128  cur_lib = exp_lib->prev;
129  }
130  }
131 
132  return 0;
133 }
#define EXP_LIB_MAX
Definition: slib.c:99
slib_exp_lib_list_t * slib_exp_lib_list(void)
Definition: slib.c:31
u8 name[8]
Definition: slib.h:37
struct _slib_exp_lib * prev
Definition: slib.h:33
slib_exp_lib_t exp_lib
Definition: common.h:8

References __memcmp(), _slib_cur_exp_lib_list, smem_buf::bytes, smem_buf::exp_lib, EXP_LIB_MAX, slib_exp_lib_t::exports, slib_exp_lib_list_t::head, slib_exp_lib_t::name, slib_exp_lib_t::prev, SifRpcGetOtherData(), slib_exp_lib_list(), SyncDCache(), and slib_exp_lib_list_t::tail.

Referenced by sbv_patch_disable_prefix_check(), and sbv_patch_enable_lmb().

Variable Documentation

◆ _slib_cur_exp_lib_list

slib_exp_lib_list_t _slib_cur_exp_lib_list = {NULL, NULL}

◆ smem_buf

struct smem_buf smem_buf
extern

Definition at line 1 of file common.c.