From 9753ff753e0cbc3e142308a6335a4f324eae4071 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Thu, 23 May 2024 17:17:15 -0500 Subject: [PATCH] More work on EMBED macro. --- f256lib/f256.h | 14 +++--- .../mos-platform/f256/CMakeLists.txt | 3 ++ .../mos-platform/f256/declare.ld | 1 + .../mos-platform/f256/link.ld | 18 ++----- .../mos-platform/f256/memory.ld | 1 + .../mos-platform/f256/output.ld | 2 +- .../mos-platform/f256/sections.ld | 1 + tools/overlay/overlay.c | 48 +++++++++++++------ 8 files changed, 52 insertions(+), 36 deletions(-) create mode 100644 llvm-mos-sdk-patches/mos-platform/f256/declare.ld create mode 100644 llvm-mos-sdk-patches/mos-platform/f256/memory.ld create mode 100644 llvm-mos-sdk-patches/mos-platform/f256/sections.ld diff --git a/f256lib/f256.h b/f256lib/f256.h index 4a52c97..2cf6e5c 100644 --- a/f256lib/f256.h +++ b/f256lib/f256.h @@ -130,19 +130,19 @@ typedef struct colorS { #define IBSTR2(x) #x #define IBSTR(x) IBSTR2(x) #define EMBED(name, file, address) \ - __asm__(".section binary." IBSTR(name) ",\"aR\" \n" \ - ".global incbin_" IBSTR(name) "_start\n" \ + __asm__(".section ." IBSTR(name) ",\"aR\" \n" \ + ".global " IBSTR(name) "_start\n" \ ".balign 16\n" \ - "incbin_" IBSTR(name) "_start:\n" \ + IBSTR(name) "_start:\n" \ ".incbin \"" file "\"\n" \ \ - ".global incbin_" IBSTR(name) "_end\n" \ + ".global " IBSTR(name) "_end\n" \ ".balign 1\n" \ - "incbin_" IBSTR(name) "_end:\n" \ + IBSTR(name) "_end:\n" \ ".byte 0\n" \ ); \ - extern __attribute__((aligned(16))) const char ## name ## _start[]; \ - extern const char ## name ## _end[] + extern __attribute__((aligned(16))) const char name ## _start[]; \ + extern const char name ## _end[] // Single-byte diff --git a/llvm-mos-sdk-patches/mos-platform/f256/CMakeLists.txt b/llvm-mos-sdk-patches/mos-platform/f256/CMakeLists.txt index 5ab7bac..ab48761 100644 --- a/llvm-mos-sdk-patches/mos-platform/f256/CMakeLists.txt +++ b/llvm-mos-sdk-patches/mos-platform/f256/CMakeLists.txt @@ -8,6 +8,9 @@ file(READ clang.cfg CONFIG) install(FILES link.ld + declare.ld + memory.ld + sections.ld output.ld TYPE LIB) diff --git a/llvm-mos-sdk-patches/mos-platform/f256/declare.ld b/llvm-mos-sdk-patches/mos-platform/f256/declare.ld new file mode 100644 index 0000000..08a03b0 --- /dev/null +++ b/llvm-mos-sdk-patches/mos-platform/f256/declare.ld @@ -0,0 +1 @@ +/* This is generated by the overlay tool - DO NOT EDIT. */ diff --git a/llvm-mos-sdk-patches/mos-platform/f256/link.ld b/llvm-mos-sdk-patches/mos-platform/f256/link.ld index 3877c7c..b69bf5b 100644 --- a/llvm-mos-sdk-patches/mos-platform/f256/link.ld +++ b/llvm-mos-sdk-patches/mos-platform/f256/link.ld @@ -38,8 +38,7 @@ __block22_lma = (22<<24)|__SLOT_ADDR; __block23_lma = (23<<24)|__SLOT_ADDR; /* Stash preloaded binary data */ -__binarydata_lma = 0x54000; /* Block 42 */ -__BINARYDATA_SIZE = 0x2C000; /* Size of A2-3D2, 3D/2D data area, and 2 bitmaps. */ +INCLUDE declare.ld MEMORY { block8 : ORIGIN = __block8_lma, LENGTH = __BLOCK_SIZE @@ -58,7 +57,7 @@ MEMORY { block21 : ORIGIN = __block21_lma, LENGTH = __BLOCK_SIZE block22 : ORIGIN = __block22_lma, LENGTH = __BLOCK_SIZE block23 : ORIGIN = __block23_lma, LENGTH = __BLOCK_SIZE -/* binarydata : ORIGIN = __binarydata_lma, LENGTH = __BINARYDATA_SIZE */ + INCLUDE memory.ld } REGION_ALIAS("c_writeable", ram) @@ -82,7 +81,7 @@ SECTIONS { .block21 : { *(.block21 .block21.*) } >block21 end_block21 = .; .block22 : { *(.block22 .block22.*) } >block22 end_block22 = .; .block23 : { *(.block23 .block23.*) } >block23 end_block23 = .; -/* .binarydata : { *(.binarydata .binarydata.*) } >binarydata end_binarydata = .; */ + INCLUDE sections.ld } OUTPUT_FORMAT { @@ -95,18 +94,9 @@ OUTPUT_FORMAT { BYTE(0x00) TRIM(ram) - /* Overlay Segments */ + /* Overlay Segments and Binary Data */ INCLUDE output.ld - /* Binary Data */ -/* - SHORT(ORIGIN(binarydata)) - BYTE(ORIGIN(binarydata)>>16) - SHORT(end_binarydata - __binarydata_lma) - BYTE((end_binarydata - __binarydata_lma)>>16) - TRIM(binarydata) -*/ - /* Launch the program, at _start */ SHORT(_start) LONG(0) diff --git a/llvm-mos-sdk-patches/mos-platform/f256/memory.ld b/llvm-mos-sdk-patches/mos-platform/f256/memory.ld new file mode 100644 index 0000000..08a03b0 --- /dev/null +++ b/llvm-mos-sdk-patches/mos-platform/f256/memory.ld @@ -0,0 +1 @@ +/* This is generated by the overlay tool - DO NOT EDIT. */ diff --git a/llvm-mos-sdk-patches/mos-platform/f256/output.ld b/llvm-mos-sdk-patches/mos-platform/f256/output.ld index f856485..08a03b0 100644 --- a/llvm-mos-sdk-patches/mos-platform/f256/output.ld +++ b/llvm-mos-sdk-patches/mos-platform/f256/output.ld @@ -1 +1 @@ -/* This is generated by the overlay tool. */ +/* This is generated by the overlay tool - DO NOT EDIT. */ diff --git a/llvm-mos-sdk-patches/mos-platform/f256/sections.ld b/llvm-mos-sdk-patches/mos-platform/f256/sections.ld new file mode 100644 index 0000000..08a03b0 --- /dev/null +++ b/llvm-mos-sdk-patches/mos-platform/f256/sections.ld @@ -0,0 +1 @@ +/* This is generated by the overlay tool - DO NOT EDIT. */ diff --git a/tools/overlay/overlay.c b/tools/overlay/overlay.c index 10e36e8..0f94ac5 100644 --- a/tools/overlay/overlay.c +++ b/tools/overlay/overlay.c @@ -301,7 +301,6 @@ void parseCFile(char *filename, char *targetFile, FILE *trampoline, char *trampo } // Is this an EMBED? "EMBED(name, file, address);" - found = false; // This is tracking if we're quoted or not. start = strstr(buffer, "EMBED"); if (start != NULL) { // Scan for opening paren, three arguments. @@ -312,6 +311,7 @@ void parseCFile(char *filename, char *targetFile, FILE *trampoline, char *trampo d = NULL; // Start of second argument. e = NULL; // End of second argument. f = NULL; // Start of third argument. + found = false; // This is tracking if we're quoted or not. for (x=0; xname = strdup(d); + newEmbed->filename = strdup(d); *e = x; // Address. - newEmbed->address = atol(f); + newEmbed->address = strtol(f, NULL, 0); // Add to list. if (_embeds == NULL) { _embeds = newEmbed; @@ -442,6 +442,7 @@ int main(int argc, char *argv[]) { DIR *dir; struct dirent *dirent; struct stat fileStat; + char *generated = "This is generated by the overlay tool - DO NOT EDIT."; /* * Command line: @@ -485,7 +486,7 @@ int main(int argc, char *argv[]) { free(targetDir); return 1; } - fprintf(out, "// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n\n"); + fprintf(out, "// %s\n\n", generated); fprintf(out, "#ifndef TRAMPOLINE_H\n"); fprintf(out, "#define TRAMPOLINE_H\n\n"); @@ -596,12 +597,34 @@ int main(int argc, char *argv[]) { return 1; } + fprintf(out, "/* %s */\n\n", generated); + fprintf(out2, "/* %s */\n\n", generated); + fprintf(out3, "/* %s */\n\n", generated); + // Populate three linker sections. _embedsHead = _embeds; while (_embedsHead != NULL) { // Declaration. - in = fopen(_embedsHead->filename, "rb"); // ***TODO*** This path will be wrong. - if (in == NULL) { + length = 0; + // Try to open embedded file relative to each provided directory. + // This includes the target directory. + for (x=2; xfilename); + printf("Checking [%s]\n", targetFile); + free(sourceDir); + in = fopen(targetFile, "rb"); + free(targetFile); + if (in != NULL) { + fseek(in, 0, SEEK_END); + length = ftell(in) + 1; // Without the +1 the linker will overflow the segment. + fclose(in); + break; + } + } + if (length == 0) { + fprintf(stderr, "ERROR! Cannot locate %s!\n", _embedsHead->filename); free(targetDir); free(linkerFile); free(linkerFile2); @@ -611,16 +634,12 @@ int main(int argc, char *argv[]) { fclose(out3); return 1; } - fseek(in, 0, SEEK_END); - length = ftell(in); - fclose(in); - fprintf(out, " __%s_lma = %lx;\n", _embedsHead->name, _embedsHead->address); - fprintf(out, " __%s_size = %lx;\n\n", _embedsHead->name, length); + fprintf(out, " __%s_lma = 0x%lx;\n", _embedsHead->name, _embedsHead->address); + fprintf(out, " __%s_size = 0x%lx;\n\n", _embedsHead->name, length); // MEMORY. fprintf(out2, " %s : ORIGIN = __%s_lma, LENGTH = __%s_size\n", _embedsHead->name, _embedsHead->name, _embedsHead->name); // SECTIONS. fprintf(out3, " .%s : { *(.%s .%s*) } >%s end_%s = .;\n", _embedsHead->name, _embedsHead->name, _embedsHead->name, _embedsHead->name, _embedsHead->name); - _embedsHead = _embedsHead->next; } @@ -640,6 +659,7 @@ int main(int argc, char *argv[]) { free(linkerFile); return 1; } + fprintf(out, "/* %s */\n\n", generated); for (x=0; x<_totalBanks; x++) { fprintf(out, " SHORT(%d*0x2000)\n", x+8); fprintf(out, " BYTE(%d/8)\n", x+8);