2020-03-17 04:31:30 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2021-11-30 23:29:09 +00:00
|
|
|
#include "spec.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2023-02-26 16:26:07 +00:00
|
|
|
// Note: *SECTION ALIGNMENT* Object files built with a compiler such as GCC can, by default, use narrower
|
2022-02-19 21:50:56 +00:00
|
|
|
// alignment for sections size, compared to IDO padding sections to a 0x10-aligned size.
|
2023-02-26 16:26:07 +00:00
|
|
|
// To properly generate relocations relative to section starts, sections currently need to be aligned
|
|
|
|
// explicitly (to 0x10 currently, a narrower alignment might work), otherwise the linker does implicit alignment
|
|
|
|
// and inserts padding between the address indicated by section start symbols (such as *SegmentRoDataStart) and
|
2022-02-19 21:50:56 +00:00
|
|
|
// the actual aligned start of the section.
|
2023-02-26 16:26:07 +00:00
|
|
|
// With IDO, the padding of sections to an aligned size makes the section start at aligned addresses out of the box,
|
2022-02-19 21:50:56 +00:00
|
|
|
// so the explicit alignment has no further effect.
|
|
|
|
|
2021-11-30 23:29:09 +00:00
|
|
|
struct Segment *g_segments;
|
|
|
|
int g_segmentsCount;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-11-30 23:29:09 +00:00
|
|
|
static void write_ld_script(FILE *fout)
|
2020-03-17 04:31:30 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
|
2022-02-19 21:50:56 +00:00
|
|
|
fputs("OUTPUT_ARCH (mips)\n\n"
|
|
|
|
"SECTIONS {\n"
|
2020-03-17 04:31:30 +00:00
|
|
|
" _RomSize = 0;\n"
|
|
|
|
" _RomStart = _RomSize;\n\n",
|
|
|
|
fout);
|
|
|
|
|
|
|
|
for (i = 0; i < g_segmentsCount; i++)
|
|
|
|
{
|
|
|
|
const struct Segment *seg = &g_segments[i];
|
|
|
|
|
|
|
|
// align start of ROM segment
|
|
|
|
if (seg->fields & (1 << STMT_romalign))
|
|
|
|
fprintf(fout, " _RomSize = (_RomSize + %i) & ~ %i;\n", seg->romalign - 1, seg->romalign - 1);
|
|
|
|
|
|
|
|
// initialized data (.text, .data, .rodata, .sdata)
|
|
|
|
|
2021-08-01 19:53:46 +00:00
|
|
|
fprintf(fout, " _%sSegmentRomStartTemp = _RomSize;\n"
|
|
|
|
" _%sSegmentRomStart = _%sSegmentRomStartTemp;\n"
|
|
|
|
" ..%s ", seg->name, seg->name, seg->name, seg->name);
|
2020-06-07 14:31:11 +00:00
|
|
|
|
|
|
|
if (seg->fields & (1 << STMT_after))
|
2024-03-29 15:11:45 +00:00
|
|
|
fprintf(fout, "(_%sSegmentEnd + %i) & ~ %i ", seg->after, seg->align - 1, seg->align - 1);
|
2020-06-07 14:31:11 +00:00
|
|
|
else if (seg->fields & (1 << STMT_number))
|
|
|
|
fprintf(fout, "0x%02X000000 ", seg->number);
|
|
|
|
else if (seg->fields & (1 << STMT_address))
|
2020-03-17 04:31:30 +00:00
|
|
|
fprintf(fout, "0x%08X ", seg->address);
|
2024-03-29 15:11:45 +00:00
|
|
|
else
|
|
|
|
fprintf(fout, "ALIGN(0x%X) ", seg->align);
|
2020-06-07 14:31:11 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
// (AT(_RomSize) isn't necessary, but adds useful "load address" lines to the map file)
|
|
|
|
fprintf(fout, ": AT(_RomSize)\n {\n"
|
|
|
|
" _%sSegmentStart = .;\n"
|
|
|
|
" . = ALIGN(0x10);\n"
|
|
|
|
" _%sSegmentTextStart = .;\n",
|
|
|
|
seg->name, seg->name);
|
|
|
|
|
|
|
|
for (j = 0; j < seg->includesCount; j++)
|
2021-11-23 18:31:44 +00:00
|
|
|
{
|
2024-06-10 14:07:51 +00:00
|
|
|
if (!seg->includes[j].dataOnlyWithinRodata)
|
|
|
|
{
|
|
|
|
fprintf(fout, " %s (.text)\n", seg->includes[j].fpath);
|
|
|
|
if (seg->includes[j].linkerPadding != 0)
|
|
|
|
fprintf(fout, " . += 0x%X;\n", seg->includes[j].linkerPadding);
|
|
|
|
fprintf(fout, " . = ALIGN(0x10);\n");
|
|
|
|
}
|
2021-11-23 18:31:44 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
fprintf(fout, " _%sSegmentTextEnd = .;\n", seg->name);
|
|
|
|
|
|
|
|
fprintf(fout, " _%sSegmentTextSize = ABSOLUTE( _%sSegmentTextEnd - _%sSegmentTextStart );\n", seg->name, seg->name, seg->name);
|
|
|
|
|
|
|
|
fprintf(fout, " _%sSegmentDataStart = .;\n", seg->name);
|
|
|
|
|
|
|
|
for (j = 0; j < seg->includesCount; j++)
|
z_message_PAL, message_data_static and surrounding doc (#996)
* Initial progress on z_message_PAL, very messy
* Fix merge
* Some more progress
* Fix merge
* More z_message_PAL
* Small progress
* More small progress
* message_data_static files OK
* Prepare z_message_tables
* Matched another function, small updates
* Attempt to use asm-processor static-symbols branch
* Refactor text id declarations
* Begin large text codes parser function
* Fix merge
* Refactor done
* Build OK, add color and highscore names
* Remove encoded text headers and automatically encode during build
* Fix kanfont
* Various cleanups
* DISP macros
* Another match aside data
* Further progress
* Small improvements
* Deduplicate magic values for text control codes, small improvements
* Tiny progress
* Minor cleanups
* Clean up z_message_PAL comment
* Progress on large functions
* Further progress on large functions
* Changes to mkldscript to link .data in the .rodata section
* data OK
* Few improvements
* Use gDPLoadTextureBlock macros where appropriate
* rm z_message_tables, progress on large functions
* 2 more matches
* Improvements
* Small progress
* More progress on big function
* progress
* match func_80107980
* match Message_Update
* match func_8010BED8
* done
* Progress on remaining large functions
* Small progress on largest function
* Another match, extract text and move to assets, improve text build system
* Small nonmatchings improvements
* docs wip
* Largest function maybe equivalent
* Fix merge
* Document do_action values, largest function is almost instruction-matching
* Rename NAVI do_action to NONE, as that appears to be how that value is used in practice
* Fix merge
* one match
* Last function is instruction-matching
* Fix
* Improvements thanks to engineer124
* Stack matched thanks to petrie911, now just a/v/low t regalloc issues, some cleanup
* More variables labeled, use text state enum everywhere
* More labels and names
* Fix
* Actor_IsTalking -> Actor_TalkRequested
* Match func_8010C39C and remove unused asm
* More docs
* Mostly ocarina related docs
* All msgModes named
* Fix assetclean
* Cleanup
* Extraction fixes and headers
* Suggestions
* Review suggestions
* Change text extraction again, only extract if the headers do not already exist
* Fix
* Use ast for charmap, fix assetclean for real this time
* Review suggestions
* BGM ids and ran formatter
* Review comments
* rename include_readonly to include_data_with_rodata
* Remove leading 0s in number directives
* Review suggestions for message_data_static
* textbox pos enum comments, rename several enum names from Message to TextBox
Co-authored-by: Thar0 <maximilianc64@gmail.com>
Co-authored-by: Zelllll <56516451+Zelllll@users.noreply.github.com>
Co-authored-by: petrie911 <pmontag@DESKTOP-LG8A167.localdomain>
Co-authored-by: Roman971 <romanlasnier@hotmail.com>
2021-11-23 01:20:30 +00:00
|
|
|
{
|
2024-06-10 14:07:51 +00:00
|
|
|
if (!seg->includes[j].dataOnlyWithinRodata && !seg->includes[j].noData)
|
2022-02-19 21:50:56 +00:00
|
|
|
fprintf(fout, " %s (.data)\n"
|
|
|
|
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
|
z_message_PAL, message_data_static and surrounding doc (#996)
* Initial progress on z_message_PAL, very messy
* Fix merge
* Some more progress
* Fix merge
* More z_message_PAL
* Small progress
* More small progress
* message_data_static files OK
* Prepare z_message_tables
* Matched another function, small updates
* Attempt to use asm-processor static-symbols branch
* Refactor text id declarations
* Begin large text codes parser function
* Fix merge
* Refactor done
* Build OK, add color and highscore names
* Remove encoded text headers and automatically encode during build
* Fix kanfont
* Various cleanups
* DISP macros
* Another match aside data
* Further progress
* Small improvements
* Deduplicate magic values for text control codes, small improvements
* Tiny progress
* Minor cleanups
* Clean up z_message_PAL comment
* Progress on large functions
* Further progress on large functions
* Changes to mkldscript to link .data in the .rodata section
* data OK
* Few improvements
* Use gDPLoadTextureBlock macros where appropriate
* rm z_message_tables, progress on large functions
* 2 more matches
* Improvements
* Small progress
* More progress on big function
* progress
* match func_80107980
* match Message_Update
* match func_8010BED8
* done
* Progress on remaining large functions
* Small progress on largest function
* Another match, extract text and move to assets, improve text build system
* Small nonmatchings improvements
* docs wip
* Largest function maybe equivalent
* Fix merge
* Document do_action values, largest function is almost instruction-matching
* Rename NAVI do_action to NONE, as that appears to be how that value is used in practice
* Fix merge
* one match
* Last function is instruction-matching
* Fix
* Improvements thanks to engineer124
* Stack matched thanks to petrie911, now just a/v/low t regalloc issues, some cleanup
* More variables labeled, use text state enum everywhere
* More labels and names
* Fix
* Actor_IsTalking -> Actor_TalkRequested
* Match func_8010C39C and remove unused asm
* More docs
* Mostly ocarina related docs
* All msgModes named
* Fix assetclean
* Cleanup
* Extraction fixes and headers
* Suggestions
* Review suggestions
* Change text extraction again, only extract if the headers do not already exist
* Fix
* Use ast for charmap, fix assetclean for real this time
* Review suggestions
* BGM ids and ran formatter
* Review comments
* rename include_readonly to include_data_with_rodata
* Remove leading 0s in number directives
* Review suggestions for message_data_static
* textbox pos enum comments, rename several enum names from Message to TextBox
Co-authored-by: Thar0 <maximilianc64@gmail.com>
Co-authored-by: Zelllll <56516451+Zelllll@users.noreply.github.com>
Co-authored-by: petrie911 <pmontag@DESKTOP-LG8A167.localdomain>
Co-authored-by: Roman971 <romanlasnier@hotmail.com>
2021-11-23 01:20:30 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
fprintf(fout, " _%sSegmentDataEnd = .;\n", seg->name);
|
|
|
|
|
|
|
|
fprintf(fout, " _%sSegmentDataSize = ABSOLUTE( _%sSegmentDataEnd - _%sSegmentDataStart );\n", seg->name, seg->name, seg->name);
|
2022-01-23 23:09:02 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
fprintf(fout, " _%sSegmentRoDataStart = .;\n", seg->name);
|
|
|
|
|
|
|
|
for (j = 0; j < seg->includesCount; j++)
|
2021-08-31 13:30:02 +00:00
|
|
|
{
|
2024-06-10 14:07:51 +00:00
|
|
|
if (seg->includes[j].dataOnlyWithinRodata)
|
2022-02-19 21:50:56 +00:00
|
|
|
fprintf(fout, " %s (.data)\n"
|
|
|
|
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
|
|
|
|
|
2021-08-31 13:30:02 +00:00
|
|
|
// Compilers other than IDO, such as GCC, produce different sections such as
|
|
|
|
// the ones named directly below. These sections do not contain values that
|
|
|
|
// need relocating, but we need to ensure that the base .rodata section
|
|
|
|
// always comes first. The reason this is important is due to relocs assuming
|
|
|
|
// the base of .rodata being the offset for the relocs and thus needs to remain
|
|
|
|
// the beginning of the entire rodata area in order to remain consistent.
|
|
|
|
// Inconsistencies will lead to various .rodata reloc crashes as a result of
|
|
|
|
// either missing relocs or wrong relocs.
|
2024-06-10 14:07:51 +00:00
|
|
|
if (!seg->includes[j].dataOnlyWithinRodata)
|
|
|
|
fprintf(fout, " %s (.rodata)\n"
|
|
|
|
" %s (.rodata.str*)\n"
|
|
|
|
" %s (.rodata.cst*)\n"
|
|
|
|
" . = ALIGN(0x10);\n",
|
|
|
|
seg->includes[j].fpath, seg->includes[j].fpath, seg->includes[j].fpath);
|
2021-08-31 13:30:02 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
fprintf(fout, " _%sSegmentRoDataEnd = .;\n", seg->name);
|
|
|
|
|
|
|
|
fprintf(fout, " _%sSegmentRoDataSize = ABSOLUTE( _%sSegmentRoDataEnd - _%sSegmentRoDataStart );\n", seg->name, seg->name, seg->name);
|
|
|
|
|
|
|
|
fprintf(fout, " _%sSegmentSDataStart = .;\n", seg->name);
|
|
|
|
|
|
|
|
for (j = 0; j < seg->includesCount; j++)
|
2024-06-10 14:07:51 +00:00
|
|
|
if (!seg->includes[j].dataOnlyWithinRodata)
|
|
|
|
fprintf(fout, " %s (.sdata)\n"
|
|
|
|
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
fprintf(fout, " _%sSegmentSDataEnd = .;\n", seg->name);
|
|
|
|
|
2021-11-30 23:29:09 +00:00
|
|
|
fprintf(fout, " _%sSegmentOvlStart = .;\n", seg->name);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-11-30 23:29:09 +00:00
|
|
|
for (j = 0; j < seg->includesCount; j++)
|
2024-06-10 14:07:51 +00:00
|
|
|
if (!seg->includes[j].dataOnlyWithinRodata)
|
|
|
|
fprintf(fout, " %s (.ovl)\n", seg->includes[j].fpath);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-11-30 23:29:09 +00:00
|
|
|
fprintf(fout, " _%sSegmentOvlEnd = .;\n", seg->name);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
if (seg->fields & (1 << STMT_increment))
|
|
|
|
fprintf(fout, " . += 0x%08X;\n", seg->increment);
|
2022-01-23 23:09:02 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
fputs(" }\n", fout);
|
2022-02-19 21:50:56 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
fprintf(fout, " _RomSize += ( _%sSegmentOvlEnd - _%sSegmentTextStart );\n", seg->name, seg->name);
|
|
|
|
|
2021-08-01 19:53:46 +00:00
|
|
|
fprintf(fout, " _%sSegmentRomEndTemp = _RomSize;\n"
|
|
|
|
"_%sSegmentRomEnd = _%sSegmentRomEndTemp;\n\n",
|
|
|
|
seg->name, seg->name, seg->name);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-02-19 21:50:56 +00:00
|
|
|
// align end of ROM segment
|
2020-03-17 04:31:30 +00:00
|
|
|
if (seg->fields & (1 << STMT_romalign))
|
|
|
|
fprintf(fout, " _RomSize = (_RomSize + %i) & ~ %i;\n", seg->romalign - 1, seg->romalign - 1);
|
|
|
|
|
|
|
|
// uninitialized data (.sbss, .scommon, .bss, COMMON)
|
|
|
|
fprintf(fout, " ..%s.bss ADDR(..%s) + SIZEOF(..%s) (NOLOAD) :\n"
|
|
|
|
/*" ..%s.bss :\n"*/
|
|
|
|
" {\n"
|
|
|
|
" . = ALIGN(0x10);\n"
|
|
|
|
" _%sSegmentBssStart = .;\n",
|
|
|
|
seg->name, seg->name, seg->name, seg->name);
|
2022-02-19 21:50:56 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
for (j = 0; j < seg->includesCount; j++)
|
2024-06-10 14:07:51 +00:00
|
|
|
if (!seg->includes[j].dataOnlyWithinRodata)
|
|
|
|
fprintf(fout, " %s (.sbss)\n"
|
|
|
|
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
|
2022-02-19 21:50:56 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
for (j = 0; j < seg->includesCount; j++)
|
2024-06-10 14:07:51 +00:00
|
|
|
if (!seg->includes[j].dataOnlyWithinRodata)
|
|
|
|
fprintf(fout, " %s (.scommon)\n"
|
|
|
|
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
|
2022-02-19 21:50:56 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
for (j = 0; j < seg->includesCount; j++)
|
2024-06-10 14:07:51 +00:00
|
|
|
if (!seg->includes[j].dataOnlyWithinRodata)
|
|
|
|
fprintf(fout, " %s (.bss)\n"
|
|
|
|
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
|
2022-02-19 21:50:56 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
for (j = 0; j < seg->includesCount; j++)
|
2024-06-10 14:07:51 +00:00
|
|
|
if (!seg->includes[j].dataOnlyWithinRodata)
|
|
|
|
fprintf(fout, " %s (COMMON)\n"
|
|
|
|
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
|
2022-02-19 21:50:56 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
fprintf(fout, " . = ALIGN(0x10);\n"
|
|
|
|
" _%sSegmentBssEnd = .;\n"
|
|
|
|
" _%sSegmentEnd = .;\n"
|
|
|
|
" }\n"
|
|
|
|
" _%sSegmentBssSize = ABSOLUTE( _%sSegmentBssEnd - _%sSegmentBssStart );\n\n",
|
|
|
|
seg->name, seg->name, seg->name, seg->name, seg->name);
|
|
|
|
}
|
|
|
|
|
2022-02-19 21:50:56 +00:00
|
|
|
fputs(" _RomEnd = _RomSize;\n\n", fout);
|
|
|
|
|
|
|
|
// Debugging sections
|
|
|
|
fputs(
|
2023-08-29 15:25:12 +00:00
|
|
|
// mdebug sections
|
|
|
|
" .pdr : { *(.pdr) }" "\n"
|
2022-02-19 21:50:56 +00:00
|
|
|
" .mdebug : { *(.mdebug) }" "\n"
|
|
|
|
" .mdebug.abi32 : { *(.mdebug.abi32) }" "\n"
|
|
|
|
// DWARF debug sections
|
|
|
|
// Symbols in the DWARF debugging sections are relative to the beginning of the section so we begin them at 0.
|
|
|
|
// DWARF 1
|
|
|
|
" .debug 0 : { *(.debug) }" "\n"
|
|
|
|
" .line 0 : { *(.line) }" "\n"
|
|
|
|
// GNU DWARF 1 extensions
|
|
|
|
" .debug_srcinfo 0 : { *(.debug_srcinfo) }" "\n"
|
|
|
|
" .debug_sfnames 0 : { *(.debug_sfnames) }" "\n"
|
|
|
|
// DWARF 1.1 and DWARF 2
|
|
|
|
" .debug_aranges 0 : { *(.debug_aranges) }" "\n"
|
|
|
|
" .debug_pubnames 0 : { *(.debug_pubnames) }" "\n"
|
|
|
|
// DWARF 2
|
|
|
|
" .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }" "\n"
|
|
|
|
" .debug_abbrev 0 : { *(.debug_abbrev) }" "\n"
|
|
|
|
" .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }" "\n"
|
|
|
|
" .debug_frame 0 : { *(.debug_frame) }" "\n"
|
|
|
|
" .debug_str 0 : { *(.debug_str) }" "\n"
|
|
|
|
" .debug_loc 0 : { *(.debug_loc) }" "\n"
|
|
|
|
" .debug_macinfo 0 : { *(.debug_macinfo) }" "\n"
|
|
|
|
// SGI/MIPS DWARF 2 extensions
|
|
|
|
" .debug_weaknames 0 : { *(.debug_weaknames) }" "\n"
|
|
|
|
" .debug_funcnames 0 : { *(.debug_funcnames) }" "\n"
|
|
|
|
" .debug_typenames 0 : { *(.debug_typenames) }" "\n"
|
|
|
|
" .debug_varnames 0 : { *(.debug_varnames) }" "\n"
|
|
|
|
// DWARF 3
|
|
|
|
" .debug_pubtypes 0 : { *(.debug_pubtypes) }" "\n"
|
|
|
|
" .debug_ranges 0 : { *(.debug_ranges) }" "\n"
|
2023-08-29 15:25:12 +00:00
|
|
|
// DWARF 5
|
|
|
|
" .debug_addr 0 : { *(.debug_addr) }" "\n"
|
|
|
|
" .debug_line_str 0 : { *(.debug_line_str) }" "\n"
|
|
|
|
" .debug_loclists 0 : { *(.debug_loclists) }" "\n"
|
2022-02-19 21:50:56 +00:00
|
|
|
" .debug_macro 0 : { *(.debug_macro) }" "\n"
|
2023-08-29 15:25:12 +00:00
|
|
|
" .debug_names 0 : { *(.debug_names) }" "\n"
|
|
|
|
" .debug_rnglists 0 : { *(.debug_rnglists) }" "\n"
|
|
|
|
" .debug_str_offsets 0 : { *(.debug_str_offsets) }" "\n"
|
|
|
|
" .debug_sup 0 : { *(.debug_sup) }\n"
|
|
|
|
// gnu attributes
|
2022-02-19 21:50:56 +00:00
|
|
|
" .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }" "\n", fout);
|
|
|
|
|
|
|
|
// Discard all other sections not mentioned above
|
|
|
|
fputs(" /DISCARD/ :" "\n"
|
|
|
|
" {" "\n"
|
|
|
|
" *(*);" "\n"
|
|
|
|
" }" "\n", fout);
|
|
|
|
fputs("}\n", fout);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void usage(const char *execname)
|
|
|
|
{
|
2022-02-19 21:50:56 +00:00
|
|
|
fprintf(stderr, "Nintendo 64 linker script generation tool v0.03\n"
|
2020-03-17 04:31:30 +00:00
|
|
|
"usage: %s SPEC_FILE LD_SCRIPT\n"
|
2021-11-30 23:29:09 +00:00
|
|
|
"SPEC_FILE file describing the organization of object files into segments\n"
|
|
|
|
"LD_SCRIPT filename of output linker script\n",
|
2020-03-17 04:31:30 +00:00
|
|
|
execname);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2021-11-30 23:29:09 +00:00
|
|
|
FILE *ldout;
|
|
|
|
void *spec;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if (argc != 3)
|
|
|
|
{
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
spec = util_read_whole_file(argv[1], &size);
|
|
|
|
parse_rom_spec(spec, &g_segments, &g_segmentsCount);
|
|
|
|
|
|
|
|
ldout = fopen(argv[2], "w");
|
|
|
|
if (ldout == NULL)
|
|
|
|
util_fatal_error("failed to open file '%s' for writing", argv[2]);
|
|
|
|
write_ld_script(ldout);
|
|
|
|
fclose(ldout);
|
|
|
|
|
2022-02-06 19:40:26 +00:00
|
|
|
free_rom_spec(g_segments, g_segmentsCount);
|
2021-11-30 23:29:09 +00:00
|
|
|
free(spec);
|
|
|
|
|
|
|
|
return 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|