brickos の makelx が扱えるシンボル長が短い件
とりあえず 80 文字制限はちょっとねーってことで 256 文字にしてみた。
brickos のバージョンは 0.9.0 です。
Index: srecload.c
===================================================================
--- srecload.c (revision 19)
+++ srecload.c (working copy)
@@ -37,7 +37,7 @@
* kekoa@graphics.stanford.edu
* 10/3/98
*/
-
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -50,20 +50,20 @@
#define IMG_HIGHEST 0xffff
#define IMG_MAXSIZE 0x10000
+static char buf[256];
//! load symbols from symbolsrec file
/*! \return current line in file
- the symbol section is enclosed in $$
+ the symbol section is enclosed in $$
symbol line format is SYMBOL $ADDR
*/
static int symbols_load(image_t *img,FILE *file) {
- char buf[256];
int doubledollar=0;
unsigned short text=0,
text_end=0,
- data=0,
- data_end=0,
+ data=0,
+ data_end=0,
bss=0,
bss_end=0,
ctors=0,
@@ -72,10 +72,10 @@
dtors_end=0,
_main=0;
int line=0;
-
+
// read in symbols
//
- while(doubledollar<2 && fgets(buf, 80, file)) {
+ while(doubledollar<2 && fgets(buf, sizeof(buf)-1, file)) {
int i;
line++;
@@ -84,8 +84,8 @@
for(i=0; buf[i] && isspace(buf[i]); i++)
;
if (!buf[i])
- continue;
-
+ continue;
+
if(buf[i]=='$' && buf[i+1]=='$') {
// delimiter?
//
@@ -95,62 +95,62 @@
//
char *symbol;
unsigned short address;
-
+
if(doubledollar<1) {
- fprintf(stderr,"malformed symbolsrec file at line %d\n",line);
- exit(-1);
+ fprintf(stderr,"malformed symbolsrec file at line %d\n",line);
+ exit(-1);
}
-
+
// read symbol
//
symbol=buf+i;
while(buf[i] && buf[i]!=' ')
- i++;
+ i++;
if(buf[i]!=' ' || buf[i+1]!='$') {
- fprintf(stderr,"malformed symbolsrec file at line %d\n",line);
- exit(-1);
+ fprintf(stderr,"malformed symbolsrec file at line %d\n",line);
+ exit(-1);
}
buf[i]=0;
-
+
address=(unsigned short) strtoul(buf+i+2,NULL,16);
-
+
// retain relevant offsets
//
if(!strcmp(symbol,"___text"))
- text=address;
+ text=address;
else if(!strcmp(symbol,"___text_end"))
- text_end=address;
+ text_end=address;
else if(!strcmp(symbol,"___data"))
- data=address;
+ data=address;
else if(!strcmp(symbol,"___data_end"))
- data_end=address;
+ data_end=address;
else if(!strcmp(symbol,"___bss"))
- bss=address;
+ bss=address;
else if(!strcmp(symbol,"___bss_end"))
- bss_end=address;
+ bss_end=address;
else if(!strcmp(symbol,"___ctors"))
- ctors=address;
+ ctors=address;
else if(!strcmp(symbol,"___ctors_end"))
- ctors_end=address;
+ ctors_end=address;
else if(!strcmp(symbol,"___dtors"))
- dtors=address;
+ dtors=address;
else if(!strcmp(symbol,"___dtors_end"))
- dtors_end=address;
+ dtors_end=address;
else if(!strcmp(symbol,"_main"))
- _main=address;
- }
+ _main=address;
+ }
}
// save general file information
//
- img->base =text;
+ img->base =text;
// added ctor/dtor sections for C++. They reside between text and data
// so they've been added to text for simplicity. -stephen 14Jan01
img->text_size=(text_end - text) + (ctors_end - ctors) + (dtors_end - dtors);
img->data_size=data_end - data;
img->bss_size = bss_end - bss;
img->offset =_main-text;
-
+
return line;
}
@@ -158,7 +158,6 @@
void image_load(image_t *img,const char *filename)
{
FILE *file;
- char buf[256];
srec_t srec;
int line;
unsigned short size,start=0;
@@ -172,15 +171,15 @@
//
line=symbols_load(img,file);
size=img->text_size+img->data_size;
-
+
if((img->text=calloc(size,1))== NULL) {
fprintf(stderr, "out of memory\n");
exit(1);
}
-
- // Build an image of the srecord data
+
+ // Build an image of the srecord data
//
- while (fgets(buf, 80, file)) {
+ while (fgets(buf, sizeof(buf)-1, file)) {
int i,error;
line++;
@@ -189,34 +188,34 @@
for(i=0; buf[i] && isspace(buf[i]); i++)
;
if (!buf[i])
- continue;
+ continue;
// decode line
//
if ((error = srec_decode(&srec, buf)) < 0) {
- char *errstr = NULL;
- switch (error) {
- case S_NULL: errstr = "null string error"; break;
- case S_INVALID_HDR: errstr = "invalid header"; break;
- case S_INVALID_CHAR: errstr = "invalid character"; break;
- case S_INVALID_TYPE: errstr = "invalid type"; break;
- case S_TOO_SHORT: errstr = "line to short"; break;
- case S_TOO_LONG: errstr = "line too line"; break;
- case S_INVALID_CKSUM: /* ignored */ break;
- default: errstr = "unknown error"; break;
- }
- if (errstr) {
- fprintf(stderr, "%s: %s on line %d\n", filename, errstr, line);
- exit(1);
- }
+ char *errstr = NULL;
+ switch (error) {
+ case S_NULL: errstr = "null string error"; break;
+ case S_INVALID_HDR: errstr = "invalid header"; break;
+ case S_INVALID_CHAR: errstr = "invalid character"; break;
+ case S_INVALID_TYPE: errstr = "invalid type"; break;
+ case S_TOO_SHORT: errstr = "line to short"; break;
+ case S_TOO_LONG: errstr = "line too line"; break;
+ case S_INVALID_CKSUM: /* ignored */ break;
+ default: errstr = "unknown error"; break;
+ }
+ if (errstr) {
+ fprintf(stderr, "%s: %s on line %d\n", filename, errstr, line);
+ exit(1);
+ }
}
-
+
// handle lines
//
if (srec.type == 1) {
if (srec.addr < img->base || srec.addr + srec.count > img->base + size) {
- fprintf(stderr, "%s: address [0x%4.4lX, 0x%4.4lX] out of bounds [0x%4.4X-0x%4.4X] on line %d\n",filename, srec.addr, (srec.addr + srec.count), img->base, (img->base + size), line);
- exit(1);
+ fprintf(stderr, "%s: address [0x%4.4lX, 0x%4.4lX] out of bounds [0x%4.4X-0x%4.4X] on line %d\n",filename, srec.addr, (srec.addr + srec.count), img->base, (img->base + size), line);
+ exit(1);
}
memcpy(img->text + srec.addr - img->base, srec.data, srec.count);