From: notaz Date: Mon, 18 Nov 2013 23:50:53 +0000 (+0200) Subject: C code link-in, some reorganization X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8022df01f333cb5018c838a5b13e49edbb57d6b4;p=ia32rtools.git C code link-in, some reorganization --- diff --git a/run_mkpubinc.sh b/run_mkpubinc.sh index a3d085f..91a931b 100755 --- a/run_mkpubinc.sh +++ b/run_mkpubinc.sh @@ -1,8 +1,9 @@ #!/bin/sh +set -e -echo -n > public.inc +echo -n > $2 -cat StarCraft.asm | fromdos | sed -e \ +cat $1 | fromdos | sed -e \ '1,/^_rdata.*segment/d;/^_data_last/q;/^[[:blank:];]/d;/^;/d;/^_r\?data\>/d;' | awk '{print $1}' | \ while read a; do test -z "$a" && continue @@ -14,5 +15,5 @@ while read a; do ;; esac - echo "PUBLIC $a" >> public.inc + echo "PUBLIC $a" >> $2 done diff --git a/scr.ld b/scr.ld deleted file mode 100644 index 483b7ac..0000000 --- a/scr.ld +++ /dev/null @@ -1,222 +0,0 @@ -/* modified from /usr/i586-mingw32msvc/lib/ldscripts/i386pe.x */ -OUTPUT_FORMAT(pei-i386) -SEARCH_DIR("/usr/i586-mingw32msvc/lib"); -SECTIONS -{ - /* Make the virtual address and file offset synced if the alignment is - lower than the target page size. */ - . = SIZEOF_HEADERS; - . = ALIGN(__section_alignment__); - .text __image_base__ + (__section_alignment__): - { - StarCraft.o(.text) - } - .rdata 0x4fe000: - { - StarCraft.o(_rdata) - } - .data 0x50c000: - { - StarCraft.o(.data) - } - .text2 BLOCK(__section_alignment__) : - { - *(.init) - *(.text) - *(SORT(.text$*)) - *(.text.*) - *(.glue_7t) - *(.glue_7) - ___CTOR_LIST__ = .; __CTOR_LIST__ = . ; - LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*)); LONG (0); - ___DTOR_LIST__ = .; __DTOR_LIST__ = . ; - LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*)); LONG (0); - *(.fini) - /* ??? Why is .gcc_exc here? */ - *(.gcc_exc) - PROVIDE (etext = .); - *(.gcc_except_table) - } - .rdata2 BLOCK(__section_alignment__) : - { - *(.rdata) - *(SORT(.rdata$*)) - ___RUNTIME_PSEUDO_RELOC_LIST__ = .; - __RUNTIME_PSEUDO_RELOC_LIST__ = .; - *(.rdata_runtime_pseudo_reloc) - ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .; - __RUNTIME_PSEUDO_RELOC_LIST_END__ = .; - } - /* The Cygwin32 library uses a section to avoid copying certain data - on fork. This used to be named ".data". The linker used - to include this between __data_start__ and __data_end__, but that - breaks building the cygwin32 dll. Instead, we name the section - ".data_cygwin_nocopy" and explictly include it after __data_end__. */ - .data2 BLOCK(__section_alignment__) : - { - __data_start__ = . ; - *(.data) - *(.data2) - *(SORT(.data$*)) - *(.jcr) - __data_end__ = . ; - *(.data_cygwin_nocopy) - } - .eh_frame BLOCK(__section_alignment__) : - { - *(.eh_frame) - } - .pdata BLOCK(__section_alignment__) : - { - *(.pdata) - } - .bss BLOCK(__section_alignment__) : - { - __bss_start__ = . ; - *(.bss) - *(COMMON) - __bss_end__ = . ; - } - .edata BLOCK(__section_alignment__) : - { - *(.edata) - } - /DISCARD/ : - { - *(.debug$S) - *(.debug$T) - *(.debug$F) - *(.drectve) - } - .idata BLOCK(__section_alignment__) : - { - /* This cannot currently be handled with grouped sections. - See pe.em:sort_sections. */ - SORT(*)(.idata$2) - SORT(*)(.idata$3) - /* These zeroes mark the end of the import list. */ - LONG (0); LONG (0); LONG (0); LONG (0); LONG (0); - SORT(*)(.idata$4) - SORT(*)(.idata$5) - SORT(*)(.idata$6) - SORT(*)(.idata$7) - } - .CRT BLOCK(__section_alignment__) : - { - ___crt_xc_start__ = . ; - *(SORT(.CRT$XC*)) /* C initialization */ - ___crt_xc_end__ = . ; - ___crt_xi_start__ = . ; - *(SORT(.CRT$XI*)) /* C++ initialization */ - ___crt_xi_end__ = . ; - ___crt_xl_start__ = . ; - *(SORT(.CRT$XL*)) /* TLS callbacks */ - /* ___crt_xl_end__ is defined in the TLS Directory support code */ - ___crt_xp_start__ = . ; - *(SORT(.CRT$XP*)) /* Pre-termination */ - ___crt_xp_end__ = . ; - ___crt_xt_start__ = . ; - *(SORT(.CRT$XT*)) /* Termination */ - ___crt_xt_end__ = . ; - } - .tls BLOCK(__section_alignment__) : - { - ___tls_start__ = . ; - *(.tls) - *(.tls$) - *(SORT(.tls$*)) - ___tls_end__ = . ; - } - .endjunk BLOCK(__section_alignment__) : - { - /* end is deprecated, don't use it */ - PROVIDE (end = .); - PROVIDE ( _end = .); - __end__ = .; - } - .rsrc BLOCK(__section_alignment__) : - { - *(.rsrc) - *(SORT(.rsrc$*)) - } - .reloc BLOCK(__section_alignment__) : - { - *(.reloc) - } - .stab BLOCK(__section_alignment__) (NOLOAD) : - { - *(.stab) - } - .stabstr BLOCK(__section_alignment__) (NOLOAD) : - { - *(.stabstr) - } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section. Unlike other targets that fake this by putting the - section VMA at 0, the PE format will not allow it. */ - /* DWARF 1.1 and DWARF 2. */ - .debug_aranges BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_aranges) - } - .debug_pubnames BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_pubnames) - } - .debug_pubtypes BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_pubtypes) - } - /* DWARF 2. */ - .debug_info BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_info) *(.gnu.linkonce.wi.*) - } - .debug_abbrev BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_abbrev) - } - .debug_line BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_line) - } - .debug_frame BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_frame) - } - .debug_str BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_str) - } - .debug_loc BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_loc) - } - .debug_macinfo BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_macinfo) - } - /* SGI/MIPS DWARF 2 extensions. */ - .debug_weaknames BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_weaknames) - } - .debug_funcnames BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_funcnames) - } - .debug_typenames BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_typenames) - } - .debug_varnames BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_varnames) - } - /* DWARF 3. */ - .debug_ranges BLOCK(__section_alignment__) (NOLOAD) : - { - *(.debug_ranges) - } -} diff --git a/tools/asmproc.c b/tools/asmproc.c index 911fe58..0297664 100644 --- a/tools/asmproc.c +++ b/tools/asmproc.c @@ -38,7 +38,8 @@ static char *next_word(char *w, size_t wsize, char *s) struct sl_item { char *name; - int is_replace; + unsigned int is_replace:1; + unsigned int found:1; }; static int cmp_sym(const void *p1_, const void *p2_) @@ -47,6 +48,12 @@ static int cmp_sym(const void *p1_, const void *p2_) const char *s1 = p1->name, *s2 = p2->name; int i; + // replace is with syms from C with '_' prepended + if (p1->is_replace) + s1++; + if (p2->is_replace) + s2++; + for (i = 0; ; i++) { if (s1[i] == s2[i]) continue; @@ -94,12 +101,14 @@ void read_list(struct sl_item **sl_in, int *cnt, int *alloc, FILE *f, int is_rep sl[c].name = strdup(word); sl[c].is_replace = is_repl; + sl[c].found = 0; c++; if (c >= *alloc) { *alloc *= 2; sl = realloc(sl, *alloc * sizeof(sl[0])); my_assert_not(sl, NULL); + memset(sl + c, 0, (*alloc - c) * sizeof(sl[0])); } } @@ -107,9 +116,24 @@ void read_list(struct sl_item **sl_in, int *cnt, int *alloc, FILE *f, int is_rep *cnt = c; } +const char *sym_use(const struct sl_item *sym) +{ + static char buf[256+3]; + int ret; + + ret = snprintf(buf, sizeof(buf), "%s%s", + sym->is_replace ? "" : "rm_", sym->name); + if (ret >= sizeof(buf)) { + printf("truncation detected: '%s'\n", buf); + exit(1); + } + + return buf; +} + int main(int argc, char *argv[]) { - struct sl_item *symlist, *sym, ssym; + struct sl_item *symlist, *sym, ssym = { NULL, }; FILE *fout, *fin, *f; int symlist_alloc; int symlist_cnt; @@ -119,6 +143,7 @@ int main(int argc, char *argv[]) char word3[256]; char word4[256]; char *p; + int i; if (argc != 5) { // rmlist - prefix func with 'rm_', callsites with '_' @@ -130,7 +155,7 @@ int main(int argc, char *argv[]) symlist_alloc = 16; symlist_cnt = 0; - symlist = malloc(symlist_alloc * sizeof(symlist[0])); + symlist = calloc(symlist_alloc, sizeof(symlist[0])); my_assert_not(symlist, NULL); f = fopen(argv[3], "r"); @@ -145,10 +170,11 @@ int main(int argc, char *argv[]) qsort(symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym_sort); -printf("symlist:\n"); -int i; -for (i = 0; i < symlist_cnt; i++) - printf("%d '%s'\n", symlist[i].is_replace, symlist[i].name); +#if 0 + printf("symlist:\n"); + for (i = 0; i < symlist_cnt; i++) + printf("%d '%s'\n", symlist[i].is_replace, symlist[i].name); +#endif fin = fopen(argv[2], "r"); my_assert_not(fin, NULL); @@ -173,6 +199,7 @@ for (i = 0; i < symlist_cnt; i++) sym = bsearch(&ssym, symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym); if (sym != NULL) { + sym->found = 1; fprintf(fout, "rm_%s\t%s%s", word, word2, p); continue; } @@ -183,8 +210,8 @@ for (i = 0; i < symlist_cnt; i++) sym = bsearch(&ssym, symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym); if (sym != NULL) { - fprintf(fout, "\t\t%s\t%s%s%s", word, - sym->is_replace ? "_" : "rm_", word2, p); + fprintf(fout, "\t\t%s\t%s%s", word, + sym_use(sym), p); continue; } } @@ -200,7 +227,8 @@ for (i = 0; i < symlist_cnt; i++) sym = bsearch(&ssym, symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym); if (sym != NULL) { - fprintf(fout, "\t\tdd offset %s%s", word3, p); + fprintf(fout, "\t\tdd offset %s%s", + sym_use(sym), p); continue; } } @@ -216,8 +244,8 @@ for (i = 0; i < symlist_cnt; i++) sym = bsearch(&ssym, symlist, symlist_cnt, sizeof(symlist[0]), cmp_sym); if (sym != NULL) { - fprintf(fout, "%s\tdd offset %s%s%s", word, - sym->is_replace ? "_" : "rm_", word4, p); + fprintf(fout, "%s\tdd offset %s%s", word, + sym_use(sym), p); continue; } } @@ -226,6 +254,11 @@ pass: fwrite(line, 1, strlen(line), fout); } + for (i = 0; i < symlist_cnt; i++) { + if (!symlist[i].found) + printf("warning: sym '%s' not found\n", symlist[i].name); + } + fclose(fin); fclose(fout); diff --git a/uni.inc b/uni.inc deleted file mode 100644 index e69de29..0000000