ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
erl.h File Reference
#include <tamtypes.h>
+ Include dependency graph for erl.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  erl_loader_t
 
struct  symbol_t
 

Macros

#define ERL_FLAG_STICKY   1
 
#define ERL_FLAG_STATIC   2
 
#define ERL_FLAG_CLEAR   4
 
#define ERL_DYN_ADDR   0
 

Functions

struct erl_record_tload_erl_from_mem (u8 *mem, int argc, char **argv)
 
struct erl_record_tload_erl_from_file (const char *fname, int argc, char **argv)
 
struct erl_record_t_init_load_erl_from_file (const char *fname, char *erl_id)
 
struct erl_record_tload_erl_from_mem_to_addr (u8 *mem, u32 addr, int argc, char **argv)
 
struct erl_record_tload_erl_from_file_to_addr (const char *fname, u32 addr, int argc, char **argv)
 
struct erl_record_t_init_load_erl_from_file_to_addr (const char *fname, u32 addr, char *erl_id)
 
int unload_erl (struct erl_record_t *erl)
 
int erl_add_global_symbol (const char *symbol, u32 address)
 
struct erl_record_tfind_erl (const char *name)
 
struct erl_record_terl_resolve (u32 address)
 
struct symbol_terl_find_local_symbol (const char *symbol, struct erl_record_t *erl)
 
struct symbol_terl_find_symbol (const char *symbol)
 
void erl_flush_symbols (struct erl_record_t *erl)
 

Variables

char _init_erl_prefix []
 
erl_loader_t _init_load_erl
 

Detailed Description

The relocatable elf loader/linker.

Definition in file erl.h.

Macro Definition Documentation

◆ ERL_DYN_ADDR

#define ERL_DYN_ADDR   0

Definition at line 66 of file erl.h.

◆ ERL_FLAG_CLEAR

#define ERL_FLAG_CLEAR   4

Clear ERL bytes on unload

Definition at line 28 of file erl.h.

◆ ERL_FLAG_STATIC

#define ERL_FLAG_STATIC   2

ERL is relocated at a static memory address; set by *_to_addr functions

Definition at line 26 of file erl.h.

◆ ERL_FLAG_STICKY

#define ERL_FLAG_STICKY   1

ERL is sticky and cannot be unloaded

Definition at line 24 of file erl.h.

Function Documentation

◆ _init_load_erl_from_file()

struct erl_record_t* _init_load_erl_from_file ( const char *  fname,
char *  erl_id 
)

Definition at line 1012 of file erl.c.

1012  {
1013  char tfname[1024];
1014  struct erl_record_t * r;
1015  char * argv[2];
1016 
1017  if (erl_id)
1018  if ((r = find_erl(erl_id)))
1019  return r;
1020 
1021  argv[0] = erl_id;
1022  argv[1] = 0;
1023 
1024  strcpy(tfname, _init_erl_prefix);
1025  strcat(tfname, fname);
1026 
1027  return load_erl_from_file(tfname, 1, argv);
1028 }
char * erl_id
Definition: erl-support.c:15
struct erl_record_t * load_erl_from_file(const char *fname, int argc, char **argv)
Definition: erl.c:1030
struct erl_record_t * find_erl(const char *name)
Definition: erl.c:1133
char _init_erl_prefix[256]
Definition: erl.c:281

References _init_erl_prefix, erl_id, find_erl(), and load_erl_from_file().

Referenced by _init_load_erl_wrapper_from_file(), and main().

◆ _init_load_erl_from_file_to_addr()

struct erl_record_t* _init_load_erl_from_file_to_addr ( const char *  fname,
u32  addr,
char *  erl_id 
)

Definition at line 1055 of file erl.c.

1055  {
1056  char tfname[1024];
1057  struct erl_record_t * r;
1058  char * argv[2];
1059 
1060  if (erl_id)
1061  if ((r = find_erl(erl_id)))
1062  return r;
1063 
1064  argv[0] = erl_id;
1065  argv[1] = 0;
1066 
1067  strcpy(tfname, _init_erl_prefix);
1068  strcat(tfname, fname);
1069 
1070  return load_erl_from_file_to_addr(tfname, addr, 1, argv);
1071 }
struct erl_record_t * load_erl_from_file_to_addr(const char *fname, u32 addr, int argc, char **argv)
Definition: erl.c:1048

