ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
erl-loader.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, 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 # Small erl loader to provide a startup core.
11 */
12 
13 #include <string.h>
14 #include <erl.h>
15 
16 extern struct export_list_t {
17  char * name;
18  void * pointer;
20 
21 static void parse_boot_path(int argc, char ** argv) {
22  char * p;
23 
24  if (argc == 0) // Are people still using naplink ? :P
25  strcpy(_init_erl_prefix, "host:");
26 
27  strcpy(_init_erl_prefix, argv[0]);
28 
29  p = strrchr(_init_erl_prefix, '/');
30 
31  if (!p)
32  p = strrchr(_init_erl_prefix, '\\');
33 
34  if (!p)
35  p = strrchr(_init_erl_prefix, ':');
36 
37  if (!p)
38  return;
39 
40  *(++p) = 0;
42 }
43 
44 static char * prohibit_list[] = {
45  "_edata", "_end", "_end_bss", "_fbss", "_fdata", "_fini",
46  "_ftext", "_gp", "_init", "main",
47  0
48 };
49 
50 static void export_symbols() {
51  struct export_list_t * p;
52  int i, prohibit;
53 
54  for (p = export_list; p->name; p++) {
55  prohibit = 0;
56  for (i = 0; prohibit_list[i]; i++) {
57  if (!(strcmp(prohibit_list[i], p->name))) {
58  prohibit = 1;
59  break;
60  }
61  }
62  if (!prohibit)
64  }
65 }
66 
67 typedef void (*func_t)(void);
68 
69 int main(int argc, char ** argv) {
70  struct symbol_t * s;
71  int i;
72 
73  parse_boot_path(argc, argv);
74 
76 
77  if (argc >= 2) {
78  for (i = 1; i < argc; i++) {
79  _init_load_erl_from_file(argv[i], 0);
80  }
81  } else {
82  _init_load_erl_from_file("main.erl", 0);
83  }
84 
85  if ((s = erl_find_symbol("main"))) {
86  ((func_t) s->address)();
87  }
88 
89  return 0;
90 }
int main(int argc, char **argv)
Definition: erl-loader.c:69
static char * prohibit_list[]
Definition: erl-loader.c:44
void(* func_t)(void)
Definition: erl-loader.c:67
static void parse_boot_path(int argc, char **argv)
Definition: erl-loader.c:21
struct export_list_t export_list[]
static void export_symbols()
Definition: erl-loader.c:50
char _init_erl_prefix[]
Definition: erl.c:281
int erl_add_global_symbol(const char *symbol, u32 address)
Definition: erl.c:574
struct symbol_t * erl_find_symbol(const char *symbol)
Definition: erl.c:443
struct erl_record_t * _init_load_erl_from_file(const char *fname, char *erl_id)
Definition: erl.c:1012
s32 s
Definition: ps2ipc.c:30
void * pointer
Definition: dummy-exports.c:3
Definition: erl.h:42
unsigned int u32
Definition: tamtypes.h:30