PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
erl-loader.c
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
16extern struct export_list_t {
17 char * name;
18 void * pointer;
19} export_list[];
20
21static 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;
41 _init_erl_prefix[p - _init_erl_prefix] = 0;
42}
43
44static char * prohibit_list[] = {
45 "_edata", "_end", "_end_bss", "_fbss", "_fdata", "_fini",
46 "_ftext", "_gp", "_init", "main",
47 0
48};
49
50static void export_symbols() {
51 struct export_list_t * p;
52
53 for (p = export_list; p->name; p++) {
54 int i;
55 int prohibit;
56 prohibit = 0;
57 for (i = 0; prohibit_list[i]; i++) {
58 if (!(strcmp(prohibit_list[i], p->name))) {
59 prohibit = 1;
60 break;
61 }
62 }
63 if (!prohibit)
64 erl_add_global_symbol(p->name, (u32) p->pointer);
65 }
66}
67
68typedef void (*func_t)(void);
69
70int main(int argc, char *argv[]) {
71 struct symbol_t * s;
72
73 parse_boot_path(argc, argv);
74
75 export_symbols();
76
77 if (argc >= 2) {
78 int i;
79 for (i = 1; i < argc; i++) {
80 _init_load_erl_from_file(argv[i], 0);
81 }
82 } else {
83 _init_load_erl_from_file("main.erl", 0);
84 }
85
86 if ((s = erl_find_symbol("main"))) {
87 ((func_t) s->address)();
88 }
89
90 return 0;
91}
Definition erl.h:42