diff ticoff/tables.c @ 73:10f3fbff5e97

tiobjd: symbol table parsing implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 25 Mar 2014 18:34:03 +0000
parents c15cd3d695c0
children 2eef88395908
line wrap: on
line diff
--- a/ticoff/tables.c	Tue Mar 25 08:51:32 2014 +0000
+++ b/ticoff/tables.c	Tue Mar 25 18:34:03 2014 +0000
@@ -93,3 +93,53 @@
 	}
 	exit(0);
 }
+
+get_int_symbol_table()
+{
+	unsigned n;
+	struct internal_syment *in;
+
+	symtab = malloc(sizeof(struct internal_syment *) * nsymtab);
+	if (!symtab) {
+		perror("malloc");
+		exit(1);
+	}
+	for (n = 0; n < nsymtab; ) {
+		in = malloc(sizeof(struct internal_syment));
+		if (!in) {
+			perror("malloc");
+			exit(1);
+		}
+		symtab[n] = in;
+		in->name = get_secorsym_name(symtab_raw[n].e_name);
+		in->value = get_u32(symtab_raw[n].e_value);
+		in->scnum = get_s16(symtab_raw[n].e_scnum);
+		if (in->scnum < -2 || in->scnum > nsections) {
+			fprintf(stderr,
+				"symtab entry #%u: scnum out of range\n", n);
+			exit(1);
+		}
+		in->type = get_u16(symtab_raw[n].e_type);
+		in->class = symtab_raw[n].e_sclass;
+		switch (symtab_raw[n++].e_numaux) {
+		case 0:
+			in->aux = 0;
+			continue;
+		case 1:
+			if (n >= nsymtab) {
+				fprintf(stderr,
+				"error: last symbol's aux spills over\n");
+				exit(1);
+			}
+			symtab[n] = 0;
+			in->aux = (u_char *)(symtab_raw + n);
+			n++;
+			continue;
+		default:
+			n--;
+			fprintf(stderr, "symtab entry #%u: invalid numaux\n",
+				n);
+			exit(1);
+		}
+	}
+}