More work on EMBED macro.

This commit is contained in:
Scott Duensing 2024-05-23 17:17:15 -05:00
parent 8fbd2f1b72
commit 9753ff753e
8 changed files with 52 additions and 36 deletions

View file

@ -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

View file

@ -8,6 +8,9 @@ file(READ clang.cfg CONFIG)
install(FILES
link.ld
declare.ld
memory.ld
sections.ld
output.ld
TYPE LIB)

View file

@ -0,0 +1 @@
/* This is generated by the overlay tool - DO NOT EDIT. */

View file

@ -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)

View file

@ -0,0 +1 @@
/* This is generated by the overlay tool - DO NOT EDIT. */

View file

@ -1 +1 @@
/* This is generated by the overlay tool. */
/* This is generated by the overlay tool - DO NOT EDIT. */

View file

@ -0,0 +1 @@
/* This is generated by the overlay tool - DO NOT EDIT. */

View file

@ -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; x<strlen(buffer); x++) {
switch (c) {
case 0: // Opening parenthesis.
@ -337,11 +337,11 @@ void parseCFile(char *filename, char *targetFile, FILE *trampoline, char *trampo
if (buffer[x] == '"') {
// ***TODO*** This will barf if the filename has a " in it.
if (!found) {
d = &buffer[x];
d = &buffer[x+1];
} else {
found = !found;
e = &buffer[x];
}
found = !found;
} else {
if ((!found) && (buffer[x] == ',')) c++;
}
@ -366,10 +366,10 @@ void parseCFile(char *filename, char *targetFile, FILE *trampoline, char *trampo
// Filename.
x = *e;
*e = 0;
newEmbed->name = 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; x<argc; x++) {
sourceDir = strdup(argv[x]);
utilFixPathSeparators(&sourceDir, true);
targetFile = utilCreateString("%s%s", sourceDir, _embedsHead->filename);
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);