FreeCalypso > hg > freecalypso-reveng
changeset 134:c131238c56bf
tiobjd: implemented parsing of the hint input files
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 07 Apr 2014 02:41:35 +0000 |
parents | daeaa5950d10 |
children | df432a4b1b84 |
files | leo-obj/main/Create_RVtasks.hints leo-obj/main/Makefile leo-obj/main/int.hints leo-obj/tool/hints.c leo-obj/tool/intstruct.h |
diffstat | 5 files changed, 148 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/leo-obj/main/Create_RVtasks.hints Mon Apr 07 02:41:35 2014 +0000 @@ -0,0 +1,26 @@ +[.text] + +2a8 d32 +2d4 asciz +2d8 asciz +2dc asciz +30c asciz +340 asciz +374 asciz +3a8 asciz +3cc asciz +3f8 asciz +43c asciz +440 asciz +444 asciz +448 asciz +44c asciz +450 asciz +454 asciz +458 asciz +460 asciz +46c asciz +470 asciz +474 asciz +478 asciz +484-4b8 d32
--- a/leo-obj/main/Makefile Mon Apr 07 01:22:09 2014 +0000 +++ b/leo-obj/main/Makefile Mon Apr 07 02:41:35 2014 +0000 @@ -7,7 +7,13 @@ .SUFFIXES: .obj .disasm .obj.disasm: - ${TOOL} $< disasm > $@ + ${TOOL} $*.obj disasm > $@ + +Create_RVtasks.disasm: Create_RVtasks.obj Create_RVtasks.hints + ${TOOL} $*.obj disasm -h $*.hints > $@ + +int.disasm: int.obj int.hints + ${TOOL} $*.obj disasm -h $*.hints > $@ ${TARGETS}: ${TOOL} Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/leo-obj/main/int.hints Mon Apr 07 02:41:35 2014 +0000 @@ -0,0 +1,11 @@ +[S_D_Mem] +mode bss + +[E_D_Mem] +mode bss + +[.intvecs] +mode code + +[.inttext] +mode code
--- a/leo-obj/tool/hints.c Mon Apr 07 01:22:09 2014 +0000 +++ b/leo-obj/tool/hints.c Mon Apr 07 02:41:35 2014 +0000 @@ -82,8 +82,109 @@ regular_hint(arg1, arg2) char *arg1, *arg2; { - fprintf(stderr, "error: regular hints not implemented yet\n"); - exit(1); + struct hint *hint; + char *cp, *np; + + if (!section) { + fprintf(stderr, + "%s line %d: error: hint line outside of section\n", + filename_for_err, lineno); + exit(1); + } + hint = malloc(sizeof(struct hint)); + if (!hint) { + perror("malloc"); + exit(1); + } + hint->pos = strtoul(arg1, &cp, 16); + if (*cp == '-') { + cp++; + hint->endpos = strtoul(cp, &cp, 16); + } else + hint->endpos = hint->pos; + if (*cp) { + fprintf(stderr, "%s line %d: invalid hint position syntax\n", + filename_for_err, lineno); + exit(1); + } + if (hint->endpos < hint->pos) { + fprintf(stderr, "%s line %d: range going backward\n", + filename_for_err, lineno); + exit(1); + } + if (lasthint && hint->pos <= lasthint->endpos) { + fprintf(stderr, "%s line %d: hint pos <= previous\n", + filename_for_err, lineno); + exit(1); + } + hint->type = 0; + hint->linebrk = 0; + hint->next = 0; + for (cp = arg2; isspace(*cp); cp++) + ; + if (!*cp) { + fprintf(stderr, "%s line %d: no keyword after hint pos\n", + filename_for_err, lineno); + exit(1); + } + for (np = cp; *cp && !isspace(*cp); cp++) + ; + if (*cp) + *cp++ = '\0'; + if (!strcmp(np, "linebrk") || !strcmp(np, "linebreak")) { + hint->linebrk = 1; + while (isspace(*cp)) + cp++; + if (!*cp || *cp == '#') + goto out; + for (np = cp; *cp && !isspace(*cp); cp++) + ; + if (*cp) + *cp++ = '\0'; + } + if (!strcmp(np, "d8")) + hint->type = HINT_D8; + else if (!strcmp(np, "d16")) + hint->type = HINT_D16; + else if (!strcmp(np, "d32")) + hint->type = HINT_D32; + else if (!strcmp(np, "asciz")) + hint->type = HINT_ASCIZ; + else { + fprintf(stderr, "%s line %d: unknown hint keyword \"%s\"\n", + filename_for_err, lineno, np); + exit(1); + } + /* enforce alignment and range restrictions */ + switch (hint->type) { + case HINT_D16: + if (hint->pos & 1 || hint->endpos & 1) { + fprintf(stderr, "%s line %d: d16 hint misaligned\n", + filename_for_err, lineno); + exit(1); + } + break; + case HINT_D32: + if (hint->pos & 3 || hint->endpos & 3) { + fprintf(stderr, "%s line %d: d32 hint misaligned\n", + filename_for_err, lineno); + exit(1); + } + break; + case HINT_ASCIZ: + if (hint->endpos != hint->pos) { + fprintf(stderr, + "%s line %d: no range allowed for asciz hints\n", + filename_for_err, lineno); + exit(1); + } + break; + } +out: if (lasthint) + lasthint->next = hint; + else + section->hints = hint; + lasthint = hint; } read_hints_file(filename)