References _init_erl_prefix, erl_id, find_erl(), and load_erl_from_file_to_addr().

◆ erl_add_global_symbol()

int erl_add_global_symbol ( const char *  symbol,
u32  address 
)

Definition at line 574 of file erl.c.

574  {
575  return add_symbol(0, symbol, address);
576 }
static int add_symbol(struct erl_record_t *erl, const char *symbol, u32 address)
Definition: erl.c:546

References add_symbol().

Referenced by export_symbols().

◆ erl_find_local_symbol()

struct symbol_t* erl_find_local_symbol ( const char *  symbol,
struct erl_record_t erl 
)

Definition at line 427 of file erl.c.

427  {
428  if (!erl)
429  return 0;
430  if (hfind(erl->symbols, symbol, strlen(symbol)))
431  return hstuff(erl->symbols);
432  return 0;
433 }
word hfind()
#define hstuff(t)
Definition: hashtab.h:111
struct htab * symbols
Definition: erl.h:38

References hfind(), hstuff, and erl_loader_t::symbols.

Referenced by load_erl(), and unload_erl().

◆ erl_find_symbol()

struct symbol_t* erl_find_symbol ( const char *  symbol)

Definition at line 443 of file erl.c.

443  {
444  if (global_symbols)
445  if (hfind(global_symbols, symbol, strlen(symbol)))
446  return hstuff(global_symbols);
447  return r_find_symbol(symbol, erl_record_root);
448 }
static htab * global_symbols
Definition: erl.c:278
static struct symbol_t * r_find_symbol(const char *symbol, struct erl_record_t *erl)
Definition: erl.c:435
static struct erl_record_t * erl_record_root
Definition: erl.c:276

References erl_record_root, global_symbols, hfind(), hstuff, and r_find_symbol().

Referenced by add_symbol(), main(), and read_erl().

◆ erl_flush_symbols()

void erl_flush_symbols ( struct erl_record_t erl)

Definition at line 1145 of file erl.c.

1145  {
1146  if (!erl->symbols)
1147  return;
1148 
1149  if (hfirst(erl->symbols)) do {
1150  destroy_symbol((struct symbol_t *) hstuff(erl->symbols));
1151  free(hkey(erl->symbols));
1152  hdel(erl->symbols);
1153  } while (hcount(erl->symbols));
1154 
1155  hdestroy(erl->symbols);
1156 
1157  erl->symbols = 0;
1158 }
static void destroy_symbol(struct symbol_t *s)
Definition: erl.c:345
word hfirst()
#define hkey(t)
Definition: hashtab.h:109
#define hcount(t)
Definition: hashtab.h:108
word hdel()
void hdestroy()
Definition: erl.h:42

References destroy_symbol(), hcount, hdel(), hdestroy(), hfirst(), hkey, hstuff, and erl_loader_t::symbols.

Referenced by destroy_erl_record(), and unload_erl().

◆ erl_resolve()

struct erl_record_t* erl_resolve ( u32  address)

Definition at line 1121 of file erl.c.

1121  {
1122  struct erl_record_t * r;
1123 
1124  for (r = erl_record_root; r; r = r->next) {
1125  u32 r_ptr = (u32) r->bytes;
1126  if ((address >= r_ptr) && (address < (r_ptr + r->fullsize)))
1127  return r;
1128  }
1129 
1130  return 0;
1131 }
u32 fullsize
Definition: erl.h:32
struct erl_record_t * next
Definition: erl.h:39
u8 * bytes
Definition: erl.h:31
unsigned int u32
Definition: tamtypes.h:30

References erl_loader_t::bytes, erl_record_root, erl_loader_t::fullsize, and erl_loader_t::next.

◆ find_erl()

struct erl_record_t* find_erl ( const char *  name)

Definition at line 1133 of file erl.c.

1133  {
1134  struct erl_record_t * r;
1135 
1136  for (r = erl_record_root; r; r = r->next) {
1137  if (r->name)
1138  if (!strcmp(name, r->name))
1139  return r;
1140  }
1141 
1142  return 0;
1143 }
char * name
Definition: erl.h:33

References erl_record_root, erl_loader_t::name, and erl_loader_t::next.

Referenced by _init_load_erl_from_file(), _init_load_erl_from_file_to_addr(), and r_unload_dependancies().

◆ load_erl_from_file()

struct erl_record_t* load_erl_from_file ( const char *  fname,
int  argc,
char **  argv 
)

