/* Tool to make gzipped second stage binary Copyright (C) 1996 Jakub Jelinek This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include FILE *f; char buffer[2048]; void save(FILE *out, int len) { int i; while (len > 0) { i = 2048; if (len < i) i = len; if (fread (buffer, 1, i, f) != i) exit(1); if (fwrite (buffer, 1, i, out) != i) exit(1); len -= i; } } void main(int argc, char **argv) { FILE *g, *h; int reloc = 0x280000; int first_start, first_end, second_start, second_end, end, rodata_start, rodata_end; int net = 0; if (!strcmp (argv[1], "-a")) net = 1; f = fopen(argv[2], "r"); while (fgets (buffer, 256, f)) { if (!strcmp (buffer+11, "start\n")) reloc = strtol (buffer, NULL, 16); else if (!strcmp (buffer+11, "main_text_start\n")) first_start = strtol (buffer, NULL, 16) - reloc; else if (!strcmp (buffer+11, "main_text_end\n")) first_end = strtol (buffer, NULL, 16) - reloc; else if (!strcmp (buffer+11, "main_data_start\n")) second_start = strtol (buffer, NULL, 16) - reloc; else if (!strcmp (buffer+11, "main_data_end\n")) second_end = strtol (buffer, NULL, 16) - reloc; else if (!strcmp (buffer+11, "main_rodata_start\n")) rodata_start = strtol (buffer, NULL, 16) - reloc; else if (!strcmp (buffer+11, "main_rodata_end\n")) rodata_end = strtol (buffer, NULL, 16) - reloc; else if (!strcmp (buffer+11, "__bss_start\n")) end = strtol (buffer, NULL, 16) - reloc; } fclose (f); f = fopen(argv[3], "r"); g = fopen(argv[4], "w"); h = fopen(argv[5], "w"); if (fread(buffer, 1, 32, f) != 32) exit(1); if (!net) { memset (buffer, 0, 2048); if (fwrite(buffer, 1, 2048, g) != 2048) exit(1); } else { if (fwrite (buffer, 1, 32, g) != 32) exit(1); } save (g, first_start); save (h, first_end - first_start); save (g, rodata_start - first_end); save (h, rodata_end - rodata_start); save (g, second_start - rodata_end); save (h, second_end - second_start); save (g, end - second_end); fclose (f); fclose (g); fclose (h); exit (0); }