phash.ph: yet another attempt at getting Perl to behave, arithmetically
[nasm/avx512.git] / rdoff / rdx.c
blob82210a655f48be089a3fcb9a748d1c8b3c56b0e0
1 /* rdx.c RDOFF Object File loader program
3 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4 * Julian Hall. All rights reserved. The software is
5 * redistributable under the licence given in the file "Licence"
6 * distributed in the NASM archive.
7 */
9 /* note: most of the actual work of this program is done by the modules
10 "rdfload.c", which loads and relocates the object file, and by "rdoff.c",
11 which contains general purpose routines to manipulate RDOFF object
12 files. You can use these files in your own program to load RDOFF objects
13 and execute the code in them in a similar way to what is shown here. */
15 #include <stdio.h>
16 #include <stdlib.h>
18 #include "rdfload.h"
19 #include "symtab.h"
21 typedef int (*main_fn) (int, char **); /* Main function prototype */
23 int main(int argc, char **argv)
25 rdfmodule *m;
26 main_fn code;
27 symtabEnt *s;
29 if (argc < 2) {
30 puts("usage: rdx <rdoff-executable> [params]\n");
31 exit(255);
34 m = rdfload(argv[1]);
36 if (!m) {
37 rdfperror("rdx", argv[1]);
38 exit(255);
41 rdf_relocate(m); /* in this instance, the default relocation
42 values will work fine, but they may need changing
43 in other cases... */
45 s = symtabFind(m->symtab, "_main");
46 if (!s) {
47 fprintf(stderr, "rdx: could not find symbol '_main' in '%s'\n",
48 argv[1]);
49 exit(255);
52 code = (main_fn) s->offset;
54 argv++, argc--; /* remove 'rdx' from command line */
56 return code(argc, argv); /* execute */