Definition at line 1030 of file erl.c.

1030  {
1031  return load_erl(fname, 0, ERL_DYN_ADDR, argc, argv);
1032 }
static struct erl_record_t * load_erl(const char *fname, u8 *elf_mem, u32 addr, int argc, char **argv)
Definition: erl.c:940
#define ERL_DYN_ADDR
Definition: erl.h:66

References ERL_DYN_ADDR, and load_erl().

Referenced by _init_load_erl_from_file().

◆ load_erl_from_file_to_addr()

struct erl_record_t* load_erl_from_file_to_addr ( const char *  fname,
u32  addr,
int  argc,
char **  argv 
)

Definition at line 1048 of file erl.c.

1048  {
1049  return load_erl(fname, 0, addr, argc, argv);
1050 }

References load_erl().

Referenced by _init_load_erl_from_file_to_addr().

◆ load_erl_from_mem()

struct erl_record_t* load_erl_from_mem ( u8 mem,
int  argc,
char **  argv 
)

Definition at line 1034 of file erl.c.

1034  {
1035  return load_erl(0, mem, ERL_DYN_ADDR, argc, argv);
1036 }

References ERL_DYN_ADDR, and load_erl().

◆ load_erl_from_mem_to_addr()

struct erl_record_t* load_erl_from_mem_to_addr ( u8 mem,
u32  addr,
int  argc,
char **  argv 
)

Definition at line 1041 of file erl.c.

1041  {
1042  return load_erl(0, mem, addr, argc, argv);
1043 }

References load_erl().

◆ unload_erl()

int unload_erl ( struct erl_record_t erl)

Definition at line 1084 of file erl.c.

1084  {
1085  struct symbol_t * s;
1086  struct dependancy_t * p;
1087 
1088  dprintf("Unloading module %s.\n", erl->name ? erl->name : "(noname)");
1089 
1090  if ((erl->flags) & ERL_FLAG_STICKY) {
1091  dprintf("Module is sticky, won't unload.\n");
1092  return 0;
1093  }
1094 
1095  for (p = dependancy_root; p; p = p->next) {
1096  if (p->provider == erl) {
1097  dprintf("Other modules depend on it, won't unload.\n");
1098  return 0;
1099  }
1100  }
1101 
1102  if ((s = erl_find_local_symbol("_fini", erl))) {
1103  dprintf("_fini = %08X\n", s->address);
1104 #ifdef _EE
1105  ((func_t)s->address)();
1106 #endif
1107  }
1108 
1109  if (erl->dependancies)
1111 
1112  erl_flush_symbols(erl);
1113 
1114  destroy_dependancy_r(erl);
1115 
1116  destroy_erl_record(erl);
1117 
1118  return 1;
1119 }
struct symbol_t * erl_find_local_symbol(const char *symbol, struct erl_record_t *erl)
Definition: erl.c:427
static void destroy_erl_record(struct erl_record_t *erl)
Definition: erl.c:368
void erl_flush_symbols(struct erl_record_t *erl)
Definition: erl.c:1145
static void destroy_dependancy_r(struct erl_record_t *erl)
Definition: erl.c:495
#define dprintf(a...)
Definition: erl.c:33
static struct dependancy_t * dependancy_root
Definition: erl.c:283
void r_unload_dependancies(char **d)
Definition: erl.c:1073
int(* func_t)(void)
Definition: erl.c:928
#define ERL_FLAG_STICKY
Definition: erl.h:24
s32 s
Definition: ps2ipc.c:30
struct erl_record_t * provider
Definition: erl.c:270
struct dependancy_t * next
Definition: erl.c:271
u32 flags
Definition: erl.h:35
char ** dependancies
Definition: erl.h:34

References erl_loader_t::dependancies, dependancy_root, destroy_dependancy_r(), destroy_erl_record(), dprintf, erl_find_local_symbol(), ERL_FLAG_STICKY, erl_flush_symbols(), erl_loader_t::flags, erl_loader_t::name, dependancy_t::next, dependancy_t::provider, r_unload_dependancies(), and s.

Referenced by load_erl(), and r_unload_dependancies().

Variable Documentation

◆ _init_erl_prefix

char _init_erl_prefix[]
extern

◆ _init_load_erl

erl_loader_t _init_load_erl
extern

Definition at line 938 of file erl.c.

Referenced by load_erl().