comparison lwlink/script.c @ 315:fcd103148aa6

Add ability to load sections downward instead of upward Add "section ... high ..." statement to link scripts to allow a section to be placed based on its end address instead of its start address. All sections listed after such a statement are treated as growing downward until the next section statement specifying a load address.
author William Astle <lost@l-w.ca>
date Wed, 27 Nov 2013 16:01:26 -0700
parents 86eb8814a05c
children 55c1f9a321e9
comparison
equal deleted inserted replaced
310:86eb8814a05c 315:fcd103148aa6
378 linkscript.execsym = NULL; 378 linkscript.execsym = NULL;
379 } 379 }
380 } 380 }
381 else if (!strcmp(line, "section")) 381 else if (!strcmp(line, "section"))
382 { 382 {
383 int growsdown = 0;
383 // section 384 // section
384 // parse out the section name and flags 385 // parse out the section name and flags
385 for (ptr2 = ptr; *ptr2 && !isspace(*ptr2); ptr2++) 386 for (ptr2 = ptr; *ptr2 && !isspace(*ptr2); ptr2++)
386 /* do nothing */ ; 387 /* do nothing */ ;
387 388
402 ptr2 += 4; 403 ptr2 += 4;
403 while (*ptr2 && isspace(*ptr2)) 404 while (*ptr2 && isspace(*ptr2))
404 ptr2++; 405 ptr2++;
405 406
406 } 407 }
408 else if (!strncmp(ptr2, "high", 4))
409 {
410 ptr2 += 4;
411 while (*ptr2 && isspace(*ptr2))
412 ptr2++;
413 growsdown = 1;
414 }
407 else 415 else
408 { 416 {
409 fprintf(stderr, "%s: bad script\n", scriptfile); 417 fprintf(stderr, "%s: bad script\n", scriptfile);
410 exit(1); 418 exit(1);
411 } 419 }
420 }
421 else
422 {
423 if (linkscript.nlines > 0)
424 growsdown = linkscript.lines[linkscript.nlines - 1].growsdown;
412 } 425 }
413 426
414 // now ptr2 points to the load address if there is one 427 // now ptr2 points to the load address if there is one
415 // or NUL if not 428 // or NUL if not
416 linkscript.lines = lw_realloc(linkscript.lines, sizeof(struct scriptline_s) * (linkscript.nlines + 1)); 429 linkscript.lines = lw_realloc(linkscript.lines, sizeof(struct scriptline_s) * (linkscript.nlines + 1));
417 430
418 linkscript.lines[linkscript.nlines].noflags = 0; 431 linkscript.lines[linkscript.nlines].noflags = 0;
419 linkscript.lines[linkscript.nlines].yesflags = 0; 432 linkscript.lines[linkscript.nlines].yesflags = 0;
433 linkscript.lines[linkscript.nlines].growsdown = growsdown;
420 if (*ptr2) 434 if (*ptr2)
421 linkscript.lines[linkscript.nlines].loadat = strtol(ptr2, NULL, 16); 435 linkscript.lines[linkscript.nlines].loadat = strtol(ptr2, NULL, 16);
422 else 436 else
423 linkscript.lines[linkscript.nlines].loadat = -1; 437 linkscript.lines[linkscript.nlines].loadat = -1;
424 for (ptr2 = ptr; *ptr2 && *ptr2 != ','; ptr2++) 438 for (ptr2 = ptr; *ptr2 && *ptr2 != ','; ptr2++)