FreeCalypso > hg > freecalypso-reveng
changeset 126:2c6b1319383b
tiobjd: first preparations for adding disasm hints mechanism
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sat, 05 Apr 2014 19:14:43 +0000 |
parents | b8ac21536779 |
children | a314d6aa9bf1 |
files | ticoff/Makefile ticoff/hints.c ticoff/intstruct.h ticoff/main.c ticoff/tables.c |
diffstat | 5 files changed, 163 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ticoff/Makefile Fri Apr 04 18:56:23 2014 +0000 +++ b/ticoff/Makefile Sat Apr 05 19:14:43 2014 +0000 @@ -1,8 +1,8 @@ CC= gcc CFLAGS= -O2 PROG= tiobjd -OBJS= armdis.o atcommon.o basics.o disasm.o globals.o lowlevel.o main.o \ - profile.o reloc.o symtab.o tables.o thumbdis.o +OBJS= armdis.o atcommon.o basics.o disasm.o globals.o hints.o lowlevel.o \ + main.o profile.o reloc.o symtab.o tables.o thumbdis.o HDRS= coffconst.h filestruct.h globals.h intstruct.h all: ${PROG}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ticoff/hints.c Sat Apr 05 19:14:43 2014 +0000 @@ -0,0 +1,137 @@ +/* + * Parsing of the disassembly hints file + */ + +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include "intstruct.h" +#include "globals.h" + +static char *filename_for_err; +static int lineno; +static struct internal_scnhdr *section; +static struct hint **hint_link; + +static void +set_section(name) + char *name; +{ + unsigned n; + struct internal_scnhdr *sec = 0; + + for (n = 0; n < nsections; n++) + if (!strcmp(sections[n].name, name)) { + sec = sections + n; + break; + } + if (!sec) { + fprintf(stderr, "%s line %d: no section named \"%s\" in %s\n", + filename_for_err, lineno, name, objfilename); + exit(1); + } + if (sec->sectype_hint || sec->hints) { + fprintf(stderr, "%s line %d: [%s] given more than once\n", + filename_for_err, lineno, name); + exit(1); + } + section = sec; + hint_link = &sec->hints; +} + +static void +set_mode(arg) + char *arg; +{ + char *cp; + + if (!section) { + fprintf(stderr, + "%s line %d: error: mode line outside of section\n", + filename_for_err, lineno); + exit(1); + } + if (section->sectype_hint) { + fprintf(stderr, + "%s line %d: mode given more than once for [%s]\n", + filename_for_err, lineno, section->name); + exit(1); + } + while (isspace(*arg)) + arg++; + if (!*arg) { + fprintf(stderr, "%s line %d: mode line: missing argument\n", + filename_for_err, lineno); + exit(1); + } + for (cp = arg; *cp && !isspace(*cp); cp++) + ; + if (*cp) + *cp++ = '\0'; + if (!strcmp(arg, "code")) + section->sectype_hint = SECTYPE_CODE; + else if (!strcmp(arg, "data")) + section->sectype_hint = SECTYPE_DATA; + else if (!strcmp(arg, "bss")) + section->sectype_hint = SECTYPE_BSS; + else { + fprintf(stderr, "%s line %d: unknown mode \"%s\"\n", + filename_for_err, lineno, arg); + exit(1); + } +} + +static void +regular_hint(arg1, arg2) + char *arg1, *arg2; +{ + fprintf(stderr, "error: regular hints not implemented yet\n"); + exit(1); +} + +read_hints_file(filename) + char *filename; +{ + FILE *f; + char linebuf[128], *cp, *np; + + f = fopen(filename, "r"); + if (!f) { + perror(filename); + exit(1); + } + filename_for_err = filename; + for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) { + for (cp = linebuf; isspace(*cp); cp++) + ; + if (!*cp || *cp == '#') + continue; + if (*cp == '[') { + np = ++cp; + cp = index(cp, ']'); + if (!cp) { + fprintf(stderr, + "%s line %d: invalid section syntax\n", + filename, lineno); + exit(1); + } + *cp = '\0'; + set_section(np); + continue; + } + for (np = cp; *cp && !isspace(*cp); cp++) + ; + if (*cp) + *cp++ = '\0'; + if (!strcmp(np, "mode")) { + set_mode(cp); + continue; + } + regular_hint(np, cp); + } + fclose(f); + return(0); +}
--- a/ticoff/intstruct.h Fri Apr 04 18:56:23 2014 +0000 +++ b/ticoff/intstruct.h Sat Apr 05 19:14:43 2014 +0000 @@ -15,8 +15,14 @@ unsigned nsymbols; struct internal_syment **sorted_symbols; struct internal_reloc *int_relocs; + int sectype_hint; + struct hint *hints; }; +#define SECTYPE_CODE 1 +#define SECTYPE_DATA 2 +#define SECTYPE_BSS 3 + struct internal_syment { unsigned number; char *name; @@ -34,3 +40,16 @@ int type; char *typestr; }; + +struct hint { + unsigned pos; + int type; + unsigned nitems; + int linebrk; + struct hint *next; +}; + +#define HINT_D8 1 +#define HINT_D16 2 +#define HINT_ASCIZ 3 +#define HINT_D32 4
--- a/ticoff/main.c Fri Apr 04 18:56:23 2014 +0000 +++ b/ticoff/main.c Sat Apr 05 19:14:43 2014 +0000 @@ -41,8 +41,8 @@ { struct cmdtab *tp; - if (argc != 3) { - fprintf(stderr, "usage: %s <objfile> <op>\n", argv[0]); + if (argc < 3) { + fprintf(stderr, "usage: %s <objfile> <op> [args]\n", argv[0]); exit(1); } objfilename = argv[1]; @@ -56,5 +56,5 @@ argv[2]); exit(1); } - return tp->func(); + return tp->func(argc - 2, argv + 2); }